Commit a9b6fdfe2f286654b15ac04e7dec4f0edf68e68b

Authored by Gustavo
1 parent ccb88e79

Modified bulletin views to properly display the information about the goals

Showing 1 changed file with 45 additions and 3 deletions   Show diff stats
bulletin/views.py
@@ -11,6 +11,7 @@ from .utils import brodcast_dificulties @@ -11,6 +11,7 @@ from .utils import brodcast_dificulties
11 from goals.models import Goals,GoalItem,MyGoals 11 from goals.models import Goals,GoalItem,MyGoals
12 12
13 import xlwt 13 import xlwt
  14 +import xlrd
14 import time 15 import time
15 import datetime 16 import datetime
16 from log.mixins import LogMixin 17 from log.mixins import LogMixin
@@ -111,6 +112,9 @@ class NewWindowView(LoginRequiredMixin, LogMixin, generic.DetailView): @@ -111,6 +112,9 @@ class NewWindowView(LoginRequiredMixin, LogMixin, generic.DetailView):
111 112
112 topic = self.object.topic 113 topic = self.object.topic
113 114
  115 + slug = self.kwargs.get('slug', '')
  116 + bulletin = get_object_or_404(Bulletin, slug=slug)
  117 +
114 meta_geral = Goals.objects.get(topic=topic) 118 meta_geral = Goals.objects.get(topic=topic)
115 metas = GoalItem.objects.filter(goal = meta_geral) 119 metas = GoalItem.objects.filter(goal = meta_geral)
116 metas_pessoais = [] 120 metas_pessoais = []
@@ -134,6 +138,12 @@ class NewWindowView(LoginRequiredMixin, LogMixin, generic.DetailView): @@ -134,6 +138,12 @@ class NewWindowView(LoginRequiredMixin, LogMixin, generic.DetailView):
134 138
135 context['metas'] = lista_metas 139 context['metas'] = lista_metas
136 140
  141 + alcancadas, medias = read_excel_file(self.request.user,meta_geral,len(itens_da_meta),bulletin)
  142 +
  143 + for x in range(len(lista_metas)):
  144 + lista_metas[x]['alcancada'] = alcancadas[x]
  145 + lista_metas[x]['media'] = medias[x]
  146 +
137 147
138 return context 148 return context
139 149
@@ -206,7 +216,8 @@ class InsideView(LoginRequiredMixin, LogMixin, generic.DetailView): @@ -206,7 +216,8 @@ class InsideView(LoginRequiredMixin, LogMixin, generic.DetailView):
206 216
207 217
208 topic = self.object.topic 218 topic = self.object.topic
209 - 219 + slug = self.kwargs.get('slug', '')
  220 + bulletin = get_object_or_404(Bulletin, slug=slug)
210 meta_geral = Goals.objects.get(topic=topic) 221 meta_geral = Goals.objects.get(topic=topic)
211 metas = GoalItem.objects.filter(goal = meta_geral) 222 metas = GoalItem.objects.filter(goal = meta_geral)
212 metas_pessoais = [] 223 metas_pessoais = []
@@ -228,6 +239,12 @@ class InsideView(LoginRequiredMixin, LogMixin, generic.DetailView): @@ -228,6 +239,12 @@ class InsideView(LoginRequiredMixin, LogMixin, generic.DetailView):
228 else: 239 else:
229 lista_metas[x]['estabelecida'] = metas_pessoais[x].value 240 lista_metas[x]['estabelecida'] = metas_pessoais[x].value
230 241
  242 + alcancadas, medias = read_excel_file(self.request.user,meta_geral,len(itens_da_meta),bulletin)
  243 +
  244 + for x in range(len(lista_metas)):
  245 + lista_metas[x]['alcancada'] = alcancadas[x]
  246 + lista_metas[x]['media'] = medias[x]
  247 +
231 context['metas'] = lista_metas 248 context['metas'] = lista_metas
232 249
233 return context 250 return context
@@ -258,8 +275,11 @@ class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): @@ -258,8 +275,11 @@ class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView):
258 275
259 if existe_meta: 276 if existe_meta:
260 meta_geral = Goals.objects.get(topic=topic) 277 meta_geral = Goals.objects.get(topic=topic)
  278 + print(meta_geral.limit_submission_date.date() - 1)
  279 + print(meta_geral.presentation)
261 now = timezone.now() 280 now = timezone.now()
262 - if meta_geral.limit_submission_date > now: 281 + print(datetime.datetime.today().date())
  282 + if meta_geral.limit_submission_date.date() > datetime.datetime.today().date():
263 messages.error(request,_("The deadline to submit the goals of the topic %s has not yet closed, so you can't create a Bulletin.") %(topic) ) 283 messages.error(request,_("The deadline to submit the goals of the topic %s has not yet closed, so you can't create a Bulletin.") %(topic) )
264 caminho2 = request.META['HTTP_REFERER'] 284 caminho2 = request.META['HTTP_REFERER']
265 return redirect(caminho2) 285 return redirect(caminho2)
@@ -415,7 +435,29 @@ def create_excel_file(estudantes,metas,meta): @@ -415,7 +435,29 @@ def create_excel_file(estudantes,metas,meta):
415 if not os.path.isdir(folder_path): 435 if not os.path.isdir(folder_path):
416 os.makedirs(folder_path) 436 os.makedirs(folder_path)
417 workbook.save(settings.BASE_DIR+"\\bulletin\\static\\xls\\"+str(meta.slug)+".xls") 437 workbook.save(settings.BASE_DIR+"\\bulletin\\static\\xls\\"+str(meta.slug)+".xls")
418 - 438 +def read_excel_file(estudante,meta,qtd,boletim):
  439 + nome = boletim.file_content.path
  440 + arquivo = xlrd.open_workbook(nome)
  441 + planilha = arquivo.sheet_by_index(0)
  442 + alcance = []
  443 + medias = []
  444 +
  445 + for n in range(planilha.nrows):
  446 + if n == 0:
  447 + continue
  448 + else:
  449 + linha = planilha.row_values(n)
  450 + if int(linha[0]) == int(estudante.id):
  451 + for x in range(2,2+qtd):
  452 + alcance.append(int(linha[x]))
  453 + break
  454 +
  455 + for b in range(2,planilha.ncols):
  456 + soma = sum(list(planilha.col_values(b,1,planilha.nrows)))
  457 + media = soma // (planilha.nrows - 1)
  458 + medias.append(media)
  459 +
  460 + return alcance, medias
419 461
420 462
421 class UpdateView(LoginRequiredMixin, LogMixin, generic.UpdateView): 463 class UpdateView(LoginRequiredMixin, LogMixin, generic.UpdateView):