2021-12-11 16:46:15 +01:00
|
|
|
# -*- mode: python -*-
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# Gestion scolarite IUT
|
|
|
|
#
|
2023-01-02 13:16:27 +01:00
|
|
|
# Copyright (c) 1999 - 2023 Emmanuel Viennet. All rights reserved.
|
2021-12-11 16:46:15 +01: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
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
"""Génération du bulletin en format XML / compatibilité ScoDoc 7
|
|
|
|
|
|
|
|
=> exporte quelques résultats BUT dans le format des anciens bulletins XML ScoDoc 7
|
|
|
|
afin d'avoir un affichage acceptable sur les ENT anciens.
|
|
|
|
|
|
|
|
Les plate-formes modernes utilisent uniquement la version JSON (but/bulletin_but.py)
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
import datetime
|
|
|
|
from xml.etree import ElementTree
|
|
|
|
from xml.etree.ElementTree import Element
|
|
|
|
|
|
|
|
from app import log
|
|
|
|
from app.but import bulletin_but
|
|
|
|
from app.models import FormSemestre, Identite
|
|
|
|
import app.scodoc.sco_utils as scu
|
|
|
|
import app.scodoc.notesdb as ndb
|
2023-02-12 13:36:47 +01:00
|
|
|
from app.scodoc import codes_cursus
|
2021-12-11 16:46:15 +01:00
|
|
|
from app.scodoc import sco_edit_ue
|
|
|
|
from app.scodoc import sco_etud
|
|
|
|
from app.scodoc import sco_photos
|
|
|
|
from app.scodoc import sco_preferences
|
|
|
|
from app.scodoc import sco_xml
|
2022-11-14 08:32:17 +01:00
|
|
|
from app.scodoc.sco_xml import quote_xml_attr
|
2021-12-11 16:46:15 +01:00
|
|
|
|
|
|
|
|
|
|
|
def bulletin_but_xml_compat(
|
|
|
|
formsemestre_id,
|
|
|
|
etudid,
|
|
|
|
doc=None, # XML document
|
|
|
|
force_publishing=False,
|
|
|
|
xml_nodate=False,
|
|
|
|
xml_with_decisions=False, # inclue les decisions même si non publiées
|
|
|
|
version="long",
|
|
|
|
) -> str:
|
|
|
|
"""Bulletin XML au format ScoDoc 7, avec informations "BUT" """
|
|
|
|
from app.scodoc import sco_bulletins
|
|
|
|
|
|
|
|
log(
|
2023-03-20 11:17:38 +01:00
|
|
|
f"bulletin_but_xml_compat( formsemestre_id={formsemestre_id}, etudid={etudid} )"
|
2021-12-11 16:46:15 +01:00
|
|
|
)
|
2023-03-20 11:17:38 +01:00
|
|
|
etud = Identite.get_etud(etudid)
|
|
|
|
formsemestre = FormSemestre.get_formsemestre(formsemestre_id)
|
2022-01-09 10:11:50 +01:00
|
|
|
results = bulletin_but.ResultatsSemestreBUT(formsemestre)
|
2022-01-16 23:47:52 +01:00
|
|
|
nb_inscrits = results.get_inscriptions_counts()[scu.INSCRIT]
|
2022-03-06 22:40:20 +01:00
|
|
|
# etat_inscription = etud.inscription_etat(formsemestre.id)
|
2022-01-16 23:47:52 +01:00
|
|
|
etat_inscription = results.formsemestre.etuds_inscriptions[etudid].etat
|
2022-01-09 10:11:50 +01:00
|
|
|
if (not formsemestre.bul_hide_xml) or force_publishing:
|
2022-01-07 18:09:45 +01:00
|
|
|
published = 1
|
2021-12-11 16:46:15 +01:00
|
|
|
else:
|
2022-01-07 18:09:45 +01:00
|
|
|
published = 0
|
2021-12-11 16:46:15 +01:00
|
|
|
if xml_nodate:
|
|
|
|
docdate = ""
|
|
|
|
else:
|
|
|
|
docdate = datetime.datetime.now().isoformat()
|
|
|
|
el = {
|
|
|
|
"etudid": str(etudid),
|
|
|
|
"formsemestre_id": str(formsemestre_id),
|
|
|
|
"date": docdate,
|
2022-01-07 18:09:45 +01:00
|
|
|
"publie": str(published),
|
2021-12-11 16:46:15 +01:00
|
|
|
}
|
2022-01-09 10:11:50 +01:00
|
|
|
if formsemestre.etapes:
|
|
|
|
el["etape_apo"] = formsemestre.etapes[0].etape_apo or ""
|
2021-12-11 16:46:15 +01:00
|
|
|
n = 2
|
2022-01-09 10:11:50 +01:00
|
|
|
for et in formsemestre.etapes[1:]:
|
2021-12-11 16:46:15 +01:00
|
|
|
el["etape_apo" + str(n)] = et.etape_apo or ""
|
|
|
|
n += 1
|
|
|
|
x = Element("bulletinetud", **el)
|
|
|
|
if doc:
|
|
|
|
is_appending = True
|
|
|
|
doc.append(x)
|
|
|
|
else:
|
|
|
|
is_appending = False
|
|
|
|
doc = x
|
|
|
|
# Infos sur l'etudiant
|
|
|
|
doc.append(
|
|
|
|
Element(
|
|
|
|
"etudiant",
|
|
|
|
etudid=str(etudid),
|
|
|
|
code_nip=etud.code_nip or "",
|
|
|
|
code_ine=etud.code_ine or "",
|
2022-11-14 08:32:17 +01:00
|
|
|
nom=quote_xml_attr(etud.nom),
|
|
|
|
prenom=quote_xml_attr(etud.prenom),
|
|
|
|
civilite=quote_xml_attr(etud.civilite_str),
|
|
|
|
sexe=quote_xml_attr(etud.civilite_str), # compat
|
|
|
|
photo_url=quote_xml_attr(sco_photos.get_etud_photo_url(etud.id)),
|
|
|
|
email=quote_xml_attr(etud.get_first_email() or ""),
|
|
|
|
emailperso=quote_xml_attr(etud.get_first_email("emailperso") or ""),
|
2021-12-11 16:46:15 +01:00
|
|
|
)
|
|
|
|
)
|
|
|
|
# Disponible pour publication ?
|
|
|
|
if not published:
|
2022-01-08 15:27:40 +01:00
|
|
|
return sco_xml.XML_HEADER + ElementTree.tostring(doc).decode(
|
|
|
|
scu.SCO_ENCODING
|
|
|
|
) # stop !
|
2022-01-09 10:11:50 +01:00
|
|
|
|
|
|
|
if etat_inscription == scu.INSCRIT:
|
|
|
|
# Moyenne générale:
|
|
|
|
doc.append(
|
2021-12-11 16:46:15 +01:00
|
|
|
Element(
|
|
|
|
"note",
|
2022-01-09 10:11:50 +01:00
|
|
|
value=scu.fmt_note(results.etud_moy_gen[etud.id]),
|
|
|
|
min=scu.fmt_note(results.etud_moy_gen.min()),
|
|
|
|
max=scu.fmt_note(results.etud_moy_gen.max()),
|
|
|
|
moy=scu.fmt_note(results.etud_moy_gen.mean()), # moyenne des moy. gen.
|
2021-12-11 16:46:15 +01:00
|
|
|
)
|
|
|
|
)
|
2022-01-25 10:45:13 +01:00
|
|
|
rang = 0 # XXX TODO rang de l'étudiant selon la moy gen indicative
|
|
|
|
# valeur du bonus sport
|
|
|
|
if results.bonus is not None:
|
|
|
|
bonus = results.bonus[etud.id]
|
|
|
|
else:
|
|
|
|
bonus = 0
|
2022-01-09 10:11:50 +01:00
|
|
|
doc.append(Element("rang", value=str(rang), ninscrits=str(nb_inscrits)))
|
|
|
|
# XXX TODO: ajouter "rang_group" : rangs dans les partitions
|
|
|
|
doc.append(Element("note_max", value="20")) # notes toujours sur 20
|
|
|
|
doc.append(Element("bonus_sport_culture", value=str(bonus)))
|
|
|
|
# Liste les UE / modules /evals
|
2022-02-12 09:40:33 +01:00
|
|
|
for ue in results.ues: # avec bonus
|
2022-01-09 10:11:50 +01:00
|
|
|
rang_ue = 0 # XXX TODO rang de l'étudiant dans cette UE
|
|
|
|
nb_inscrits_ue = (
|
|
|
|
nb_inscrits # approx: compliqué de définir le "nb d'inscrit à une UE"
|
|
|
|
)
|
|
|
|
x_ue = Element(
|
|
|
|
"ue",
|
|
|
|
id=str(ue.id),
|
2022-11-14 08:32:17 +01:00
|
|
|
numero=quote_xml_attr(ue.numero),
|
|
|
|
acronyme=quote_xml_attr(ue.acronyme or ""),
|
|
|
|
titre=quote_xml_attr(ue.titre or ""),
|
|
|
|
code_apogee=quote_xml_attr(ue.code_apogee or ""),
|
2022-01-09 10:11:50 +01:00
|
|
|
)
|
|
|
|
doc.append(x_ue)
|
2023-02-12 13:36:47 +01:00
|
|
|
if ue.type != codes_cursus.UE_SPORT:
|
2022-01-09 10:11:50 +01:00
|
|
|
v = results.etud_moy_ue[ue.id][etud.id]
|
2022-02-12 09:40:33 +01:00
|
|
|
vmin = results.etud_moy_ue[ue.id].min()
|
|
|
|
vmax = results.etud_moy_ue[ue.id].max()
|
2022-01-09 10:11:50 +01:00
|
|
|
else:
|
2022-02-12 09:40:33 +01:00
|
|
|
v = results.bonus or 0.0
|
|
|
|
vmin = vmax = 0.0
|
2022-01-09 10:11:50 +01:00
|
|
|
x_ue.append(
|
|
|
|
Element(
|
|
|
|
"note",
|
|
|
|
value=scu.fmt_note(v),
|
2022-02-12 09:40:33 +01:00
|
|
|
min=scu.fmt_note(vmin),
|
|
|
|
max=scu.fmt_note(vmax),
|
2021-12-11 16:46:15 +01:00
|
|
|
)
|
2022-01-09 10:11:50 +01:00
|
|
|
)
|
|
|
|
x_ue.append(Element("ects", value=str(ue.ects if ue.ects else 0)))
|
|
|
|
x_ue.append(Element("rang", value=str(rang_ue)))
|
|
|
|
x_ue.append(Element("effectif", value=str(nb_inscrits_ue)))
|
|
|
|
# Liste les modules rattachés à cette UE
|
2022-02-11 08:52:09 +01:00
|
|
|
for modimpl in results.formsemestre.modimpls:
|
2022-01-09 10:11:50 +01:00
|
|
|
# Liste ici uniquement les modules rattachés à cette UE
|
|
|
|
if modimpl.module.ue.id == ue.id:
|
2022-01-09 22:33:08 +01:00
|
|
|
# mod_moy = scu.fmt_note(results.etud_moy_ue[ue.id][etud.id])
|
2022-02-13 09:57:37 +01:00
|
|
|
try:
|
|
|
|
coef = results.modimpl_coefs_df[modimpl.id][ue.id]
|
|
|
|
except KeyError:
|
|
|
|
coef = 0.0
|
2022-01-09 10:11:50 +01:00
|
|
|
x_mod = Element(
|
|
|
|
"module",
|
|
|
|
id=str(modimpl.id),
|
|
|
|
code=str(modimpl.module.code or ""),
|
|
|
|
coefficient=str(coef),
|
|
|
|
numero=str(modimpl.module.numero or 0),
|
2022-11-14 08:32:17 +01:00
|
|
|
titre=quote_xml_attr(modimpl.module.titre or ""),
|
|
|
|
abbrev=quote_xml_attr(modimpl.module.abbrev or ""),
|
|
|
|
code_apogee=quote_xml_attr(modimpl.module.code_apogee or ""),
|
2021-12-11 16:46:15 +01:00
|
|
|
)
|
2022-02-11 17:03:27 +01:00
|
|
|
# XXX TODO rangs et effectifs
|
|
|
|
# --- notes de chaque eval:
|
|
|
|
if version != "short":
|
|
|
|
for e in modimpl.evaluations:
|
|
|
|
if e.visibulletin or version == "long":
|
|
|
|
x_eval = Element(
|
|
|
|
"evaluation",
|
|
|
|
jour=e.jour.isoformat() if e.jour else "",
|
|
|
|
heure_debut=e.heure_debut.isoformat()
|
|
|
|
if e.heure_debut
|
|
|
|
else "",
|
|
|
|
heure_fin=e.heure_fin.isoformat()
|
|
|
|
if e.heure_debut
|
|
|
|
else "",
|
|
|
|
coefficient=str(e.coefficient),
|
|
|
|
# pas les poids en XML compat
|
|
|
|
evaluation_type=str(e.evaluation_type),
|
2022-11-14 08:32:17 +01:00
|
|
|
description=quote_xml_attr(e.description),
|
2022-02-11 17:03:27 +01:00
|
|
|
# notes envoyées sur 20, ceci juste pour garder trace:
|
|
|
|
note_max_origin=str(e.note_max),
|
2021-12-11 16:46:15 +01:00
|
|
|
)
|
2022-02-11 17:03:27 +01:00
|
|
|
x_mod.append(x_eval)
|
2022-02-14 13:55:07 +01:00
|
|
|
try:
|
|
|
|
x_eval.append(
|
|
|
|
Element(
|
|
|
|
"note",
|
|
|
|
value=scu.fmt_note(
|
|
|
|
results.modimpls_results[
|
|
|
|
e.moduleimpl_id
|
|
|
|
].evals_notes[e.id][etud.id],
|
|
|
|
note_max=e.note_max,
|
|
|
|
),
|
|
|
|
)
|
2022-02-11 17:03:27 +01:00
|
|
|
)
|
2022-02-14 13:55:07 +01:00
|
|
|
except KeyError:
|
|
|
|
x_eval.append(
|
|
|
|
Element("note", value="", note_max="")
|
|
|
|
)
|
|
|
|
|
2022-02-11 17:03:27 +01:00
|
|
|
# XXX TODO: Evaluations incomplètes ou futures: XXX
|
2022-01-09 10:11:50 +01:00
|
|
|
# XXX TODO UE capitalisee (listee seulement si meilleure que l'UE courante)
|
2021-12-11 16:46:15 +01:00
|
|
|
|
|
|
|
# --- Absences
|
|
|
|
if sco_preferences.get_preference("bul_show_abs", formsemestre_id):
|
2022-01-09 10:11:50 +01:00
|
|
|
nbabs, nbabsjust = formsemestre.get_abs_count(etud.id)
|
2021-12-11 16:46:15 +01:00
|
|
|
doc.append(Element("absences", nbabs=str(nbabs), nbabsjust=str(nbabsjust)))
|
|
|
|
|
|
|
|
# -------- LA SUITE EST COPIEE SANS MODIF DE sco_bulletins_xml.py ---------
|
|
|
|
# TODO : refactoring
|
|
|
|
|
|
|
|
# --- Decision Jury
|
|
|
|
if (
|
|
|
|
sco_preferences.get_preference("bul_show_decision", formsemestre_id)
|
|
|
|
or xml_with_decisions
|
|
|
|
):
|
|
|
|
infos, dpv = sco_bulletins.etud_descr_situation_semestre(
|
|
|
|
etudid,
|
2023-03-08 22:56:11 +01:00
|
|
|
formsemestre,
|
2021-12-11 16:46:15 +01:00
|
|
|
format="xml",
|
|
|
|
show_uevalid=sco_preferences.get_preference(
|
|
|
|
"bul_show_uevalid", formsemestre_id
|
|
|
|
),
|
|
|
|
)
|
|
|
|
x_situation = Element("situation")
|
2022-11-14 08:32:17 +01:00
|
|
|
x_situation.text = quote_xml_attr(infos["situation"])
|
2021-12-11 16:46:15 +01:00
|
|
|
doc.append(x_situation)
|
|
|
|
if dpv:
|
|
|
|
decision = dpv["decisions"][0]
|
|
|
|
etat = decision["etat"]
|
|
|
|
if decision["decision_sem"]:
|
|
|
|
code = decision["decision_sem"]["code"] or ""
|
|
|
|
else:
|
|
|
|
code = ""
|
|
|
|
if (
|
|
|
|
decision["decision_sem"]
|
|
|
|
and "compense_formsemestre_id" in decision["decision_sem"]
|
|
|
|
):
|
|
|
|
doc.append(
|
|
|
|
Element(
|
|
|
|
"decision",
|
|
|
|
code=code,
|
|
|
|
etat=str(etat),
|
|
|
|
compense_formsemestre_id=str(
|
|
|
|
decision["decision_sem"]["compense_formsemestre_id"] or ""
|
|
|
|
),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
doc.append(Element("decision", code=code, etat=str(etat)))
|
|
|
|
|
|
|
|
if decision[
|
|
|
|
"decisions_ue"
|
|
|
|
]: # and sco_preferences.get_preference( 'bul_show_uevalid', formsemestre_id): always publish (car utile pour export Apogee)
|
|
|
|
for ue_id in decision["decisions_ue"].keys():
|
|
|
|
ue = sco_edit_ue.ue_list({"ue_id": ue_id})[0]
|
|
|
|
doc.append(
|
|
|
|
Element(
|
|
|
|
"decision_ue",
|
|
|
|
ue_id=str(ue["ue_id"]),
|
2022-11-14 08:32:17 +01:00
|
|
|
numero=quote_xml_attr(ue["numero"]),
|
|
|
|
acronyme=quote_xml_attr(ue["acronyme"]),
|
|
|
|
titre=quote_xml_attr(ue["titre"]),
|
2021-12-11 16:46:15 +01:00
|
|
|
code=decision["decisions_ue"][ue_id]["code"],
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
for aut in decision["autorisations"]:
|
|
|
|
doc.append(
|
|
|
|
Element(
|
|
|
|
"autorisation_inscription", semestre_id=str(aut["semestre_id"])
|
|
|
|
)
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
doc.append(Element("decision", code="", etat="DEM"))
|
|
|
|
# --- Appreciations
|
|
|
|
cnx = ndb.GetDBConnexion()
|
|
|
|
apprecs = sco_etud.appreciations_list(
|
|
|
|
cnx, args={"etudid": etudid, "formsemestre_id": formsemestre_id}
|
|
|
|
)
|
|
|
|
for appr in apprecs:
|
|
|
|
x_appr = Element(
|
|
|
|
"appreciation",
|
|
|
|
date=ndb.DateDMYtoISO(appr["date"]),
|
|
|
|
)
|
2022-11-14 08:32:17 +01:00
|
|
|
x_appr.text = quote_xml_attr(appr["comment"])
|
2021-12-11 16:46:15 +01:00
|
|
|
doc.append(x_appr)
|
|
|
|
|
|
|
|
if is_appending:
|
|
|
|
return None
|
|
|
|
else:
|
|
|
|
return sco_xml.XML_HEADER + ElementTree.tostring(doc).decode(scu.SCO_ENCODING)
|