eds/cms/views.py

177 lines
4.8 KiB
Python
Raw Permalink Normal View History

2017-08-13 22:58:46 +02:00
"""
2017-04-07 09:17:20 +02:00
Created on 4 déc. 2012
@author: alzo
2017-08-13 22:58:46 +02:00
"""
2017-08-14 07:43:21 +02:00
import os
2017-10-30 14:31:02 +01:00
import tempfile
2017-08-14 07:43:21 +02:00
2018-05-23 15:17:03 +02:00
2018-05-23 21:16:25 +02:00
from django.db.models import Sum
2017-08-13 22:58:46 +02:00
from django.http import HttpResponse
2018-05-23 15:17:03 +02:00
from django.views.generic import ListView, TemplateView, DetailView
2017-04-07 09:17:20 +02:00
2018-05-23 21:16:25 +02:00
from cms.pdf import PeriodeSemestrePdf, ModuleDescriptionPdf, FormationPlanPdf
2018-05-23 15:17:03 +02:00
2018-02-16 15:11:06 +01:00
from cms.models import (
Domaine, Processus, Module, Competence, Concept, UploadDoc
)
2017-04-07 09:17:20 +02:00
2017-08-13 22:58:46 +02:00
2017-04-07 09:17:20 +02:00
class HomeView(TemplateView):
template_name = 'cms/index.html'
def get_context_data(self, **kwargs):
context = super(HomeView, self).get_context_data(**kwargs)
for d in Domaine.objects.all().order_by('code'):
context[d.code] = d
for c in Processus.objects.all().order_by('code'):
context[c.code] = c
for m in Module.objects.all().order_by('code'):
context[m.code] = m
return context
class DomaineDetailView(DetailView):
template_name = 'cms/domaine_detail.html'
model = Domaine
class DomaineListView(ListView):
template_name = 'cms/domaine_list.html'
model = Domaine
class ProcessusDetailView(DetailView):
template_name = 'cms/processus_detail.html'
model = Processus
class ProcessusListView(ListView):
template_name = 'cms/processus_list.html'
model = Processus
class ModuleDetailView(DetailView):
template_name = 'cms/module_detail.html'
model = Module
class ModuleListView(ListView):
template_name = 'cms/module_list.html'
model = Module
class EvaluationView(ListView):
template_name = 'cms/evaluation.html'
model = Processus
2017-08-13 22:58:46 +02:00
2018-02-16 15:11:06 +01:00
class ConceptDetailView(DetailView):
template_name = 'cms/concept_detail.html'
model = Concept
2018-02-16 11:14:31 +01:00
class UploadDocListView(ListView):
template_name = 'cms/uploaddoc_list.html'
model = UploadDoc
2017-04-25 21:07:48 +02:00
def get_queryset(self, **kwargs):
2018-02-16 11:14:31 +01:00
query = UploadDoc.objects.filter(published=True)
2017-04-25 21:07:48 +02:00
return query
2017-08-13 22:58:46 +02:00
2017-04-19 18:49:49 +02:00
2018-02-16 11:14:31 +01:00
class UploadDocDetailView(DetailView):
2017-04-25 21:07:48 +02:00
"""
2018-02-16 15:37:11 +01:00
Display uploaded docs
2017-04-25 21:07:48 +02:00
"""
2018-02-16 11:14:31 +01:00
template_name = 'cms/uploaddoc_detail.html'
2017-04-19 18:49:49 +02:00
model = UploadDoc
2017-10-30 14:31:02 +01:00
def print_module_pdf(request, pk):
filename = 'module.pdf'
path = os.path.join(tempfile.gettempdir(), filename)
2017-11-02 14:56:11 +01:00
pdf = ModuleDescriptionPdf(path)
2017-10-30 14:31:02 +01:00
module = Module.objects.get(pk=pk)
pdf.produce(module)
2018-05-23 21:16:25 +02:00
2017-10-30 14:31:02 +01:00
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)
return response
def print_plan_formation(request):
filename = 'plan_formation.pdf'
path = os.path.join(tempfile.gettempdir(), filename)
2017-11-02 14:56:11 +01:00
pdf = FormationPlanPdf(path)
2017-10-30 14:31:02 +01:00
domain = Domaine.objects.all().order_by('code')
process = Processus.objects.all().order_by('code')
pdf.produce(domain, process)
with open(path, mode='rb') as fh:
response = HttpResponse(fh.read(), content_type='application/pdf')
response['Content-Disposition'] = 'attachment; filename="EDS_plan_formation.pdf"'
return response
def print_periode_formation(request):
filename = 'periode_formation.pdf'
path = os.path.join(tempfile.gettempdir(), filename)
context = {}
2018-05-23 21:16:25 +02:00
context = get_detail_semestre(context)
pdf = PeriodeSemestrePdf(path)
2017-11-01 16:10:31 +01:00
pdf.produce(context)
2017-10-30 14:31:02 +01:00
2017-10-30 22:03:31 +01:00
with open(path, mode='rb') as fh:
2017-10-30 14:31:02 +01:00
response = HttpResponse(fh.read(), content_type='application/pdf')
response['Content-Disposition'] = 'attachment; filename="{0}"'.format(filename)
return response
2018-05-23 21:16:25 +02:00
def get_detail_semestre(context):
2017-04-19 18:49:49 +02:00
"""
2017-11-02 15:03:22 +01:00
Retrive periods
2017-10-30 14:31:02 +01:00
"""
2018-05-23 21:16:25 +02:00
context['tot']= 0
2018-02-16 11:14:31 +01:00
liste = Module.objects.filter(pratique_prof=0)
2018-05-23 21:16:25 +02:00
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['modules'] = liste
2017-04-07 09:17:20 +02:00
return context
class PeriodeView(TemplateView):
template_name = 'cms/periodes.html'
2017-10-30 14:31:02 +01:00
2017-04-07 09:17:20 +02:00
def get_context_data(self, **kwargs):
2018-02-16 11:14:31 +01:00
context = super().get_context_data(**kwargs)
2018-05-23 21:16:25 +02:00
return get_detail_semestre(context)
2017-04-07 09:17:20 +02:00
2017-08-13 22:58:46 +02:00
2017-05-04 17:16:04 +02:00
class CompetenceListView(ListView):
model = Competence
template_name = 'cms/competence_list.html'
class TravailPersoListView(ListView):
model = Module
template_name = 'cms/travail_perso.html'
def get_context_data(self, **kwargs):
2018-02-16 11:14:31 +01:00
context = super().get_context_data(**kwargs)
2018-05-23 21:16:25 +02:00
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