Fixed getting candidate PDF summary
This commit is contained in:
parent
7ee3511e5f
commit
01a2560740
3 changed files with 13 additions and 14 deletions
|
|
@ -4,7 +4,6 @@ from reportlab.lib.units import cm
|
|||
from reportlab.platypus import PageTemplate, Paragraph, Spacer, Table, TableStyle
|
||||
|
||||
from django.utils.dateformat import format as django_format
|
||||
from django.utils.text import slugify
|
||||
|
||||
from stages.pdf import EpcBaseDocTemplate, LOGO_EPC, LOGO_ESNE, style_normal, style_bold
|
||||
from .models import (
|
||||
|
|
@ -17,9 +16,8 @@ class InscriptionSummaryPDF(EpcBaseDocTemplate):
|
|||
"""
|
||||
PDF for summary of inscription
|
||||
"""
|
||||
def __init__(self, candidate, **kwargs):
|
||||
filename = slugify('{0}_{1}'.format(candidate.last_name, candidate.first_name)) + '.pdf'
|
||||
super().__init__(filename, **kwargs)
|
||||
def __init__(self, out, **kwargs):
|
||||
super().__init__(out, **kwargs)
|
||||
self.addPageTemplates([
|
||||
PageTemplate(id='FirstPage', frames=[self.page_frame], onPage=self.header)
|
||||
])
|
||||
|
|
|
|||
|
|
@ -370,7 +370,7 @@ tél. 032 886 33 00
|
|||
'attachment; filename="dupond_henri.pdf"'
|
||||
)
|
||||
self.assertEqual(response['Content-Type'], 'application/pdf')
|
||||
self.assertGreater(len(response.content), 200)
|
||||
self.assertGreater(int(response['Content-Length']), 1000)
|
||||
|
||||
def test_export_candidates(self):
|
||||
ede = Section.objects.create(name='EDE')
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
import io
|
||||
import os
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib import messages
|
||||
from django.http import HttpResponse
|
||||
from django.shortcuts import redirect
|
||||
from django.http import FileResponse
|
||||
from django.shortcuts import get_object_or_404, redirect
|
||||
from django.template import loader
|
||||
from django.urls import reverse, reverse_lazy
|
||||
from django.utils import timezone
|
||||
from django.utils.text import slugify
|
||||
|
||||
from stages.views.base import EmailConfirmationBaseView
|
||||
from candidats.models import Candidate, Interview
|
||||
|
|
@ -170,11 +172,10 @@ def inscription_summary(request, pk):
|
|||
"""
|
||||
Print a PDF summary of inscription
|
||||
"""
|
||||
candidat = Candidate.objects.get(pk=pk)
|
||||
pdf = InscriptionSummaryPDF(candidat)
|
||||
candidat = get_object_or_404(Candidate, pk=pk)
|
||||
buff = io.BytesIO()
|
||||
pdf = InscriptionSummaryPDF(buff)
|
||||
pdf.produce(candidat)
|
||||
|
||||
with open(pdf.filename, mode='rb') as fh:
|
||||
response = HttpResponse(fh.read(), content_type='application/pdf')
|
||||
response['Content-Disposition'] = 'attachment; filename="{0}"'.format(os.path.basename(pdf.filename))
|
||||
return response
|
||||
filename = slugify('{0}_{1}'.format(candidat.last_name, candidat.first_name)) + '.pdf'
|
||||
buff.seek(0)
|
||||
return FileResponse(buff, as_attachment=True, filename=filename)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue