Update colors in PDF module

This commit is contained in:
alazo 2018-02-16 14:52:26 +01:00
parent 29815bb6eb
commit 7e748bd41f
6 changed files with 82 additions and 96 deletions

View file

@ -1,14 +1,17 @@
from reportlab.platypus import (SimpleDocTemplate, Spacer, Frame, Paragraph, Preformatted, from reportlab.platypus import (
PageTemplate, NextPageTemplate, FrameBreak, Table, TableStyle) SimpleDocTemplate, Spacer, Frame, Paragraph, Preformatted, PageTemplate, NextPageTemplate,
FrameBreak, Table, TableStyle
)
from reportlab.lib.pagesizes import A4, landscape from reportlab.lib.pagesizes import A4, landscape
from reportlab.lib.units import cm from reportlab.lib.units import cm
from reportlab.lib.enums import TA_LEFT, TA_CENTER from reportlab.lib.enums import TA_LEFT
from reportlab.lib import colors from reportlab.lib import colors
from reportlab.lib.colors import HexColor
from reportlab.lib.styles import ParagraphStyle as ps from reportlab.lib.styles import ParagraphStyle as ps
from reportlab.pdfgen import canvas from reportlab.pdfgen import canvas
from django.contrib.staticfiles.finders import find from django.contrib.staticfiles.finders import find
from django.conf import settings
style_normal = ps(name='CORPS', fontName='Helvetica', fontSize=9, alignment=TA_LEFT) style_normal = ps(name='CORPS', fontName='Helvetica', fontSize=9, alignment=TA_LEFT)
style_bold = ps(name='CORPS', fontName='Helvetica-Bold', fontSize=10, alignment=TA_LEFT) style_bold = ps(name='CORPS', fontName='Helvetica-Bold', fontSize=10, alignment=TA_LEFT)
@ -17,11 +20,11 @@ LOGO_EPC = find('img/logo_EPC.png')
LOGO_ESNE = find('img/logo_ESNE.png') LOGO_ESNE = find('img/logo_ESNE.png')
FILIERE = 'Formation EDS' FILIERE = 'Formation EDS'
class NumberedCanvas(canvas.Canvas): class NumberedCanvas(canvas.Canvas):
""" """
Page number and pages counter Page number and pages counter
""" """
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
canvas.Canvas.__init__(self, *args, **kwargs) canvas.Canvas.__init__(self, *args, **kwargs)
self._saved_page_states = [] self._saved_page_states = []
@ -70,7 +73,7 @@ class EpcBaseDocTemplate(SimpleDocTemplate):
canvas.line(doc.leftMargin, doc.height + 0.2 * cm, doc.width + doc.leftMargin, doc.height + 0.2 * cm) canvas.line(doc.leftMargin, doc.height + 0.2 * cm, doc.width + doc.leftMargin, doc.height + 0.2 * cm)
canvas.restoreState() canvas.restoreState()
def setNormalTemplatePage(self): def normal_template_page(self):
first_page_table_frame = Frame(self.leftMargin, self.bottomMargin, self.width + 1 * cm, self.height - 4 * cm, first_page_table_frame = Frame(self.leftMargin, self.bottomMargin, self.width + 1 * cm, self.height - 4 * cm,
id='first_table', showBoundary=0, leftPadding=0 * 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, later_pages_table_frame = Frame(self.leftMargin, self.bottomMargin, self.width + 1 * cm, self.height - 2 * cm,
@ -81,7 +84,7 @@ class EpcBaseDocTemplate(SimpleDocTemplate):
self.addPageTemplates([first_page, later_pages]) self.addPageTemplates([first_page, later_pages])
self.story = [NextPageTemplate(['*', 'LaterPages'])] self.story = [NextPageTemplate(['*', 'LaterPages'])]
def setSixSemestreTemplatePage(self): def six_semester_template_page(self):
frame_size = (8 * cm, 6.5 * cm,) frame_size = (8 * cm, 6.5 * cm,)
w, h = frame_size w, h = frame_size
@ -102,7 +105,7 @@ class ModuleDescriptionPdf(EpcBaseDocTemplate):
def __init__(self, filename): def __init__(self, filename):
super().__init__(filename, 'Module de formation', A4) super().__init__(filename, 'Module de formation', A4)
self.setNormalTemplatePage() self.normal_template_page()
def produce(self, module): def produce(self, module):
str_competence = '' str_competence = ''
@ -177,7 +180,7 @@ class FormationPlanPdf(EpcBaseDocTemplate):
def __init__(self, filename): def __init__(self, filename):
super().__init__(filename, 'Plan de formation', landscape(A4)) super().__init__(filename, 'Plan de formation', landscape(A4))
self.setNormalTemplatePage() self.normal_template_page()
def formating(self, el1='', length=40): def formating(self, el1='', length=40):
el1 = '' if el1 == '' else el1.__str__() el1 = '' if el1 == '' else el1.__str__()
@ -201,60 +204,65 @@ class FormationPlanPdf(EpcBaseDocTemplate):
[self.formating(domain[6]), self.formating(process[9], 60), 'M17_1', '', 'M17_2', '', 'M17_3', ''], [self.formating(domain[6]), self.formating(process[9], 60), 'M17_1', '', 'M17_2', '', 'M17_3', ''],
[self.formating(domain[7]), self.formating(process[10], 60), 'Macc', '', '', '', '', ''], [self.formating(domain[7]), self.formating(process[10], 60), 'Macc', '', '', '', '', ''],
] ]
t = Table(data, colWidths=[7 * cm, 9 * cm, 1.5 * cm, 1.5 * cm, 1.5 * cm, 1.5 * cm, 1.5 * cm, 1.5 * cm], t = Table(
spaceBefore=0.5 * cm, spaceAfter=1 * cm data, colWidths=[7 * cm, 9 * cm, 1.5 * cm, 1.5 * cm, 1.5 * cm, 1.5 * cm, 1.5 * cm, 1.5 * cm],
) spaceBefore=0.5 * cm, spaceAfter=1 * cm
t.setStyle(TableStyle([ )
('SIZE', (0, 0), (-1, -1), 8), t.setStyle(
('FONT', (0, 0), (-1, 0), 'Helvetica-Bold'), TableStyle(
('VALIGN', (0, 0), (-1, -1), 'MIDDLE'), [
('ALIGN', (2, 0), (-1, -1), 'CENTER'), ('SIZE', (0, 0), (-1, -1), 8),
('GRID', (0, 0), (-1, -1), 0.25, colors.black), ('FONT', (0, 0), (-1, 0), 'Helvetica-Bold'),
# Domaine 1 ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'),
('SPAN', (0, 1), (0, 4)), ('ALIGN', (2, 0), (-1, -1), 'CENTER'),
('SPAN', (1, 1), (1, 2)), ('GRID', (0, 0), (-1, -1), 0.25, colors.black),
('SPAN', (1, 3), (1, 4)), # Domaine 1
('BACKGROUND', (0, 1), (1, 4), colors.orange), ('SPAN', (0, 1), (0, 4)),
('BACKGROUND', (2, 1), (2, 2), colors.orange), ('SPAN', (1, 1), (1, 2)),
('BACKGROUND', (5, 3), (5, 3), colors.orange), ('SPAN', (1, 3), (1, 4)),
('BACKGROUND', (3, 4), (3, 4), colors.orange), ('BACKGROUND', (0, 1), (1, 4), settings.DOMAINE_COULEURS['D1']),
# Domaine 2 ('BACKGROUND', (2, 1), (2, 2), settings.DOMAINE_COULEURS['D1']),
('SPAN', (0, 5), (0, 7)), ('BACKGROUND', (5, 3), (5, 3), settings.DOMAINE_COULEURS['D1']),
('BACKGROUND', (0, 5), (1, 7), colors.red), ('BACKGROUND', (3, 4), (3, 4), settings.DOMAINE_COULEURS['D1']),
('BACKGROUND', (2, 5), (2, 5), colors.red), # Domaine 2
('BACKGROUND', (4, 5), (4, 5), colors.red), ('SPAN', (0, 5), (0, 7)),
('BACKGROUND', (6, 6), (6, 6), colors.red), ('BACKGROUND', (0, 5), (1, 7), settings.DOMAINE_COULEURS['D2']),
('BACKGROUND', (7, 6), (7, 6), colors.red), ('BACKGROUND', (2, 5), (2, 5), settings.DOMAINE_COULEURS['D2']),
('BACKGROUND', (6, 7), (6, 7), colors.red), ('BACKGROUND', (4, 5), (4, 5), settings.DOMAINE_COULEURS['D2']),
# Domaine 3 ('BACKGROUND', (6, 6), (6, 6), settings.DOMAINE_COULEURS['D2']),
('SPAN', (0, 8), (0, 9)), ('BACKGROUND', (7, 6), (7, 6), settings.DOMAINE_COULEURS['D2']),
('SPAN', (1, 6), (1, 7)), ('BACKGROUND', (6, 7), (6, 7), settings.DOMAINE_COULEURS['D2']),
('SPAN', (4, 8), (5, 8)), # Domaine 3
('SPAN', (4, 9), (5, 9)), ('SPAN', (0, 8), (0, 9)),
('BACKGROUND', (0, 8), (1, 9), colors.pink), ('SPAN', (1, 6), (1, 7)),
('BACKGROUND', (4, 8), (6, 8), colors.pink), ('SPAN', (4, 8), (5, 8)),
('BACKGROUND', (4, 9), (5, 9), colors.pink), ('SPAN', (4, 9), (5, 9)),
# Domaine 4 ('BACKGROUND', (0, 8), (1, 9), settings.DOMAINE_COULEURS['D3']),
('BACKGROUND', (0, 10), (1, 10), HexColor('#AD7FA8')), ('BACKGROUND', (4, 8), (6, 8), settings.DOMAINE_COULEURS['D3']),
('BACKGROUND', (4, 10), (4, 10), HexColor('#AD7FA8')), ('BACKGROUND', (4, 9), (5, 9), settings.DOMAINE_COULEURS['D3']),
('BACKGROUND', (6, 10), (6, 10), HexColor('#AD7FA8')), # Domaine 4
# Domaine 5 ('BACKGROUND', (0, 10), (1, 10), settings.DOMAINE_COULEURS['D4']),
('SPAN', (2, 11), (-1, 11)), ('BACKGROUND', (4, 10), (4, 10), settings.DOMAINE_COULEURS['D4']),
('BACKGROUND', (0, 11), (-1, 11), HexColor('#729FCF')), ('BACKGROUND', (6, 10), (6, 10), settings.DOMAINE_COULEURS['D4']),
# Domaine 6 # Domaine 5
('SPAN', (2, 12), (3, 12)), ('SPAN', (2, 11), (-1, 11)),
('SPAN', (4, 12), (5, 12)), ('BACKGROUND', (0, 11), (-1, 11), settings.DOMAINE_COULEURS['D5']),
('SPAN', (6, 12), (7, 12)), # Domaine 6
('BACKGROUND', (0, 12), (-1, 12), colors.lightgreen), ('SPAN', (2, 12), (3, 12)),
# Domaine 7 ('SPAN', (4, 12), (5, 12)),
('SPAN', (2, 13), (3, 13)), ('SPAN', (6, 12), (7, 12)),
('SPAN', (4, 13), (5, 13)), ('BACKGROUND', (0, 12), (-1, 12), settings.DOMAINE_COULEURS['D6']),
('SPAN', (6, 13), (7, 13)), # Domaine 7
('BACKGROUND', (0, 13), (-1, 13), colors.white), ('SPAN', (2, 13), (3, 13)),
# Domaine 8 ('SPAN', (4, 13), (5, 13)),
('SPAN', (2, 14), (-1, 14)), ('SPAN', (6, 13), (7, 13)),
('BACKGROUND', (0, 14), (-1, 14), colors.lightgrey), ('BACKGROUND', (0, 13), (-1, 13), settings.DOMAINE_COULEURS['D7']),
])) # Domaine 8
('SPAN', (2, 14), (-1, 14)),
('BACKGROUND', (0, 14), (-1, 14), settings.DOMAINE_COULEURS['D8']),
]
)
)
t.hAlign = TA_LEFT t.hAlign = TA_LEFT
self.story.append(t) self.story.append(t)
self.build(self.story, canvasmaker=NumberedCanvas) self.build(self.story, canvasmaker=NumberedCanvas)
@ -267,7 +275,7 @@ class PeriodSemesterPdf(EpcBaseDocTemplate):
def __init__(self, filename): def __init__(self, filename):
super().__init__(filename, 'Périodes de formation', A4) super().__init__(filename, 'Périodes de formation', A4)
self.setSixSemestreTemplatePage() self.six_semester_template_page()
def produce(self, context): def produce(self, context):
for sem in range(1, 7): for sem in range(1, 7):
@ -277,15 +285,16 @@ class PeriodSemesterPdf(EpcBaseDocTemplate):
for line in modules: for line in modules:
value = getattr(line, 'sem{0}'.format(sem)) value = getattr(line, 'sem{0}'.format(sem))
data.append([line.nom, '{0} h.'.format(value)]) data.append([line.nom, '{0} h.'.format(value)])
t = Table(data, colWidths=[6.5 * cm, 1 * cm], spaceBefore=0.5 * cm, spaceAfter=1 * cm, hAlign=TA_LEFT, t = Table(
style=[ data, colWidths=[6.5 * cm, 1 * cm], spaceBefore=0.5 * cm, spaceAfter=1 * cm, hAlign=TA_LEFT,
('ALIGN', (0, 0), (0, 0), 'LEFT'), style=[
('ALIGN', (1, 0), (-1, -1), 'RIGHT'), ('ALIGN', (0, 0), (0, 0), 'LEFT'),
('LINEBELOW', (0, 0), (1, 0), 1, colors.black), ('ALIGN', (1, 0), (-1, -1), 'RIGHT'),
('SIZE', (0, 0), (-1, -1), 9), ('LINEBELOW', (0, 0), (1, 0), 1, colors.black),
('FONT', (0, 0), (-1, 0), 'Helvetica-Bold'), ('SIZE', (0, 0), (-1, -1), 9),
] ('FONT', (0, 0), (-1, 0), 'Helvetica-Bold'),
) ]
)
self.story.append(t) self.story.append(t)
self.story.append(FrameBreak()) self.story.append(FrameBreak())

Binary file not shown.

Before

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 86 KiB

View file

@ -114,20 +114,6 @@ STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
MEDIA_URL = '/media/' MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/') MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
"""
STUDENT_IMPORT_MAPPING = {
'Num élève': 'id_ext',
'Nom élève': 'nom',
'Prénom élève': 'prenom',
'Rue élève': 'adresse',
'Localité élève': 'localite', # pcode is separated from city in prepare_import
'Tél. élève': 'telephone',
'Natel élève': 'mobile',
'Email élève': 'email_rpn',
'Date nais. élève': 'date_naissance',
'Classe': 'klasse',
}
"""
DOMAINE_COULEURS = { DOMAINE_COULEURS = {
'D1': '#fcaf3e', 'D1': '#fcaf3e',

View file

@ -3,8 +3,6 @@
{% block coltype %}colMS{% endblock %} {% block coltype %}colMS{% endblock %}
{% block content %} {% block content %}
<div id="content-main"> <div id="content-main">

View file

@ -1,15 +1,8 @@
{% extends "./base_site.html" %} {% extends "./base_site.html" %}
{% load i18n static %} {% load i18n static %}
{% block coltype %}colMS{% endblock %} {% block coltype %}colMS{% endblock %}
{% block bodyclass %}{{ block.super }}{% endblock %} {% block bodyclass %}{{ block.super }}{% endblock %}
{% block content %} {% block content %}
<div id="content-main"> <div id="content-main">
<h1>Liste des domaines</h1> <h1>Liste des domaines</h1>