forked from ScoDoc/ScoDoc
Small fixes
This commit is contained in:
parent
82f0612883
commit
3afec00b5e
@ -42,12 +42,22 @@ La préférence 'bul_pdf_class_name' est obsolete (inutilisée).
|
||||
|
||||
|
||||
"""
|
||||
import time
|
||||
import cStringIO
|
||||
import collections
|
||||
import traceback
|
||||
import reportlab
|
||||
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Frame, PageBreak
|
||||
from reportlab.platypus import Table, TableStyle, Image, KeepInFrame
|
||||
|
||||
import sco_utils
|
||||
import VERSION
|
||||
from sco_exceptions import NoteProcessError
|
||||
import sco_preferences
|
||||
from notes_log import log
|
||||
import sco_formsemestre
|
||||
from sco_pdf import *
|
||||
import sco_pdf
|
||||
from sco_pdf import PDFLOCK
|
||||
|
||||
BULLETIN_CLASSES = (
|
||||
collections.OrderedDict()
|
||||
@ -145,7 +155,7 @@ class BulletinGenerator:
|
||||
dt,
|
||||
self.infos["etud"]["nom"],
|
||||
)
|
||||
filename = unescape_html(filename).replace(" ", "_").replace("&", "")
|
||||
filename = sco_utils.unescape_html(filename).replace(" ", "_").replace("&", "")
|
||||
return filename
|
||||
|
||||
def generate(self, format="", stand_alone=True):
|
||||
@ -166,8 +176,10 @@ class BulletinGenerator:
|
||||
def generate_html(self):
|
||||
"""Return bulletin as an HTML string"""
|
||||
H = ['<div class="notes_bulletin">']
|
||||
H.append(self.bul_table(format="html")) # table des notes
|
||||
H.append(self.bul_part_below(format="html")) # infos sous la table
|
||||
# table des notes:
|
||||
H.append(self.bul_table(format="html")) # pylint: disable=no-member
|
||||
# infos sous la table:
|
||||
H.append(self.bul_part_below(format="html")) # pylint: disable=no-member
|
||||
H.append("</div>")
|
||||
return "\n".join(H)
|
||||
|
||||
@ -179,10 +191,14 @@ class BulletinGenerator:
|
||||
"""
|
||||
formsemestre_id = self.infos["formsemestre_id"]
|
||||
|
||||
objects = self.bul_title_pdf() # partie haute du bulletin
|
||||
objects += self.bul_table(format="pdf") # table des notes
|
||||
objects += self.bul_part_below(format="pdf") # infos sous la table
|
||||
objects += self.bul_signatures_pdf() # signatures
|
||||
# partie haute du bulletin
|
||||
objects = self.bul_title_pdf() # pylint: disable=no-member
|
||||
# table des notes
|
||||
objects += self.bul_table(format="pdf") # pylint: disable=no-member
|
||||
# infos sous la table
|
||||
objects += self.bul_part_below(format="pdf") # pylint: disable=no-member
|
||||
# signatures
|
||||
objects += self.bul_signatures_pdf() # pylint: disable=no-member
|
||||
|
||||
# Réduit sur une page
|
||||
objects = [KeepInFrame(0, 0, objects, mode="shrink")]
|
||||
@ -194,13 +210,13 @@ class BulletinGenerator:
|
||||
# Generation du document PDF
|
||||
sem = sco_formsemestre.get_formsemestre(self.context, formsemestre_id)
|
||||
report = cStringIO.StringIO() # in-memory document, no disk file
|
||||
document = BaseDocTemplate(report)
|
||||
document = sco_pdf.BaseDocTemplate(report)
|
||||
document.addPageTemplates(
|
||||
ScolarsPageTemplate(
|
||||
sco_pdf.ScolarsPageTemplate(
|
||||
document,
|
||||
context=self.context,
|
||||
author="%s %s (E. Viennet) [%s]"
|
||||
% (SCONAME, SCOVERSION, self.description),
|
||||
% (VERSION.SCONAME, VERSION.SCOVERSION, self.description),
|
||||
title="Bulletin %s de %s"
|
||||
% (sem["titremois"], self.infos["etud"]["nomprenom"]),
|
||||
subject="Bulletin de note",
|
||||
@ -222,7 +238,9 @@ class BulletinGenerator:
|
||||
"""
|
||||
try:
|
||||
# put each table cell in a Paragraph
|
||||
Pt = [[Paragraph(SU(x), self.CellStyle) for x in line] for line in P]
|
||||
Pt = [
|
||||
[Paragraph(sco_pdf.SU(x), self.CellStyle) for x in line] for line in P
|
||||
]
|
||||
except:
|
||||
# enquête sur exception intermittente...
|
||||
log("*** bug in PDF buildTableObject:")
|
||||
|
@ -29,16 +29,22 @@
|
||||
- statistiques decisions
|
||||
- suivi cohortes
|
||||
"""
|
||||
import os
|
||||
import tempfile
|
||||
import urllib
|
||||
import re
|
||||
import time
|
||||
import mx
|
||||
import mx.DateTime
|
||||
from mx.DateTime import DateTime as mxDateTime
|
||||
import tempfile, urllib, re
|
||||
|
||||
|
||||
from notesdb import *
|
||||
from sco_utils import *
|
||||
import sco_utils as scu
|
||||
import VERSION
|
||||
from notes_log import log
|
||||
from gen_tables import GenTable
|
||||
import sco_excel, sco_pdf
|
||||
from notesdb import DateDMYtoISO
|
||||
from sco_exceptions import ScoValueError
|
||||
import sco_codes_parcours
|
||||
from sco_codes_parcours import code_semestre_validant
|
||||
import sco_parcours_dut
|
||||
@ -129,7 +135,7 @@ def _results_by_category(
|
||||
if Count.has_key(etud[category]):
|
||||
Count[etud[category]][etud[result]] += 1
|
||||
else:
|
||||
Count[etud[category]] = DictDefault(kv_dict={etud[result]: 1})
|
||||
Count[etud[category]] = scu.DictDefault(kv_dict={etud[result]: 1})
|
||||
# conversion en liste de dict
|
||||
C = [Count[cat] for cat in categories]
|
||||
# Totaux par lignes et colonnes
|
||||
@ -214,9 +220,9 @@ def formsemestre_report(
|
||||
formsemestre_id=formsemestre_id,
|
||||
)
|
||||
#
|
||||
tab.filename = make_filename("stats " + sem["titreannee"])
|
||||
tab.filename = scu.make_filename("stats " + sem["titreannee"])
|
||||
|
||||
tab.origin = "Généré par %s le " % VERSION.SCONAME + timedate_human_repr() + ""
|
||||
tab.origin = "Généré par %s le " % VERSION.SCONAME + scu.timedate_human_repr() + ""
|
||||
tab.caption = "Répartition des résultats par %s, semestre %s" % (
|
||||
category_name,
|
||||
sem["titreannee"],
|
||||
@ -259,7 +265,7 @@ def formsemestre_report_counts(
|
||||
Tableau comptage avec choix des categories
|
||||
"""
|
||||
sem = sco_formsemestre.get_formsemestre(context, formsemestre_id)
|
||||
category_name = strcapitalize(category)
|
||||
category_name = scu.strcapitalize(category)
|
||||
title = "Comptages " + category_name
|
||||
etuds = formsemestre_etuds_stats(context, sem, only_primo=only_primo)
|
||||
tab = formsemestre_report(
|
||||
@ -484,7 +490,7 @@ def table_suivi_cohorte(
|
||||
indices_sems.sort()
|
||||
for p in P:
|
||||
p.nb_etuds = 0 # nombre total d'etudiants dans la periode
|
||||
p.sems_by_id = DictDefault(defaultvalue=[])
|
||||
p.sems_by_id = scu.DictDefault(defaultvalue=[])
|
||||
for s in p.sems:
|
||||
p.sems_by_id[s["semestre_id"]].append(s)
|
||||
p.nb_etuds += len(s["members"])
|
||||
@ -623,8 +629,8 @@ def table_suivi_cohorte(
|
||||
rows=L,
|
||||
html_col_width="4em",
|
||||
html_sortable=True,
|
||||
filename=make_filename("cohorte " + sem["titreannee"]),
|
||||
origin="Généré par %s le " % VERSION.SCONAME + timedate_human_repr() + "",
|
||||
filename=scu.make_filename("cohorte " + sem["titreannee"]),
|
||||
origin="Généré par %s le " % VERSION.SCONAME + scu.timedate_human_repr() + "",
|
||||
caption="Suivi cohorte " + pp + sem["titreannee"] + dbac,
|
||||
page_title="Suivi cohorte " + sem["titreannee"],
|
||||
html_class="table_cohorte",
|
||||
@ -666,7 +672,6 @@ def formsemestre_suivi_cohorte(
|
||||
):
|
||||
"""Affiche suivi cohortes par numero de semestre"""
|
||||
percent = int(percent)
|
||||
sem = sco_formsemestre.get_formsemestre(context, formsemestre_id)
|
||||
tab, expl, bacs, bacspecialites, annee_bacs, sexes, statuts = table_suivi_cohorte(
|
||||
context,
|
||||
formsemestre_id,
|
||||
@ -1049,7 +1054,7 @@ def table_suivi_parcours(
|
||||
etuds, bacs, bacspecialites, annee_bacs, sexes, statuts = tsp_etud_list(
|
||||
context, formsemestre_id, only_primo=only_primo
|
||||
)
|
||||
codes_etuds = DictDefault(defaultvalue=[])
|
||||
codes_etuds = scu.DictDefault(defaultvalue=[])
|
||||
for etud in etuds:
|
||||
etud["codeparcours"], etud["decisions_jury"] = get_codeparcoursetud(
|
||||
context, etud
|
||||
@ -1105,7 +1110,7 @@ def table_suivi_parcours(
|
||||
columns_ids=columns_ids,
|
||||
rows=L,
|
||||
titles=titles,
|
||||
origin="Généré par %s le " % VERSION.SCONAME + timedate_human_repr() + "",
|
||||
origin="Généré par %s le " % VERSION.SCONAME + scu.timedate_human_repr() + "",
|
||||
caption="Parcours suivis, étudiants %s semestre " % primostr
|
||||
+ sem["titreannee"],
|
||||
page_title="Parcours " + sem["titreannee"],
|
||||
@ -1164,7 +1169,6 @@ def formsemestre_suivi_parcours(
|
||||
REQUEST=None,
|
||||
):
|
||||
"""Effectifs dans les differents parcours possibles."""
|
||||
sem = sco_formsemestre.get_formsemestre(context, formsemestre_id)
|
||||
tab = table_suivi_parcours(
|
||||
context,
|
||||
formsemestre_id,
|
||||
@ -1211,9 +1215,8 @@ def graph_parcours(
|
||||
statut="",
|
||||
):
|
||||
""""""
|
||||
if not WITH_PYDOT:
|
||||
if not scu.WITH_PYDOT:
|
||||
raise ScoValueError("pydot module is not installed")
|
||||
sem = sco_formsemestre.get_formsemestre(context, formsemestre_id)
|
||||
etuds, bacs, bacspecialites, annee_bacs, sexes, statuts = tsp_etud_list(
|
||||
context,
|
||||
formsemestre_id,
|
||||
@ -1227,12 +1230,12 @@ def graph_parcours(
|
||||
# log('graph_parcours: %s etuds (only_primo=%s)' % (len(etuds), only_primo))
|
||||
if not etuds:
|
||||
return "", etuds, bacs, bacspecialites, annee_bacs, sexes, statuts
|
||||
edges = DictDefault(
|
||||
edges = scu.DictDefault(
|
||||
defaultvalue=set()
|
||||
) # {(formsemestre_id_origin, formsemestre_id_dest) : etud_set}
|
||||
sems = {}
|
||||
effectifs = DictDefault(defaultvalue=set()) # formsemestre_id : etud_set
|
||||
decisions = DictDefault(defaultvalue={}) # formsemestre_id : { code : nb_etud }
|
||||
effectifs = scu.DictDefault(defaultvalue=set()) # formsemestre_id : etud_set
|
||||
decisions = scu.DictDefault(defaultvalue={}) # formsemestre_id : { code : nb_etud }
|
||||
isolated_nodes = []
|
||||
connected_nodes = set()
|
||||
diploma_nodes = []
|
||||
@ -1279,7 +1282,11 @@ def graph_parcours(
|
||||
dem_nodes[s["formsemestre_id"]] = nid
|
||||
edges[(s["formsemestre_id"], nid)].add(etudid)
|
||||
# ajout noeud pour NAR (seulement pour noeud de depart)
|
||||
if s["formsemestre_id"] == formsemestre_id and dec and dec["code"] == NAR:
|
||||
if (
|
||||
s["formsemestre_id"] == formsemestre_id
|
||||
and dec
|
||||
and dec["code"] == sco_codes_parcours.NAR
|
||||
):
|
||||
nid = "_nar_" + s["formsemestre_id"]
|
||||
nar_nodes[s["formsemestre_id"]] = nid
|
||||
edges[(s["formsemestre_id"], nid)].add(etudid)
|
||||
@ -1295,10 +1302,10 @@ def graph_parcours(
|
||||
edges[(s["formsemestre_id"], nid)].add(etudid)
|
||||
diploma_nodes.append(nid)
|
||||
#
|
||||
g = pydot.graph_from_edges(edges.keys())
|
||||
g = scu.pydot.graph_from_edges(edges.keys())
|
||||
for fid in isolated_nodes:
|
||||
if not fid in connected_nodes:
|
||||
n = pydot.Node(name=fid)
|
||||
n = scu.pydot.Node(name=fid)
|
||||
g.add_node(n)
|
||||
g.set("rankdir", "LR") # left to right
|
||||
g.set_fontname("Helvetica")
|
||||
@ -1306,7 +1313,7 @@ def graph_parcours(
|
||||
g.set_bgcolor("#fffff0") # ou 'transparent'
|
||||
# titres des semestres:
|
||||
for s in sems.values():
|
||||
n = pydot_get_node(g, s["formsemestre_id"])
|
||||
n = scu.pydot_get_node(g, s["formsemestre_id"])
|
||||
log("s['formsemestre_id'] = %s" % s["formsemestre_id"])
|
||||
log("n=%s" % n)
|
||||
log("get=%s" % g.get_node(s["formsemestre_id"]))
|
||||
@ -1324,31 +1331,31 @@ def graph_parcours(
|
||||
s["annee_fin"][2:],
|
||||
len(effectifs[s["formsemestre_id"]]),
|
||||
)
|
||||
n.set("label", suppress_accents(label))
|
||||
n.set("label", scu.suppress_accents(label))
|
||||
n.set_fontname("Helvetica")
|
||||
n.set_fontsize(8.0)
|
||||
n.set_width(1.2)
|
||||
n.set_shape("box")
|
||||
n.set_URL("formsemestre_status?formsemestre_id=" + s["formsemestre_id"])
|
||||
# semestre de depart en vert
|
||||
n = pydot_get_node(g, formsemestre_id)
|
||||
n = scu.pydot_get_node(g, formsemestre_id)
|
||||
n.set_color("green")
|
||||
# demissions en rouge, octagonal
|
||||
for nid in dem_nodes.values():
|
||||
n = pydot_get_node(g, nid)
|
||||
n = scu.pydot_get_node(g, nid)
|
||||
n.set_color("red")
|
||||
n.set_shape("octagon")
|
||||
n.set("label", "Dem.")
|
||||
|
||||
# NAR en rouge, Mcircle
|
||||
for nid in nar_nodes.values():
|
||||
n = pydot_get_node(g, nid)
|
||||
n = scu.pydot_get_node(g, nid)
|
||||
n.set_color("red")
|
||||
n.set_shape("Mcircle")
|
||||
n.set("label", NAR)
|
||||
n.set("label", sco_codes_parcours.NAR)
|
||||
# diplomes:
|
||||
for nid in diploma_nodes:
|
||||
n = pydot_get_node(g, nid)
|
||||
n = scu.pydot_get_node(g, nid)
|
||||
n.set_color("red")
|
||||
n.set_shape("ellipse")
|
||||
n.set("label", "Diplome") # bug si accent (pas compris pourquoi)
|
||||
@ -1367,7 +1374,7 @@ def graph_parcours(
|
||||
bubbles[src_id + ":" + dst_id] = etud_descr
|
||||
e.set_URL("__xxxetudlist__?" + src_id + ":" + dst_id)
|
||||
# Genere graphe
|
||||
f, path = tempfile.mkstemp(".gr")
|
||||
_, path = tempfile.mkstemp(".gr")
|
||||
g.write(path=path, format=format)
|
||||
data = open(path, "r").read()
|
||||
log("dot generated %d bytes in %s format" % (len(data), format))
|
||||
@ -1403,7 +1410,7 @@ def graph_parcours(
|
||||
)
|
||||
return (
|
||||
'<a xlink:href="formsemestre_status?formsemestre_id=%s" xlink:title="%s"'
|
||||
% (fid, suppress_accents(title))
|
||||
% (fid, scu.suppress_accents(title))
|
||||
) # evite accents car svg utf-8 vs page en latin1...
|
||||
|
||||
data = exp1.sub(repl_title, data)
|
||||
@ -1443,8 +1450,8 @@ def formsemestre_graph_parcours(
|
||||
sexe=sexe,
|
||||
statut=statut,
|
||||
)
|
||||
filename = make_filename("flux " + sem["titreannee"])
|
||||
return sco_pdf.sendPDFFile(REQUEST, doc, filename + ".pdf")
|
||||
filename = scu.make_filename("flux " + sem["titreannee"])
|
||||
return scu.sendPDFFile(REQUEST, doc, filename + ".pdf")
|
||||
elif format == "png":
|
||||
#
|
||||
doc, etuds, bacs, bacspecialites, annee_bacs, sexes, statuts = graph_parcours(
|
||||
@ -1458,7 +1465,7 @@ def formsemestre_graph_parcours(
|
||||
sexe=sexe,
|
||||
statut=statut,
|
||||
)
|
||||
filename = make_filename("flux " + sem["titreannee"])
|
||||
filename = scu.make_filename("flux " + sem["titreannee"])
|
||||
REQUEST.RESPONSE.setHeader(
|
||||
"content-disposition", 'attachment; filename="%s"' % filename
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user