Removed set_normal_template_page for EpcBaseDocTemplate
This commit is contained in:
parent
091873e739
commit
c68e064496
2 changed files with 37 additions and 34 deletions
|
|
@ -1,12 +1,12 @@
|
|||
from reportlab.lib.enums import TA_LEFT
|
||||
from reportlab.lib.styles import ParagraphStyle as PS
|
||||
from reportlab.lib.units import cm
|
||||
from reportlab.platypus import Paragraph, Table, TableStyle
|
||||
from reportlab.platypus import PageTemplate, Paragraph, Table, TableStyle
|
||||
|
||||
from django.utils.dateformat import format as django_format
|
||||
from django.utils.text import slugify
|
||||
|
||||
from stages.pdf import EpcBaseDocTemplate
|
||||
from stages.pdf import EpcBaseDocTemplate, LOGO_EPC, LOGO_ESNE
|
||||
from .models import (
|
||||
AES_ACCORDS_CHOICES, DIPLOMA_CHOICES, DIPLOMA_STATUS_CHOICES,
|
||||
OPTION_CHOICES, RESIDENCE_PERMITS_CHOICES,
|
||||
|
|
@ -22,8 +22,27 @@ class InscriptionSummaryPDF(EpcBaseDocTemplate):
|
|||
"""
|
||||
def __init__(self, candidate, **kwargs):
|
||||
filename = slugify('{0}_{1}'.format(candidate.last_name, candidate.first_name)) + '.pdf'
|
||||
super().__init__(filename, title="Dossier d'inscription", **kwargs)
|
||||
self.set_normal_template_page()
|
||||
super().__init__(filename, **kwargs)
|
||||
self.addPageTemplates([
|
||||
PageTemplate(id='FirstPage', frames=[self.page_frame], onPage=self.header)
|
||||
])
|
||||
|
||||
def header(self, canvas, doc):
|
||||
section = "Filière EDE"
|
||||
title = "Dossier d'inscription"
|
||||
|
||||
canvas.saveState()
|
||||
canvas.drawImage(
|
||||
LOGO_EPC, doc.leftMargin, doc.height - 1.5 * cm, 5 * cm, 3 * cm, preserveAspectRatio=True
|
||||
)
|
||||
canvas.drawImage(
|
||||
LOGO_ESNE, doc.width - 2.5 * cm, doc.height - 1.2 * cm, 5 * cm, 3.3 * cm, preserveAspectRatio=True
|
||||
)
|
||||
canvas.line(doc.leftMargin, doc.height - 2 * cm, doc.width + doc.leftMargin, doc.height - 2 * cm)
|
||||
canvas.drawString(doc.leftMargin, doc.height - 2.5 * cm, section)
|
||||
canvas.drawRightString(doc.width + doc.leftMargin, doc.height - 2.5 * cm, title)
|
||||
canvas.line(doc.leftMargin, doc.height - 2.7 * cm, doc.width + doc.leftMargin, doc.height - 2.7 * cm)
|
||||
canvas.restoreState()
|
||||
|
||||
def produce(self, candidate):
|
||||
# personal data
|
||||
|
|
|
|||
|
|
@ -146,13 +146,16 @@ class CifomBaseISO(SimpleDocTemplate):
|
|||
|
||||
|
||||
class EpcBaseDocTemplate(SimpleDocTemplate):
|
||||
filiere = 'Formation EDE'
|
||||
|
||||
def __init__(self, filename, title='', pagesize=A4):
|
||||
def __init__(self, filename, title=''):
|
||||
path = os.path.join(tempfile.gettempdir(), filename)
|
||||
super().__init__(
|
||||
path, pagesize=pagesize, _pageBreakQuick=0,
|
||||
lefMargin=1.5 * cm, bottomMargin=1.5 * cm, topMargin=1.5 * cm, rightMargin=2.5 * cm
|
||||
path,
|
||||
pagesize=A4,
|
||||
lefMargin=2.5 * cm, bottomMargin=1 * cm, topMargin=1 * cm, rightMargin=2.5 * cm
|
||||
)
|
||||
self.page_frame = Frame(
|
||||
self.leftMargin, self.bottomMargin, self.width - 2.5, self.height - 3 * cm,
|
||||
id='first_table', showBoundary=0, leftPadding=0 * cm
|
||||
)
|
||||
self.story = []
|
||||
self.title = title
|
||||
|
|
@ -173,29 +176,6 @@ class EpcBaseDocTemplate(SimpleDocTemplate):
|
|||
footer.drawOn(canvas, doc.leftMargin, h)
|
||||
canvas.restoreState()
|
||||
|
||||
def later_header(self, canvas, doc):
|
||||
canvas.saveState()
|
||||
canvas.line(doc.leftMargin, doc.height + 1 * cm, doc.width + doc.leftMargin, doc.height + 1 * cm)
|
||||
canvas.drawString(doc.leftMargin, doc.height + 0.5 * cm, self.filiere)
|
||||
canvas.drawRightString(doc.width + doc.leftMargin, doc.height + 0.5 * cm, self.title)
|
||||
canvas.line(doc.leftMargin, doc.height + 0.2 * cm, doc.width + doc.leftMargin, doc.height + 0.2 * cm)
|
||||
canvas.restoreState()
|
||||
|
||||
def set_normal_template_page(self):
|
||||
first_page_table_frame = Frame(
|
||||
self.leftMargin, self.bottomMargin, self.width + 1 * cm, self.height - 3 * cm,
|
||||
id='first_table', showBoundary=0, leftPadding=0 * cm
|
||||
)
|
||||
later_pages_table_frame = Frame(
|
||||
self.leftMargin, self.bottomMargin, self.width + 1 * cm, self.height - 2 * cm,
|
||||
id='later_table', showBoundary=0, leftPadding=0 * cm
|
||||
)
|
||||
# Page template
|
||||
first_page = PageTemplate(id='FirstPage', frames=[first_page_table_frame], onPage=self.header)
|
||||
later_pages = PageTemplate(id='LaterPages', frames=[later_pages_table_frame], onPage=self.later_header)
|
||||
self.addPageTemplates([first_page, later_pages])
|
||||
self.story = [NextPageTemplate(['*', 'LaterPages'])]
|
||||
|
||||
|
||||
class ChargeSheetPDF(EpcBaseDocTemplate):
|
||||
"""
|
||||
|
|
@ -206,7 +186,9 @@ class ChargeSheetPDF(EpcBaseDocTemplate):
|
|||
self.teacher = teacher
|
||||
filename = slugify('{0}_{1}'.format(teacher.last_name, teacher.first_name)) + '.pdf'
|
||||
super().__init__(filename)
|
||||
self.set_normal_template_page()
|
||||
self.addPageTemplates([
|
||||
PageTemplate(id='FirstPage', frames=[self.page_frame], onPage=self.header)
|
||||
])
|
||||
|
||||
def produce(self, activities):
|
||||
destinataire = '{0}<br/>{1}'.format(self.teacher.civility, str(self.teacher))
|
||||
|
|
@ -370,7 +352,9 @@ class ExpertEDEPDF(EpcBaseDocTemplate):
|
|||
def __init__(self, student, **kwargs):
|
||||
filename = slugify('{0}_{1}'.format(student.last_name, student.first_name)) + '.pdf'
|
||||
super().__init__(filename, title="", **kwargs)
|
||||
self.set_normal_template_page()
|
||||
self.addPageTemplates([
|
||||
PageTemplate(id='FirstPage', frames=[self.page_frame], onPage=self.header)
|
||||
])
|
||||
|
||||
def produce(self, student):
|
||||
# Expert adress
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue