2020-09-26 16:19:37 +02:00
|
|
|
# -*- mode: python -*-
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# Gestion scolarite IUT
|
|
|
|
#
|
2023-12-31 23:04:06 +01:00
|
|
|
# Copyright (c) 1999 - 2024 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@gmail.com
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
"""Extraction de données pour poursuites d'études
|
|
|
|
|
|
|
|
Recapitule tous les semestres validés dans une feuille excel.
|
|
|
|
"""
|
2021-02-03 22:00:41 +01:00
|
|
|
import collections
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2021-09-18 10:10:02 +02:00
|
|
|
from flask import url_for, g, request
|
2021-07-11 17:37:12 +02:00
|
|
|
|
2022-02-13 23:53:11 +01:00
|
|
|
from app.comp import res_sem
|
2022-03-27 22:25:00 +02:00
|
|
|
from app.comp.res_compat import NotesTableCompat
|
2022-02-13 23:53:11 +01:00
|
|
|
from app.models import FormSemestre
|
2021-06-19 23:21:37 +02:00
|
|
|
import app.scodoc.sco_utils as scu
|
2023-06-30 15:34:50 +02:00
|
|
|
from app.scodoc import sco_assiduites
|
2021-06-19 23:21:37 +02:00
|
|
|
from app.scodoc import sco_formsemestre
|
|
|
|
from app.scodoc import sco_groups
|
|
|
|
from app.scodoc import sco_preferences
|
|
|
|
from app.scodoc import sco_etud
|
|
|
|
from app.scodoc.gen_tables import GenTable
|
2023-02-12 13:36:47 +01:00
|
|
|
from app.scodoc.codes_cursus import code_semestre_validant, code_semestre_attente
|
2024-01-20 21:34:28 +01:00
|
|
|
import sco_version
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
2024-01-20 21:34:28 +01:00
|
|
|
def etud_get_poursuite_info(sem: dict, etud: dict) -> dict:
|
2021-01-01 18:40:47 +01:00
|
|
|
"""{ 'nom' : ..., 'semlist' : [ { 'semestre_id': , 'moy' : ... }, {}, ...] }"""
|
2024-01-20 21:34:28 +01:00
|
|
|
infos = {}
|
|
|
|
infos.update(etud) # copie nom, prenom, civilite, ...
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
# Now add each semester, starting from the first one
|
|
|
|
semlist = []
|
|
|
|
current_id = sem["semestre_id"]
|
|
|
|
for sem_id in range(1, current_id + 1):
|
|
|
|
sem_descr = None
|
|
|
|
for s in etud["sems"]:
|
|
|
|
if s["semestre_id"] == sem_id:
|
|
|
|
etudid = etud["etudid"]
|
2024-10-29 19:18:36 +01:00
|
|
|
formsemestre = FormSemestre.get_or_404(s["formsemestre_id"])
|
2022-02-13 23:53:11 +01:00
|
|
|
nt: NotesTableCompat = res_sem.load_formsemestre_results(formsemestre)
|
2020-09-26 16:19:37 +02:00
|
|
|
dec = nt.get_etud_decision_sem(etudid)
|
|
|
|
# Moyennes et rangs des UE
|
2021-12-24 00:08:25 +01:00
|
|
|
ues = nt.get_ues_stat_dict(filter_sport=True)
|
2022-02-12 22:57:46 +01:00
|
|
|
moy_ues = []
|
|
|
|
for ue in ues:
|
|
|
|
ue_status = nt.get_etud_ue_status(etudid, ue["ue_id"])
|
|
|
|
if ue_status:
|
|
|
|
moy_ues.append(
|
|
|
|
(
|
|
|
|
ue["acronyme"],
|
2024-02-26 12:54:18 +01:00
|
|
|
scu.fmt_note(ue_status["moy"]),
|
2022-02-12 22:57:46 +01:00
|
|
|
)
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
moy_ues.append((ue["acronyme"], ""))
|
2020-09-26 16:19:37 +02:00
|
|
|
rg_ues = [
|
|
|
|
("rang_" + ue["acronyme"], nt.ue_rangs[ue["ue_id"]][0][etudid])
|
|
|
|
for ue in ues
|
|
|
|
]
|
|
|
|
|
|
|
|
# Moyennes et rang des modules
|
2021-12-26 19:15:47 +01:00
|
|
|
modimpls = nt.get_modimpls_dict() # recupération des modules
|
2020-09-26 16:19:37 +02:00
|
|
|
modules = []
|
|
|
|
rangs = []
|
|
|
|
for ue in ues: # on parcourt chaque UE
|
|
|
|
for modimpl in modimpls: # dans chaque UE les modules
|
|
|
|
if modimpl["module"]["ue_id"] == ue["ue_id"]:
|
2024-01-20 21:34:28 +01:00
|
|
|
code_module = modimpl["module"]["code"] or ""
|
|
|
|
note_module = scu.fmt_note(
|
2020-09-26 16:19:37 +02:00
|
|
|
nt.get_etud_mod_moy(modimpl["moduleimpl_id"], etudid)
|
|
|
|
)
|
2024-01-20 21:34:28 +01:00
|
|
|
# si étudiant inscrit au module, sauf BUT
|
|
|
|
if (note_module != "NI") and not nt.is_apc:
|
2022-02-11 16:34:02 +01:00
|
|
|
if nt.mod_rangs is not None:
|
2024-01-20 21:34:28 +01:00
|
|
|
rang_module = nt.mod_rangs[
|
|
|
|
modimpl["moduleimpl_id"]
|
|
|
|
][0][etudid]
|
2022-02-11 16:34:02 +01:00
|
|
|
else:
|
2024-01-20 21:34:28 +01:00
|
|
|
rang_module = ""
|
|
|
|
modules.append([code_module, note_module])
|
|
|
|
rangs.append(["rang_" + code_module, rang_module])
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
# Absences
|
2024-03-01 12:40:05 +01:00
|
|
|
nbabsnj, nbabsjust, _ = sco_assiduites.get_assiduites_count(
|
|
|
|
etudid, nt.sem
|
|
|
|
)
|
2024-01-20 21:34:28 +01:00
|
|
|
# En BUT, prend tout, sinon ne prend que les semestre validés par le jury
|
|
|
|
if nt.is_apc or (
|
2020-09-26 16:19:37 +02:00
|
|
|
dec
|
2024-01-20 21:34:28 +01:00
|
|
|
# not sem_descr pour ne prendre que le semestre validé le plus récent:
|
|
|
|
and not sem_descr
|
2020-09-26 16:19:37 +02:00
|
|
|
and (
|
|
|
|
code_semestre_validant(dec["code"])
|
|
|
|
or code_semestre_attente(dec["code"])
|
|
|
|
)
|
2022-09-30 22:43:39 +02:00
|
|
|
and nt.get_etud_etat(etudid) == scu.INSCRIT
|
2020-09-26 16:19:37 +02:00
|
|
|
):
|
|
|
|
d = [
|
2021-02-04 20:02:44 +01:00
|
|
|
("moy", scu.fmt_note(nt.get_etud_moy_gen(etudid))),
|
|
|
|
("moy_promo", scu.fmt_note(nt.moy_moy)),
|
2020-09-26 16:19:37 +02:00
|
|
|
("rang", nt.get_etud_rang(etudid)),
|
|
|
|
("effectif", len(nt.T)),
|
|
|
|
("date_debut", s["date_debut"]),
|
|
|
|
("date_fin", s["date_fin"]),
|
|
|
|
("periode", "%s - %s" % (s["mois_debut"], s["mois_fin"])),
|
2024-03-01 12:40:05 +01:00
|
|
|
("AbsNonJust", nbabsnj),
|
2021-07-19 19:53:01 +02:00
|
|
|
("AbsJust", nbabsjust),
|
2020-09-26 16:19:37 +02:00
|
|
|
]
|
2024-01-20 21:34:28 +01:00
|
|
|
# ajout des 2 champs notes des modules et classement dans chaque module
|
|
|
|
d += moy_ues + rg_ues + modules + rangs
|
2020-09-26 16:19:37 +02:00
|
|
|
sem_descr = collections.OrderedDict(d)
|
|
|
|
if not sem_descr:
|
|
|
|
sem_descr = collections.OrderedDict(
|
|
|
|
[
|
|
|
|
("moy", ""),
|
|
|
|
("moy_promo", ""),
|
|
|
|
("rang", ""),
|
|
|
|
("effectif", ""),
|
|
|
|
("date_debut", ""),
|
|
|
|
("date_fin", ""),
|
|
|
|
("periode", ""),
|
|
|
|
]
|
|
|
|
)
|
|
|
|
sem_descr["semestre_id"] = sem_id
|
|
|
|
semlist.append(sem_descr)
|
|
|
|
|
2024-01-20 21:34:28 +01:00
|
|
|
infos["semlist"] = semlist
|
|
|
|
return infos
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
def _flatten_info(info):
|
2024-01-20 21:34:28 +01:00
|
|
|
"""met la liste des infos semestres "a plat"
|
|
|
|
S1_moy, S1_rang, ..., S2_moy, ...
|
|
|
|
"""
|
2020-09-26 16:19:37 +02:00
|
|
|
ids = []
|
|
|
|
for s in info["semlist"]:
|
|
|
|
for k, v in s.items():
|
|
|
|
if k != "semestre_id":
|
|
|
|
label = "S%s_%s" % (s["semestre_id"], k)
|
|
|
|
info[label] = v
|
|
|
|
ids.append(label)
|
|
|
|
return ids
|
|
|
|
|
|
|
|
|
2024-01-20 21:34:28 +01:00
|
|
|
def _get_etud_info_groupes(group_ids, etat=None):
|
2021-06-02 22:40:34 +02:00
|
|
|
"""liste triée d'infos (dict) sur les etudiants du groupe indiqué.
|
|
|
|
Attention: lent, car plusieurs requetes SQL par etudiant !
|
|
|
|
"""
|
|
|
|
etuds = []
|
|
|
|
for group_id in group_ids:
|
2021-08-19 10:28:35 +02:00
|
|
|
members = sco_groups.get_group_members(group_id, etat=etat)
|
2021-06-02 22:40:34 +02:00
|
|
|
for m in members:
|
2021-06-19 23:21:37 +02:00
|
|
|
etud = sco_etud.get_etud_info(etudid=m["etudid"], filled=True)[0]
|
2021-06-02 22:40:34 +02:00
|
|
|
etuds.append(etud)
|
|
|
|
|
|
|
|
return etuds
|
|
|
|
|
|
|
|
|
2023-09-21 10:20:19 +02:00
|
|
|
def formsemestre_poursuite_report(formsemestre_id, fmt="html"):
|
2021-01-01 18:40:47 +01:00
|
|
|
"""Table avec informations "poursuite" """
|
2021-08-19 10:28:35 +02:00
|
|
|
sem = sco_formsemestre.get_formsemestre(formsemestre_id)
|
2024-01-20 21:34:28 +01:00
|
|
|
etuds = _get_etud_info_groupes([sco_groups.get_default_group(formsemestre_id)])
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
infos = []
|
|
|
|
ids = []
|
|
|
|
for etud in etuds:
|
2021-07-11 17:37:12 +02:00
|
|
|
fiche_url = url_for(
|
2024-01-20 14:49:36 +01:00
|
|
|
"scolar.fiche_etud", scodoc_dept=g.scodoc_dept, etudid=etud["etudid"]
|
2021-07-11 17:37:12 +02:00
|
|
|
)
|
|
|
|
etud["_nom_target"] = fiche_url
|
|
|
|
etud["_prenom_target"] = fiche_url
|
2024-01-20 21:34:28 +01:00
|
|
|
etud["_nom_td_attrs"] = f"""id="{etud['etudid']}" class="etudinfo" """
|
2021-08-21 00:24:51 +02:00
|
|
|
info = etud_get_poursuite_info(sem, etud)
|
2020-09-26 16:19:37 +02:00
|
|
|
idd = _flatten_info(info)
|
|
|
|
# On recupere la totalite des UEs dans ids
|
2024-01-29 22:33:06 +01:00
|
|
|
for key in idd:
|
|
|
|
if key not in ids:
|
|
|
|
ids += [key]
|
|
|
|
info["etudid"] = etud["etudid"]
|
2020-09-26 16:19:37 +02:00
|
|
|
infos.append(info)
|
|
|
|
#
|
|
|
|
column_ids = (
|
2024-01-29 22:33:06 +01:00
|
|
|
(("etudid",) if fmt.startswith("xls") else ())
|
|
|
|
+ ("civilite_str", "nom", "prenom", "annee", "date_naissance")
|
2020-09-26 16:19:37 +02:00
|
|
|
+ tuple(ids)
|
|
|
|
+ ("debouche",)
|
|
|
|
)
|
|
|
|
titles = {}
|
|
|
|
for c in column_ids:
|
|
|
|
titles[c] = c
|
|
|
|
tab = GenTable(
|
|
|
|
titles=titles,
|
|
|
|
columns_ids=column_ids,
|
|
|
|
rows=infos,
|
|
|
|
# html_col_width='4em',
|
|
|
|
html_sortable=True,
|
|
|
|
html_class="table_leftalign table_listegroupe",
|
|
|
|
pdf_link=False, # pas d'export pdf
|
2021-07-28 17:03:54 +02:00
|
|
|
preferences=sco_preferences.SemPreferences(formsemestre_id),
|
2024-05-22 00:06:30 +02:00
|
|
|
table_id="formsemestre_poursuite_report",
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
2021-02-04 20:02:44 +01:00
|
|
|
tab.filename = scu.make_filename("poursuite " + sem["titreannee"])
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2021-08-21 17:07:44 +02:00
|
|
|
tab.origin = (
|
|
|
|
"Généré par %s le " % sco_version.SCONAME + scu.timedate_human_repr() + ""
|
|
|
|
)
|
2020-09-26 16:19:37 +02:00
|
|
|
tab.caption = "Récapitulatif %s." % sem["titreannee"]
|
|
|
|
tab.html_caption = "Récapitulatif %s." % sem["titreannee"]
|
2021-09-18 10:10:02 +02:00
|
|
|
tab.base_url = "%s?formsemestre_id=%s" % (request.base_url, formsemestre_id)
|
2020-09-26 16:19:37 +02:00
|
|
|
return tab.make_page(
|
|
|
|
title="""<h2 class="formsemestre">Poursuite d'études</h2>""",
|
2023-09-21 10:20:19 +02:00
|
|
|
fmt=fmt,
|
2020-09-26 16:19:37 +02:00
|
|
|
with_html_headers=True,
|
|
|
|
)
|