Add zipped PDF export of class lists

This commit is contained in:
alazo 2018-06-16 17:45:16 +02:00 committed by Claude Paroz
parent 22563a823c
commit 386d34f63b
4 changed files with 104 additions and 1 deletions

View file

@ -34,7 +34,7 @@ from .models import (
Klass, Section, Option, Student, Teacher, Corporation, CorpContact, Course, Period,
Training, Availability
)
from .pdf import ExpertEdeLetterPdf, UpdateDataFormPDF, MentorCompensationPdfForm
from .pdf import ExpertEdeLetterPdf, UpdateDataFormPDF, MentorCompensationPdfForm, KlassListPDF
from .utils import is_int
@ -1042,6 +1042,27 @@ def print_mentor_ede_compensation_form(request, pk):
return response
def print_klass_list(request):
query = Klass.objects.all(
).annotate(num_students=Count(Case(When(student__archived=False, then=1)))
).filter(num_students__gt=0
).order_by('section', 'name')
filename = 'archive_RolesDeClasses.zip'
path = os.path.join(tempfile.gettempdir(), filename)
with zipfile.ZipFile(path, mode='w', compression=zipfile.ZIP_DEFLATED) as filezip:
for klass in query:
pdf = KlassListPDF(klass)
pdf.produce(klass)
filezip.write(pdf.filename)
with open(filezip.filename, mode='rb') as fh:
response = HttpResponse(fh.read(), content_type='application/zip')
response['Content-Disposition'] = 'attachment; filename="{0}"'.format(filename)
return response
GENERAL_EXPORT_FIELDS = [
('Num_Ele', 'ext_id'),
('Nom_Ele', 'last_name'),