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
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
"""
|
|
|
|
Rapport (table) avec dernier semestre fréquenté et débouché de chaque étudiant
|
|
|
|
"""
|
2024-08-24 08:06:46 +02:00
|
|
|
from flask import g, render_template, request, url_for
|
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
|
2024-09-09 16:21:51 +02:00
|
|
|
from app.models import Identite
|
2021-06-19 23:21:37 +02:00
|
|
|
import app.scodoc.sco_utils as scu
|
|
|
|
import app.scodoc.notesdb as ndb
|
|
|
|
from app.scodoc.gen_tables import GenTable
|
|
|
|
from app.scodoc import sco_preferences
|
2021-08-21 17:07:44 +02:00
|
|
|
import sco_version
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
2023-09-21 10:20:19 +02:00
|
|
|
def report_debouche_date(start_year=None, fmt="html"):
|
2021-09-30 09:37:18 +02:00
|
|
|
"""Rapport (table) pour les débouchés des étudiants sortis
|
|
|
|
à partir de l'année indiquée.
|
|
|
|
"""
|
2020-09-26 16:19:37 +02:00
|
|
|
if not start_year:
|
2021-09-30 09:37:18 +02:00
|
|
|
return report_debouche_ask_date("Année de début de la recherche")
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
start_year = int(start_year)
|
|
|
|
except ValueError:
|
|
|
|
return report_debouche_ask_date(
|
|
|
|
"Année invalide. Année de début de la recherche"
|
|
|
|
)
|
|
|
|
|
2023-09-21 10:20:19 +02:00
|
|
|
if fmt == "xls":
|
2020-09-26 16:19:37 +02:00
|
|
|
keep_numeric = True # pas de conversion des notes en strings
|
|
|
|
else:
|
|
|
|
keep_numeric = False
|
|
|
|
|
2021-08-21 00:24:51 +02:00
|
|
|
etudids = get_etudids_with_debouche(start_year)
|
|
|
|
tab = table_debouche_etudids(etudids, keep_numeric=keep_numeric)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2024-03-24 11:23:40 +01:00
|
|
|
tab.filename = scu.make_filename(f"debouche_scodoc_{start_year}")
|
|
|
|
tab.origin = f"Généré par {sco_version.SCONAME} le {scu.timedate_human_repr()}"
|
|
|
|
tab.caption = f"Récapitulatif débouchés à partir du 1/1/{start_year}."
|
|
|
|
tab.base_url = f"{request.base_url}?start_year={start_year}"
|
2020-09-26 16:19:37 +02:00
|
|
|
return tab.make_page(
|
|
|
|
title="""<h2 class="formsemestre">Débouchés étudiants </h2>""",
|
2024-09-09 16:21:51 +02:00
|
|
|
page_title="Débouchés étudiants",
|
2023-09-21 10:20:19 +02:00
|
|
|
fmt=fmt,
|
2020-09-26 16:19:37 +02:00
|
|
|
with_html_headers=True,
|
2024-08-24 08:06:46 +02:00
|
|
|
template="sco_page_dept.j2",
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-08-21 00:24:51 +02:00
|
|
|
def get_etudids_with_debouche(start_year):
|
2020-09-26 16:19:37 +02:00
|
|
|
"""Liste des etudids de tous les semestres terminant
|
|
|
|
à partir du 1er janvier de start_year
|
|
|
|
et ayant un 'debouche' renseigné.
|
|
|
|
"""
|
|
|
|
start_date = str(start_year) + "-01-01"
|
|
|
|
# Recupere tous les etudid avec un debouché renseigné et une inscription dans un semestre
|
|
|
|
# posterieur à la date de depart:
|
2021-07-28 17:03:54 +02:00
|
|
|
# r = ndb.SimpleDictFetch(
|
2020-09-26 16:19:37 +02:00
|
|
|
# """SELECT DISTINCT i.etudid
|
|
|
|
# FROM notes_formsemestre_inscription i, admissions adm, notes_formsemestre s
|
|
|
|
# WHERE adm.debouche is not NULL
|
|
|
|
# AND i.etudid = adm.etudid AND i.formsemestre_id = s.formsemestre_id
|
|
|
|
# AND s.date_fin >= %(start_date)s
|
|
|
|
# """,
|
|
|
|
# {'start_date' : start_date })
|
|
|
|
|
2021-06-15 13:59:56 +02:00
|
|
|
r = ndb.SimpleDictFetch(
|
2020-09-26 16:19:37 +02:00
|
|
|
"""SELECT DISTINCT i.etudid
|
2021-08-08 17:38:46 +02:00
|
|
|
FROM notes_formsemestre_inscription i, notes_formsemestre s, itemsuivi it
|
|
|
|
WHERE i.etudid = it.etudid
|
|
|
|
AND i.formsemestre_id = s.id AND s.date_fin >= %(start_date)s
|
2021-09-30 09:37:18 +02:00
|
|
|
AND s.dept_id = %(dept_id)s
|
2021-08-08 17:38:46 +02:00
|
|
|
""",
|
2021-09-30 09:37:18 +02:00
|
|
|
{"start_date": start_date, "dept_id": g.scodoc_dept_id},
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
return [x["etudid"] for x in r]
|
|
|
|
|
|
|
|
|
2021-08-21 00:24:51 +02:00
|
|
|
def table_debouche_etudids(etudids, keep_numeric=True):
|
2022-02-13 23:53:11 +01:00
|
|
|
"""Rapport pour ces étudiants"""
|
2024-03-24 11:23:40 +01:00
|
|
|
rows = []
|
|
|
|
# Recherche les débouchés:
|
2024-09-09 16:21:51 +02:00
|
|
|
# itemsuivi_etuds = {etudid: itemsuivi_list_etud(etudid) for etudid in etudids}
|
2024-03-24 11:23:40 +01:00
|
|
|
all_tags = set()
|
2020-09-26 16:19:37 +02:00
|
|
|
for etudid in etudids:
|
2024-09-09 16:21:51 +02:00
|
|
|
etud = Identite.get_etud(etudid)
|
|
|
|
# collecte les tags
|
|
|
|
all_tags.update(tag.title for item in etud.itemsuivis for tag in item.tags)
|
2020-09-26 16:19:37 +02:00
|
|
|
# retrouve le "dernier" semestre (au sens de la date de fin)
|
2024-09-09 16:21:51 +02:00
|
|
|
formsemestres = etud.get_formsemestres()
|
|
|
|
dates_fin = [s.date_fin for s in formsemestres]
|
|
|
|
imax = dates_fin.index(max(dates_fin))
|
|
|
|
formsemestre = formsemestres[imax]
|
2022-02-13 23:53:11 +01:00
|
|
|
nt: NotesTableCompat = res_sem.load_formsemestre_results(formsemestre)
|
2020-09-26 16:19:37 +02:00
|
|
|
row = {
|
|
|
|
"etudid": etudid,
|
2024-09-09 16:21:51 +02:00
|
|
|
"civilite": etud.civilite,
|
|
|
|
"nom": etud.nom,
|
|
|
|
"prenom": etud.prenom,
|
2021-07-11 17:37:12 +02:00
|
|
|
"_nom_target": url_for(
|
2024-01-20 14:49:36 +01:00
|
|
|
"scolar.fiche_etud", scodoc_dept=g.scodoc_dept, etudid=etudid
|
2021-07-11 17:37:12 +02:00
|
|
|
),
|
|
|
|
"_prenom_target": url_for(
|
2024-01-20 14:49:36 +01:00
|
|
|
"scolar.fiche_etud", scodoc_dept=g.scodoc_dept, etudid=etudid
|
2021-07-11 17:37:12 +02:00
|
|
|
),
|
2024-09-09 16:21:51 +02:00
|
|
|
"_nom_td_attrs": f'id="{etudid}" class="etudinfo"',
|
2020-09-26 16:19:37 +02:00
|
|
|
# 'debouche' : etud['debouche'],
|
2020-12-24 00:07:17 +01:00
|
|
|
"moy": scu.fmt_note(nt.get_etud_moy_gen(etudid), keep_numeric=keep_numeric),
|
2020-09-26 16:19:37 +02:00
|
|
|
"rang": nt.get_etud_rang(etudid),
|
|
|
|
"effectif": len(nt.T),
|
2024-09-09 16:21:51 +02:00
|
|
|
"semestre_id": formsemestre.semestre_id,
|
|
|
|
"semestre": formsemestre.titre,
|
|
|
|
"date_debut": formsemestre.date_debut,
|
|
|
|
"date_fin": formsemestre.date_fin,
|
|
|
|
"periode": f"{formsemestre.mois_debut()} - {formsemestre.mois_fin()}",
|
|
|
|
"sem_ident": f"{formsemestre.date_debut.isoformat()} {formsemestre.titre}", # utile pour tris
|
2020-09-26 16:19:37 +02:00
|
|
|
}
|
|
|
|
# recherche des débouchés
|
2024-09-09 16:21:51 +02:00
|
|
|
itemsuivis = etud.itemsuivis # liste de plusieurs items
|
|
|
|
if itemsuivis:
|
2024-03-24 11:23:40 +01:00
|
|
|
if keep_numeric: # pour excel:
|
|
|
|
row["debouche"] = "\n".join(
|
2024-09-09 16:21:51 +02:00
|
|
|
f"""{it.item_date.strftime(scu.DATE_FMT)}: {it.situation or ""}"""
|
|
|
|
for it in itemsuivis
|
2024-03-24 11:23:40 +01:00
|
|
|
)
|
|
|
|
else:
|
|
|
|
row["debouche"] = "<br>".join(
|
|
|
|
[
|
2024-09-09 16:21:51 +02:00
|
|
|
f"""{it.item_date.strftime(scu.DATE_FMT)} : {it.situation or ""}
|
|
|
|
<i>{', '.join( tag.title for tag in it.tags)}</i>
|
|
|
|
"""
|
|
|
|
for it in itemsuivis
|
2024-03-24 11:23:40 +01:00
|
|
|
]
|
|
|
|
)
|
2024-09-09 16:21:51 +02:00
|
|
|
for it in itemsuivis:
|
|
|
|
for tag in it.tags:
|
|
|
|
tag_name = tag.title.strip()
|
|
|
|
row[f"tag_{tag_name}"] = tag_name
|
2020-09-26 16:19:37 +02:00
|
|
|
else:
|
|
|
|
row["debouche"] = "non renseigné"
|
2024-03-24 11:23:40 +01:00
|
|
|
rows.append(row)
|
|
|
|
rows.sort(key=lambda x: x["sem_ident"])
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
titles = {
|
2021-02-13 17:28:55 +01:00
|
|
|
"civilite": "",
|
2020-09-26 16:19:37 +02:00
|
|
|
"nom": "Nom",
|
|
|
|
"prenom": "Prénom",
|
|
|
|
"semestre": "Dernier semestre",
|
|
|
|
"semestre_id": "S",
|
|
|
|
"periode": "Dates",
|
|
|
|
"moy": "Moyenne",
|
|
|
|
"rang": "Rang",
|
|
|
|
"effectif": "Eff.",
|
|
|
|
"debouche": "Débouché",
|
|
|
|
}
|
2024-03-24 11:23:40 +01:00
|
|
|
columns_ids = [
|
|
|
|
"semestre",
|
|
|
|
"semestre_id",
|
|
|
|
"periode",
|
|
|
|
"civilite",
|
|
|
|
"nom",
|
|
|
|
"prenom",
|
|
|
|
"moy",
|
|
|
|
"rang",
|
|
|
|
"effectif",
|
|
|
|
"debouche",
|
|
|
|
]
|
|
|
|
for tag in all_tags:
|
|
|
|
titles[f"tag_{tag}"] = tag
|
|
|
|
columns_ids.append(f"tag_{tag}")
|
2020-09-26 16:19:37 +02:00
|
|
|
tab = GenTable(
|
2024-03-24 11:23:40 +01:00
|
|
|
columns_ids=columns_ids,
|
2020-09-26 16:19:37 +02:00
|
|
|
titles=titles,
|
2024-03-24 11:23:40 +01:00
|
|
|
rows=rows,
|
2020-09-26 16:19:37 +02:00
|
|
|
# html_col_width='4em',
|
|
|
|
html_sortable=True,
|
|
|
|
html_class="table_leftalign table_listegroupe",
|
2021-07-28 17:03:54 +02:00
|
|
|
preferences=sco_preferences.SemPreferences(),
|
2024-05-22 00:06:30 +02:00
|
|
|
table_id="table_debouche_etudids",
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
|
|
|
return tab
|
|
|
|
|
|
|
|
|
2021-09-30 09:37:18 +02:00
|
|
|
def report_debouche_ask_date(msg: str) -> str:
|
2020-12-24 00:07:17 +01:00
|
|
|
"""Formulaire demande date départ"""
|
2024-08-24 08:06:46 +02:00
|
|
|
return render_template(
|
|
|
|
"sco_page_dept.j2",
|
|
|
|
content=f"""
|
2021-09-30 09:37:18 +02:00
|
|
|
<h2>Table des débouchés des étudiants</h2>
|
|
|
|
<form method="GET">
|
2023-12-31 23:04:06 +01:00
|
|
|
{msg}
|
2021-09-30 09:37:18 +02:00
|
|
|
<input type="text" name="start_year" value="" size=10/>
|
|
|
|
</form>
|
2024-08-24 08:06:46 +02:00
|
|
|
""",
|
|
|
|
)
|