ScoDoc-PE/sco_trombino_tours.py

481 lines
16 KiB
Python
Raw Permalink Normal View History

2020-09-26 16:19:37 +02:00
# -*- mode: python -*-
# -*- coding: utf-8 -*-
##############################################################################
#
# Gestion scolarite IUT
#
2021-01-01 17:51:08 +01:00
# Copyright (c) 1999 - 2021 Emmanuel Viennet. All rights reserved.
2020-09-26 16:19:37 +02:00
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Emmanuel Viennet emmanuel.viennet@viennet.net
#
##############################################################################
"""Photos: trombinoscopes - Version IUT Tours
Code contribué par Jérôme Billoue, IUT de Tours, 2014
Modification Jérome Billoue,Vincent Grimaud, IUT de Tours, 2017
"""
try:
from cStringIO import StringIO
except:
from StringIO import StringIO
from zipfile import ZipFile, BadZipfile
import xml
import tempfile
2021-02-04 20:02:44 +01:00
import sco_utils as scu
2020-09-26 16:19:37 +02:00
from notes_log import log
2021-01-10 18:54:39 +01:00
import sco_abs
2020-09-26 16:19:37 +02:00
import scolars
import sco_photos
import sco_formsemestre
import sco_groups
import sco_groups_view
import sco_trombino
from sco_pdf import *
from reportlab.lib import colors
from reportlab.lib import pagesizes
from reportlab.lib.pagesizes import A4, A3
# Paramétrage de l'aspect graphique:
PHOTOWIDTH = 2.8 * cm
COLWIDTH = 3.4 * cm
N_PER_ROW = 5
def pdf_trombino_tours(
context,
group_ids=[], # liste des groupes à afficher
formsemestre_id=None, # utilisé si pas de groupes selectionné
REQUEST=None,
):
2021-01-01 18:40:47 +01:00
"""Generation du trombinoscope en fichier PDF"""
2020-09-26 16:19:37 +02:00
# Informations sur les groupes à afficher:
groups_infos = sco_groups_view.DisplayedGroupsInfos(
context, group_ids, formsemestre_id=formsemestre_id, REQUEST=REQUEST
)
DeptName = context.get_preference("DeptName")
DeptFullName = context.get_preference("DeptFullName")
UnivName = context.get_preference("UnivName")
InstituteName = context.get_preference("InstituteName")
# Generate PDF page
StyleSheet = styles.getSampleStyleSheet()
objects = []
T = Table(
[
[Paragraph(SU(InstituteName), StyleSheet["Heading3"])],
[Paragraph(SU("Département " + DeptFullName), StyleSheet["Heading3"])],
[
Paragraph(
SU("Date ............ / ............ / ......................"),
StyleSheet["Normal"],
),
Paragraph(
SU(
"Module ......................................................."
),
StyleSheet["Normal"],
),
],
[
Paragraph(
SU("de ............h............ à ............h............ "),
StyleSheet["Normal"],
),
Paragraph(
SU("Enseignant ................................................."),
StyleSheet["Normal"],
),
],
[
Table(
[
[
"Séance notée :",
" ",
"DS ",
" ",
"TP Contrôle ",
" ",
"Autre cas (TD ou TP noté, QCM, etc...)",
]
],
style=TableStyle(
[
("ALIGN", (0, 0), (-1, -1), "LEFT"),
("BOX", (1, 0), (1, 0), 0.75, black),
("BOX", (3, 0), (3, 0), 0.75, black),
("BOX", (5, 0), (5, 0), 0.75, black),
]
),
)
],
],
colWidths=(COLWIDTH * N_PER_ROW) / 2,
style=TableStyle(
[
("ALIGN", (0, 0), (-1, -1), "LEFT"),
("SPAN", (0, 1), (1, 1)),
("SPAN", (0, 4), (1, 4)),
("BOTTOMPADDING", (0, -1), (-1, -1), 10),
("BOX", (0, 0), (-1, -1), 0.75, black),
]
),
)
objects.append(T)
groups = ""
for group_id in groups_infos.group_ids:
if group_id != "None":
members, group, group_tit, sem, nbdem = sco_groups.get_group_infos(
context, group_id, "I"
)
groups += " %s" % group_tit
L = []
currow = []
if sem["semestre_id"] != -1:
currow = [
Paragraph(
SU(
"<para align=center>Semestre %s</para>" % sem["semestre_id"]
),
StyleSheet["Normal"],
)
]
currow += [" "] * (N_PER_ROW - len(currow) - 1)
currow += [
Paragraph(
SU("<para align=center>%s</para>" % sem["anneescolaire"]),
StyleSheet["Normal"],
)
]
L.append(currow)
currow = [" "] * N_PER_ROW
L.append(currow)
currow = []
currow.append(
Paragraph(
SU("<para align=center><b>" + group_tit + "</b></para>"),
StyleSheet["Heading3"],
)
)
n = 1
for m in members:
img = sco_trombino._get_etud_platypus_image(
context, m, image_width=PHOTOWIDTH
)
etud_main_group = sco_groups.get_etud_main_group(
context, m["etudid"], sem
)
if group_id != etud_main_group["group_id"]:
text_group = " (" + etud_main_group["group_name"] + ")"
else:
text_group = ""
elem = Table(
[
[img],
[
Paragraph(
SU(
"<para align=center><font size=8>"
+ scolars.format_prenom(m["prenom"])
+ " "
+ scolars.format_nom(m["nom"])
+ text_group
+ "</font></para>"
),
StyleSheet["Normal"],
)
],
],
colWidths=[COLWIDTH],
style=TableStyle([("ALIGN", (0, 0), (-1, -1), "CENTER")]),
)
currow.append(elem)
if n == (N_PER_ROW - 1):
L.append(currow)
currow = []
n = (n + 1) % N_PER_ROW
if currow:
currow += [" "] * (N_PER_ROW - len(currow))
L.append(currow)
if not L:
T = Paragraph(SU("Aucune photo à exporter !"), StyleSheet["Normal"])
else:
T = Table(
L,
colWidths=[COLWIDTH] * N_PER_ROW,
style=TableStyle(
[
("LEFTPADDING", (0, 0), (-1, -1), 0),
("RIGHTPADDING", (0, 0), (-1, -1), 0),
("BOTTOMPADDING", (0, 0), (-1, -1), 0),
("TOPPADDING", (0, 1), (-1, -1), 0),
("TOPPADDING", (0, 0), (-1, 0), 10),
("LINEBELOW", (1, 0), (-2, 0), 0.75, black),
("VALIGN", (0, 0), (-1, 1), "MIDDLE"),
("VALIGN", (0, 2), (-1, -1), "TOP"),
("VALIGN", (0, 2), (0, 2), "MIDDLE"),
("SPAN", (0, 0), (0, 1)),
("SPAN", (-1, 0), (-1, 1)),
]
),
)
objects.append(T)
T = Table(
[
[
Paragraph(
SU(
"Nombre d'absents : ................. (Merci d'entourer les absents SVP)"
),
StyleSheet["Normal"],
)
]
],
colWidths=(COLWIDTH * N_PER_ROW),
style=TableStyle(
[
("ALIGN", (0, 0), (-1, -1), "CENTER"),
("BOTTOMPADDING", (0, -1), (-1, -1), 10),
("BOX", (0, 0), (-1, -1), 0.75, black),
]
),
)
objects.append(T)
# Réduit sur une page
objects = [KeepInFrame(0, 0, objects, mode="shrink")]
# Build document
report = StringIO() # in-memory document, no disk file
filename = "trombino-%s-%s.pdf" % (DeptName, groups_infos.groups_filename)
document = BaseDocTemplate(report)
document.addPageTemplates(
2021-01-04 11:31:18 +01:00
ScolarsPageTemplate(
document, context=context, preferences=context.get_preferences()
)
2020-09-26 16:19:37 +02:00
)
document.build(objects)
data = report.getvalue()
2021-02-04 20:02:44 +01:00
return scu.sendPDFFile(REQUEST, data, filename)
2020-09-26 16:19:37 +02:00
# Feuille d'absences en pdf avec photos:
def pdf_feuille_releve_absences(
context,
group_ids=[], # liste des groupes à afficher
formsemestre_id=None, # utilisé si pas de groupes selectionné
REQUEST=None,
):
2021-01-01 18:40:47 +01:00
"""Generation de la feuille d'absence en fichier PDF, avec photos"""
2020-09-26 16:19:37 +02:00
NB_CELL_AM = context.get_preference("feuille_releve_abs_AM")
NB_CELL_PM = context.get_preference("feuille_releve_abs_PM")
COLWIDTH = 0.85 * cm
if context.get_preference("feuille_releve_abs_samedi"):
2021-01-10 18:54:39 +01:00
days = sco_abs.DAYNAMES[:6] # Lundi, ..., Samedi
2020-09-26 16:19:37 +02:00
else:
2021-01-10 18:54:39 +01:00
days = sco_abs.DAYNAMES[:5] # Lundi, ..., Vendredi
2020-09-26 16:19:37 +02:00
nb_days = len(days)
# Informations sur les groupes à afficher:
groups_infos = sco_groups_view.DisplayedGroupsInfos(
context, group_ids, formsemestre_id=formsemestre_id, REQUEST=REQUEST
)
DeptName = context.get_preference("DeptName")
DeptFullName = context.get_preference("DeptFullName")
UnivName = context.get_preference("UnivName")
InstituteName = context.get_preference("InstituteName")
# Generate PDF page
StyleSheet = styles.getSampleStyleSheet()
objects = [
Table(
[
[
Paragraph(SU(InstituteName), StyleSheet["Heading3"]),
Paragraph(
SU(
"<para align=right>Semaine ..................................................................</para>"
),
StyleSheet["Normal"],
),
],
[
Paragraph(
SU("Département " + DeptFullName), StyleSheet["Heading3"]
),
"",
],
],
style=TableStyle(
[("SPAN", (0, 1), (1, 1)), ("BOTTOMPADDING", (0, -1), (-1, -1), 10)]
),
)
]
currow = [""] * (NB_CELL_AM + 1 + NB_CELL_PM + 1)
elem_day = Table(
[currow],
colWidths=([COLWIDTH] * (NB_CELL_AM + 1 + NB_CELL_PM + 1)),
style=TableStyle(
[
("GRID", (0, 0), (NB_CELL_AM - 1, 0), 0.25, black),
(
"GRID",
(NB_CELL_AM + 1, 0),
(NB_CELL_AM + NB_CELL_PM, 0),
0.25,
black,
),
]
),
)
W = []
currow = []
for n in range(nb_days):
currow.append(elem_day)
W.append(currow)
elem_week = Table(
W,
colWidths=([COLWIDTH * (NB_CELL_AM + 1 + NB_CELL_PM + 1)] * nb_days),
style=TableStyle(
[
("LEFTPADDING", (0, 0), (-1, -1), 0),
("RIGHTPADDING", (0, 0), (-1, -1), 0),
("BOTTOMPADDING", (0, 0), (-1, -1), 0),
("TOPPADDING", (0, 0), (-1, -1), 0),
]
),
)
currow = []
for n in range(nb_days):
currow += [Paragraph(SU("<b>" + days[n] + "</b>"), StyleSheet["Normal"])]
elem_day_name = Table(
[currow],
colWidths=([COLWIDTH * (NB_CELL_AM + 1 + NB_CELL_PM + 1)] * nb_days),
style=TableStyle(
[
("LEFTPADDING", (0, 0), (-1, -1), 0),
("RIGHTPADDING", (0, 0), (-1, -1), 0),
("BOTTOMPADDING", (0, 0), (-1, -1), 0),
("TOPPADDING", (0, 0), (-1, -1), 0),
]
),
)
for group_id in groups_infos.group_ids:
members, group, group_tit, sem, nbdem = sco_groups.get_group_infos(
context, group_id, "I"
)
L = []
currow = [
Paragraph(SU("<b>Groupe " + group_tit + "</b>"), StyleSheet["Normal"])
]
currow.append(elem_day_name)
L.append(currow)
currow = [Paragraph(SU("Initiales enseignant :"), StyleSheet["Normal"])]
currow.append(elem_week)
L.append(currow)
currow = [Paragraph(SU("Initiales module :"), StyleSheet["Normal"])]
currow.append(elem_week)
L.append(currow)
for m in members:
currow = [
Paragraph(
SU(
scolars.format_nom(m["nom"])
+ " "
+ scolars.format_prenom(m["prenom"])
),
StyleSheet["Normal"],
)
]
currow.append(elem_week)
L.append(currow)
if not L:
T = Paragraph(SU("Aucun étudiant !"), StyleSheet["Normal"])
else:
T = Table(
L,
colWidths=(
[5.0 * cm, (COLWIDTH * (NB_CELL_AM + 1 + NB_CELL_PM + 1) * nb_days)]
),
style=TableStyle(
[
("VALIGN", (0, 0), (-1, -1), "MIDDLE"),
("LEFTPADDING", (0, 0), (-1, -1), 0),
("RIGHTPADDING", (0, 0), (-1, -1), 0),
("BOTTOMPADDING", (0, 0), (-1, -1), 3),
("TOPPADDING", (0, 0), (-1, -1), 3),
("BOTTOMPADDING", (0, -1), (-1, -1), 10),
(
"ROWBACKGROUNDS",
(0, 2),
(-1, -1),
(colors.white, colors.lightgrey),
),
]
),
)
objects.append(T)
# Réduit sur une page
objects = [KeepInFrame(0, 0, objects, mode="shrink")]
# Build document
report = StringIO() # in-memory document, no disk file
filename = "absences-%s-%s.pdf" % (DeptName, groups_infos.groups_filename)
if context.get_preference("feuille_releve_abs_taille") == "A3":
taille = A3
elif context.get_preference("feuille_releve_abs_taille") == "A4":
taille = A4
if context.get_preference("feuille_releve_abs_format") == "Paysage":
document = BaseDocTemplate(report, pagesize=landscape(taille))
else:
document = BaseDocTemplate(report, pagesize=taille)
document.addPageTemplates(
2021-01-04 11:31:18 +01:00
ScolarsPageTemplate(
document, context=context, preferences=context.get_preferences()
)
2020-09-26 16:19:37 +02:00
)
document.build(objects)
data = report.getvalue()
2021-02-04 20:02:44 +01:00
return scu.sendPDFFile(REQUEST, data, filename)