Commit 3bb53c3a070a52241661cec6a1da7f498b932808
1 parent
4383f9d5
Exists in
master
and in
2 other branches
Generating excel file with the goals
Showing
1 changed file
with
36 additions
and
3 deletions
Show diff stats
bulletin/views.py
@@ -10,12 +10,17 @@ from amadeus.permissions import has_subject_permissions, has_resource_permission | @@ -10,12 +10,17 @@ from amadeus.permissions import has_subject_permissions, has_resource_permission | ||
10 | from .utils import brodcast_dificulties | 10 | from .utils import brodcast_dificulties |
11 | from goals.models import Goals,GoalItem | 11 | from goals.models import Goals,GoalItem |
12 | 12 | ||
13 | +import xlwt | ||
13 | import time | 14 | import time |
14 | import datetime | 15 | import datetime |
15 | from log.mixins import LogMixin | 16 | from log.mixins import LogMixin |
16 | 17 | ||
17 | from topics.models import Topic | 18 | from topics.models import Topic |
18 | 19 | ||
20 | +from django.conf import settings | ||
21 | +import os | ||
22 | +from os.path import join | ||
23 | + | ||
19 | from pendencies.forms import PendenciesForm | 24 | from pendencies.forms import PendenciesForm |
20 | 25 | ||
21 | from .forms import BulletinForm | 26 | from .forms import BulletinForm |
@@ -275,8 +280,11 @@ class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): | @@ -275,8 +280,11 @@ class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): | ||
275 | context['subject'] = topic.subject | 280 | context['subject'] = topic.subject |
276 | 281 | ||
277 | 282 | ||
278 | - meta_geral = Goals.objects.filter(topic=topic) | 283 | + meta_geral = Goals.objects.get(topic=topic) |
279 | metas = GoalItem.objects.filter(goal = meta_geral) | 284 | metas = GoalItem.objects.filter(goal = meta_geral) |
285 | + itens_da_meta = list(metas) | ||
286 | + alunos = meta_geral.topic.subject.students.all() | ||
287 | + create_excel_file(alunos, itens_da_meta,meta_geral) | ||
280 | 288 | ||
281 | 289 | ||
282 | return context | 290 | return context |
@@ -295,8 +303,33 @@ class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): | @@ -295,8 +303,33 @@ class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): | ||
295 | 303 | ||
296 | return success_url | 304 | return success_url |
297 | 305 | ||
298 | - def create_excel_file(): | ||
299 | - pass | 306 | +def create_excel_file(estudantes,metas,meta): |
307 | + workbook = xlwt.Workbook() | ||
308 | + worksheet = workbook.add_sheet(u'Bulletin') | ||
309 | + worksheet.write(0, 0, u'ID do Usuário') | ||
310 | + worksheet.write(0, 1, u'Usuário') | ||
311 | + count_meta = 2 | ||
312 | + contador_estudante = 1 | ||
313 | + | ||
314 | + for m in metas: | ||
315 | + worksheet.write(0,count_meta,u'%s' % (m.description) ) | ||
316 | + count_meta += 1 | ||
317 | + for estudante in estudantes: | ||
318 | + worksheet.write(contador_estudante,0,estudante.id ) | ||
319 | + if estudante.social_name: | ||
320 | + worksheet.write(contador_estudante,1,estudante.social_name) | ||
321 | + else: | ||
322 | + nome = estudante.username + " " + estudante.last_name | ||
323 | + worksheet.write(contador_estudante,1,nome) | ||
324 | + | ||
325 | + contador_estudante += 1 | ||
326 | + | ||
327 | + folder_path = join(settings.BASE_DIR, 'bulletin\\localfiles') | ||
328 | + #check if the folder already exists | ||
329 | + if not os.path.isdir(folder_path): | ||
330 | + os.makedirs(folder_path) | ||
331 | + workbook.save(settings.BASE_DIR+"\\bulletin\\localfiles\\"+str(meta.slug)+".xls") | ||
332 | + | ||
300 | 333 | ||
301 | 334 | ||
302 | class UpdateView(LoginRequiredMixin, LogMixin, generic.UpdateView): | 335 | class UpdateView(LoginRequiredMixin, LogMixin, generic.UpdateView): |