Ultime commit!
This commit is contained in:
parent
729bc1bea1
commit
f767b7a41b
25 changed files with 186 additions and 532 deletions
|
|
@ -307,7 +307,7 @@ class FormationPlanPdf(EpcBaseDocTemplate):
|
|||
self.build(self.story)
|
||||
|
||||
|
||||
class PeriodSemesterPdf(EpcBaseDocTemplate):
|
||||
class PeriodeSemestrePdf(EpcBaseDocTemplate):
|
||||
"""
|
||||
PDF for periods during semesters
|
||||
"""
|
||||
|
|
@ -319,7 +319,7 @@ class PeriodSemesterPdf(EpcBaseDocTemplate):
|
|||
def produce(self, context):
|
||||
|
||||
for sem in range(1, 7):
|
||||
modules = context['sem{0}'.format(str(sem))]
|
||||
modules = [m for m in context['modules'] if getattr(m, 'sem{0}'.format(sem))]
|
||||
total = context['tot{0}'.format(str(sem))]
|
||||
data = [['Semestre {0}'.format(sem), '{0} h.'.format(total)]]
|
||||
for line in modules:
|
||||
|
|
|
|||
|
|
@ -149,14 +149,14 @@ ul li {
|
|||
}
|
||||
|
||||
.p {
|
||||
border:1px solid black;
|
||||
font-size:105%;
|
||||
border:1px solid black;
|
||||
font-size:105%;
|
||||
vertical-align:middle;
|
||||
}
|
||||
|
||||
.m {
|
||||
border:1px solid black;
|
||||
font-size:105%;
|
||||
font-size:105%;
|
||||
text-align:center;
|
||||
vertical-align:middle;
|
||||
height:20px;
|
||||
|
|
|
|||
25
cms/tests.py
25
cms/tests.py
|
|
@ -1,6 +1,6 @@
|
|||
import os
|
||||
|
||||
from django.db.models import Sum
|
||||
from django.db.models import Sum, F
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import User
|
||||
|
|
@ -37,11 +37,19 @@ class PdfTestCase(TestCase):
|
|||
self.assertEqual(response['content-type'], 'application/pdf')
|
||||
self.assertGreater(len(response.content), 200)
|
||||
|
||||
def test_periodes_pdf(self):
|
||||
response = self.client.get(reverse('periodes-pdf'))
|
||||
self.assertEqual(
|
||||
response['content-disposition'],
|
||||
'attachment; filename="periode_formation.pdf"'
|
||||
)
|
||||
self.assertEqual(response['content-type'], 'application/pdf')
|
||||
self.assertGreater(len(response.content), 200)
|
||||
|
||||
def test_periode_presentiel(self):
|
||||
tot = 0
|
||||
for m in Module.objects.all():
|
||||
tot += m.total_presentiel
|
||||
tot = Module.objects.aggregate(Sum('total_presentiel'))
|
||||
self.assertEqual(tot, 1200)
|
||||
|
||||
def test_periode_pratique(self):
|
||||
|
|
@ -50,4 +58,15 @@ class PdfTestCase(TestCase):
|
|||
|
||||
def test_periode_travail_perso(self):
|
||||
tot = Module.objects.aggregate(Sum('travail_perso'))
|
||||
self.assertEqual(tot['travail_perso__sum'], 1200)
|
||||
self.assertEqual(tot['travail_perso__sum'], 1200)
|
||||
|
||||
def test_periode(self):
|
||||
liste = Module.objects.filter(pratique_prof=0)
|
||||
context = {}
|
||||
for i in range(1, 7):
|
||||
semestre = 'sem{}'.format(i)
|
||||
context.update({
|
||||
semestre: liste.exclude(semestre=0),
|
||||
'tot{}'.format(i): liste.aggregate(Sum(F(semestre)))['{}__sum'.format(semestre)]
|
||||
})
|
||||
print(context)
|
||||
|
|
|
|||
52
cms/views.py
52
cms/views.py
|
|
@ -7,11 +7,11 @@ import os
|
|||
import tempfile
|
||||
|
||||
|
||||
from django.db.models import F, Sum
|
||||
from django.db.models import Sum
|
||||
from django.http import HttpResponse
|
||||
from django.views.generic import ListView, TemplateView, DetailView
|
||||
|
||||
from cms.pdf import PeriodSemesterPdf, ModuleDescriptionPdf, FormationPlanPdf
|
||||
from cms.pdf import PeriodeSemestrePdf, ModuleDescriptionPdf, FormationPlanPdf
|
||||
|
||||
from cms.models import (
|
||||
Domaine, Processus, Module, Competence, Concept, UploadDoc
|
||||
|
|
@ -95,6 +95,7 @@ def print_module_pdf(request, pk):
|
|||
pdf = ModuleDescriptionPdf(path)
|
||||
module = Module.objects.get(pk=pk)
|
||||
pdf.produce(module)
|
||||
|
||||
with open(path, mode='rb') as fh:
|
||||
response = HttpResponse(fh.read(), content_type='application/pdf')
|
||||
response['Content-Disposition'] = 'attachment; filename="EDS_module_{0}.pdf"'.format(module.code)
|
||||
|
|
@ -119,8 +120,8 @@ def print_periode_formation(request):
|
|||
filename = 'periode_formation.pdf'
|
||||
path = os.path.join(tempfile.gettempdir(), filename)
|
||||
context = {}
|
||||
context = get_context(context)
|
||||
pdf = PeriodSemesterPdf(path)
|
||||
context = get_detail_semestre(context)
|
||||
pdf = PeriodeSemestrePdf(path)
|
||||
pdf.produce(context)
|
||||
|
||||
with open(path, mode='rb') as fh:
|
||||
|
|
@ -129,30 +130,21 @@ def print_periode_formation(request):
|
|||
return response
|
||||
|
||||
|
||||
def get_context(context):
|
||||
def get_detail_semestre(context):
|
||||
"""
|
||||
Retrive periods
|
||||
"""
|
||||
# liste = Module.objects.exclude(total_presentiel=0)
|
||||
context['tot']= 0
|
||||
liste = Module.objects.filter(pratique_prof=0)
|
||||
for i in range(1, 7):
|
||||
sss = 'sem{}'.format(i)
|
||||
tot_sem = liste.aggregate(Sum(sss))['{}__sum'.format(sss)] # total du semestre
|
||||
context.update({
|
||||
'tot{}'.format(i): tot_sem
|
||||
})
|
||||
context['tot'] += tot_sem # total des semestres
|
||||
|
||||
context['sem1'] = liste.exclude(sem1=0)
|
||||
context['tot1'] = liste.aggregate(Sum(F('sem1')))['sem1__sum']
|
||||
context['sem2'] = liste.exclude(sem2=0)
|
||||
context['tot2'] = liste.aggregate(Sum(F('sem2')))['sem2__sum']
|
||||
context['sem3'] = liste.exclude(sem3=0)
|
||||
context['tot3'] = liste.aggregate(Sum(F('sem3')))['sem3__sum']
|
||||
context['sem4'] = liste.exclude(sem4=0)
|
||||
context['tot4'] = liste.aggregate(Sum(F('sem4')))['sem4__sum']
|
||||
context['sem5'] = liste.exclude(sem5=0)
|
||||
context['tot5'] = liste.aggregate(Sum(F('sem5')))['sem5__sum']
|
||||
context['sem6'] = liste.exclude(sem6=0)
|
||||
context['tot6'] = liste.aggregate(Sum(F('sem6')))['sem6__sum']
|
||||
|
||||
context['tot'] = (
|
||||
context['tot1'] + context['tot2'] + context['tot3'] + context['tot4']
|
||||
+ context['tot5'] + context['tot6']
|
||||
)
|
||||
context['modules'] = liste
|
||||
return context
|
||||
|
||||
|
||||
|
|
@ -161,7 +153,7 @@ class PeriodeView(TemplateView):
|
|||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
return get_context(context)
|
||||
return get_detail_semestre(context)
|
||||
|
||||
|
||||
class CompetenceListView(ListView):
|
||||
|
|
@ -175,8 +167,10 @@ class TravailPersoListView(ListView):
|
|||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context = get_context(context)
|
||||
context['total_perso'] = Module.objects.aggregate((Sum('travail_perso')))['travail_perso__sum']
|
||||
context['total_presentiel'] = context['tot']
|
||||
context['total_pratique'] = Module.objects.aggregate((Sum('pratique_prof')))['pratique_prof__sum']
|
||||
return get_context(context)
|
||||
context = get_detail_semestre(context)
|
||||
context.update({
|
||||
'total_perso' : Module.objects.aggregate((Sum('travail_perso')))['travail_perso__sum'],
|
||||
'total_presentiel' : context['tot'],
|
||||
'total_pratique': Module.objects.aggregate((Sum('pratique_prof')))['pratique_prof__sum']
|
||||
})
|
||||
return context
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue