From a9b6fdfe2f286654b15ac04e7dec4f0edf68e68b Mon Sep 17 00:00:00 2001 From: Gustavo Date: Fri, 4 Aug 2017 15:07:21 -0300 Subject: [PATCH] Modified bulletin views to properly display the information about the goals --- bulletin/views.py | 48 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/bulletin/views.py b/bulletin/views.py index d17ca51..0eb01f6 100644 --- a/bulletin/views.py +++ b/bulletin/views.py @@ -11,6 +11,7 @@ from .utils import brodcast_dificulties from goals.models import Goals,GoalItem,MyGoals import xlwt +import xlrd import time import datetime from log.mixins import LogMixin @@ -111,6 +112,9 @@ class NewWindowView(LoginRequiredMixin, LogMixin, generic.DetailView): topic = self.object.topic + slug = self.kwargs.get('slug', '') + bulletin = get_object_or_404(Bulletin, slug=slug) + meta_geral = Goals.objects.get(topic=topic) metas = GoalItem.objects.filter(goal = meta_geral) metas_pessoais = [] @@ -134,6 +138,12 @@ class NewWindowView(LoginRequiredMixin, LogMixin, generic.DetailView): context['metas'] = lista_metas + alcancadas, medias = read_excel_file(self.request.user,meta_geral,len(itens_da_meta),bulletin) + + for x in range(len(lista_metas)): + lista_metas[x]['alcancada'] = alcancadas[x] + lista_metas[x]['media'] = medias[x] + return context @@ -206,7 +216,8 @@ class InsideView(LoginRequiredMixin, LogMixin, generic.DetailView): topic = self.object.topic - + slug = self.kwargs.get('slug', '') + bulletin = get_object_or_404(Bulletin, slug=slug) meta_geral = Goals.objects.get(topic=topic) metas = GoalItem.objects.filter(goal = meta_geral) metas_pessoais = [] @@ -228,6 +239,12 @@ class InsideView(LoginRequiredMixin, LogMixin, generic.DetailView): else: lista_metas[x]['estabelecida'] = metas_pessoais[x].value + alcancadas, medias = read_excel_file(self.request.user,meta_geral,len(itens_da_meta),bulletin) + + for x in range(len(lista_metas)): + lista_metas[x]['alcancada'] = alcancadas[x] + lista_metas[x]['media'] = medias[x] + context['metas'] = lista_metas return context @@ -258,8 +275,11 @@ class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): if existe_meta: meta_geral = Goals.objects.get(topic=topic) + print(meta_geral.limit_submission_date.date() - 1) + print(meta_geral.presentation) now = timezone.now() - if meta_geral.limit_submission_date > now: + print(datetime.datetime.today().date()) + if meta_geral.limit_submission_date.date() > datetime.datetime.today().date(): 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) ) caminho2 = request.META['HTTP_REFERER'] return redirect(caminho2) @@ -415,7 +435,29 @@ def create_excel_file(estudantes,metas,meta): if not os.path.isdir(folder_path): os.makedirs(folder_path) workbook.save(settings.BASE_DIR+"\\bulletin\\static\\xls\\"+str(meta.slug)+".xls") - +def read_excel_file(estudante,meta,qtd,boletim): + nome = boletim.file_content.path + arquivo = xlrd.open_workbook(nome) + planilha = arquivo.sheet_by_index(0) + alcance = [] + medias = [] + + for n in range(planilha.nrows): + if n == 0: + continue + else: + linha = planilha.row_values(n) + if int(linha[0]) == int(estudante.id): + for x in range(2,2+qtd): + alcance.append(int(linha[x])) + break + + for b in range(2,planilha.ncols): + soma = sum(list(planilha.col_values(b,1,planilha.nrows))) + media = soma // (planilha.nrows - 1) + medias.append(media) + + return alcance, medias class UpdateView(LoginRequiredMixin, LogMixin, generic.UpdateView): -- libgit2 0.21.2