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@viennet.net
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
"""Rapports sur lycées d'origine des étudiants d'un semestre.
|
|
|
|
- statistiques decisions
|
|
|
|
- suivi cohortes
|
2024-08-24 18:26:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
TODO: remplacer Google Map par https://leafletjs.com/
|
2020-09-26 16:19:37 +02:00
|
|
|
"""
|
2021-07-09 23:19:30 +02:00
|
|
|
from operator import itemgetter
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2024-08-24 18:26:51 +02:00
|
|
|
from flask import url_for, g, render_template, request
|
2021-07-11 17:37:12 +02:00
|
|
|
|
2021-08-13 09:31:49 +02:00
|
|
|
import app
|
2024-03-31 23:04:54 +02:00
|
|
|
from app.scodoc import (
|
|
|
|
sco_formsemestre,
|
|
|
|
sco_groups_view,
|
|
|
|
sco_preferences,
|
|
|
|
sco_report,
|
|
|
|
sco_etud,
|
|
|
|
)
|
|
|
|
from app.models import FormSemestre
|
|
|
|
from app.scodoc.gen_tables import GenTable
|
2021-06-19 23:21:37 +02:00
|
|
|
import app.scodoc.sco_utils as scu
|
2021-08-21 17:07:44 +02:00
|
|
|
import sco_version
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
def formsemestre_table_etuds_lycees(
|
2024-03-31 23:04:54 +02:00
|
|
|
formsemestre: FormSemestre, groups_infos, group_lycees=True, only_primo=False
|
2020-09-26 16:19:37 +02:00
|
|
|
):
|
2021-01-01 18:40:47 +01:00
|
|
|
"""Récupère liste d'etudiants avec etat et decision."""
|
2024-03-31 23:04:54 +02:00
|
|
|
sem = sco_formsemestre.get_formsemestre(formsemestre.id)
|
|
|
|
etuds = sco_report.tsp_etud_list(
|
|
|
|
formsemestre.id, groups_infos=groups_infos, only_primo=only_primo
|
|
|
|
)[0]
|
2020-09-26 16:19:37 +02:00
|
|
|
if only_primo:
|
|
|
|
primostr = "primo-entrants du "
|
|
|
|
else:
|
|
|
|
primostr = "du "
|
|
|
|
title = "Lycées des étudiants %ssemestre " % primostr + sem["titreannee"]
|
|
|
|
return _table_etuds_lycees(
|
2021-06-13 19:12:20 +02:00
|
|
|
etuds,
|
|
|
|
group_lycees,
|
|
|
|
title,
|
2024-03-31 23:04:54 +02:00
|
|
|
sco_preferences.SemPreferences(formsemestre.id),
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-09-21 10:20:19 +02:00
|
|
|
def scodoc_table_etuds_lycees(fmt="html"):
|
2021-08-13 09:31:49 +02:00
|
|
|
"""Table avec _tous_ les étudiants des semestres non verrouillés
|
|
|
|
de _tous_ les départements.
|
|
|
|
"""
|
|
|
|
cur_dept = g.scodoc_dept
|
|
|
|
semdepts = sco_formsemestre.scodoc_get_all_unlocked_sems()
|
2020-09-26 16:19:37 +02:00
|
|
|
etuds = []
|
2021-08-13 09:31:49 +02:00
|
|
|
try:
|
2023-09-21 10:20:19 +02:00
|
|
|
for sem, dept in semdepts:
|
2021-08-13 09:31:49 +02:00
|
|
|
app.set_sco_dept(dept.acronym)
|
2021-08-21 00:24:51 +02:00
|
|
|
etuds += sco_report.tsp_etud_list(sem["formsemestre_id"])[0]
|
2021-08-13 09:31:49 +02:00
|
|
|
finally:
|
|
|
|
app.set_sco_dept(cur_dept)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
tab, etuds_by_lycee = _table_etuds_lycees(
|
|
|
|
etuds,
|
|
|
|
False,
|
|
|
|
"Lycées de TOUS les étudiants",
|
2021-07-28 17:03:54 +02:00
|
|
|
sco_preferences.SemPreferences(),
|
2020-09-26 16:19:37 +02:00
|
|
|
no_links=True,
|
|
|
|
)
|
2021-09-18 10:10:02 +02:00
|
|
|
tab.base_url = request.base_url
|
2024-08-24 18:26:51 +02:00
|
|
|
table_html = tab.make_page(fmt=fmt, with_html_headers=False)
|
2023-09-21 10:20:19 +02:00
|
|
|
if fmt != "html":
|
2024-08-24 18:26:51 +02:00
|
|
|
return table_html
|
|
|
|
return render_template(
|
|
|
|
"formsemestre/etuds_lycees.j2",
|
|
|
|
table_html=table_html,
|
|
|
|
title=tab.page_title,
|
|
|
|
title_h2=f"Lycées d'origine des {len(etuds)} étudiants ({len(semdepts)} semestres)",
|
|
|
|
js_coords_lycees=js_coords_lycees(etuds_by_lycee),
|
|
|
|
)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
2021-08-21 00:24:51 +02:00
|
|
|
def _table_etuds_lycees(etuds, group_lycees, title, preferences, no_links=False):
|
2021-06-19 23:21:37 +02:00
|
|
|
etuds = [sco_etud.etud_add_lycee_infos(e) for e in etuds]
|
2021-02-04 20:02:44 +01:00
|
|
|
etuds_by_lycee = scu.group_by_key(etuds, "codelycee")
|
2020-09-26 16:19:37 +02:00
|
|
|
#
|
|
|
|
if group_lycees:
|
|
|
|
L = [etuds_by_lycee[codelycee][0] for codelycee in etuds_by_lycee]
|
|
|
|
for l in L:
|
|
|
|
l["nbetuds"] = len(etuds_by_lycee[l["codelycee"]])
|
2023-10-10 22:42:02 +02:00
|
|
|
|
2021-07-09 23:19:30 +02:00
|
|
|
L.sort(key=itemgetter("codepostallycee", "nomlycee"))
|
2020-09-26 16:19:37 +02:00
|
|
|
columns_ids = (
|
|
|
|
"nbetuds",
|
|
|
|
"codelycee",
|
|
|
|
"codepostallycee",
|
|
|
|
"villelycee",
|
|
|
|
"nomlycee",
|
|
|
|
)
|
|
|
|
bottom_titles = {
|
|
|
|
"nbetuds": len(etuds),
|
|
|
|
"nomlycee": "%d lycées"
|
|
|
|
% len([x for x in etuds_by_lycee if etuds_by_lycee[x][0]["codelycee"]]),
|
|
|
|
}
|
|
|
|
else:
|
|
|
|
L = etuds
|
|
|
|
columns_ids = (
|
2021-02-13 17:28:55 +01:00
|
|
|
"civilite_str",
|
2020-09-26 16:19:37 +02:00
|
|
|
"nom",
|
|
|
|
"prenom",
|
|
|
|
"codelycee",
|
|
|
|
"codepostallycee",
|
|
|
|
"villelycee",
|
|
|
|
"nomlycee",
|
|
|
|
)
|
|
|
|
bottom_titles = None
|
|
|
|
if not no_links:
|
|
|
|
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
|
2020-09-26 16:19:37 +02:00
|
|
|
etud["_nom_td_attrs"] = 'id="%s" class="etudinfo"' % (etud["etudid"])
|
|
|
|
|
|
|
|
tab = GenTable(
|
|
|
|
columns_ids=columns_ids,
|
|
|
|
rows=L,
|
|
|
|
titles={
|
|
|
|
"nbetuds": "Nb d'étudiants",
|
2021-02-13 17:28:55 +01:00
|
|
|
"civilite_str": "",
|
2020-09-26 16:19:37 +02:00
|
|
|
"nom": "Nom",
|
|
|
|
"prenom": "Prénom",
|
|
|
|
"etudid": "etudid",
|
|
|
|
"codelycee": "Code Lycée",
|
|
|
|
"codepostallycee": "Code postal",
|
|
|
|
"nomlycee": "Lycée",
|
|
|
|
"villelycee": "Commune",
|
|
|
|
},
|
2021-08-21 17:07:44 +02:00
|
|
|
origin="Généré par %s le " % sco_version.SCONAME
|
|
|
|
+ scu.timedate_human_repr()
|
|
|
|
+ "",
|
2020-09-26 16:19:37 +02:00
|
|
|
caption=title,
|
|
|
|
page_title="Carte lycées d'origine",
|
|
|
|
html_sortable=True,
|
|
|
|
html_class="table_leftalign table_listegroupe",
|
|
|
|
bottom_titles=bottom_titles,
|
|
|
|
preferences=preferences,
|
2024-05-22 00:06:30 +02:00
|
|
|
table_id="table_etuds_lycees",
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
|
|
|
return tab, etuds_by_lycee
|
|
|
|
|
|
|
|
|
|
|
|
def formsemestre_etuds_lycees(
|
|
|
|
formsemestre_id,
|
2024-03-31 23:04:54 +02:00
|
|
|
group_ids: list[int] = None, # si indiqué, ne prend que ces groupes
|
2023-09-21 10:20:19 +02:00
|
|
|
fmt="html",
|
2020-09-26 16:19:37 +02:00
|
|
|
only_primo=False,
|
|
|
|
no_grouping=False,
|
|
|
|
):
|
|
|
|
"""Table des lycées d'origine"""
|
2024-03-31 23:04:54 +02:00
|
|
|
formsemestre = FormSemestre.get_formsemestre(formsemestre_id)
|
|
|
|
groups_infos = sco_groups_view.DisplayedGroupsInfos(
|
|
|
|
group_ids,
|
|
|
|
formsemestre_id=formsemestre.id,
|
|
|
|
select_all_when_unspecified=True,
|
|
|
|
)
|
2020-09-26 16:19:37 +02:00
|
|
|
tab, etuds_by_lycee = formsemestre_table_etuds_lycees(
|
2024-03-31 23:04:54 +02:00
|
|
|
formsemestre, groups_infos, only_primo=only_primo, group_lycees=not no_grouping
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
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
|
|
|
if only_primo:
|
2021-05-11 11:48:32 +02:00
|
|
|
tab.base_url += "&only_primo=1"
|
2020-09-26 16:19:37 +02:00
|
|
|
if no_grouping:
|
2021-05-11 11:48:32 +02:00
|
|
|
tab.base_url += "&no_grouping=1"
|
2024-08-24 18:26:51 +02:00
|
|
|
table_html = tab.make_page(fmt=fmt, with_html_headers=False)
|
2023-09-21 10:20:19 +02:00
|
|
|
if fmt != "html":
|
2024-08-24 18:26:51 +02:00
|
|
|
return table_html
|
|
|
|
return render_template(
|
|
|
|
"formsemestre/etuds_lycees.j2",
|
|
|
|
form_primo_group=sco_report.tsp_form_primo_group(
|
2024-03-31 23:04:54 +02:00
|
|
|
only_primo, no_grouping, formsemestre_id, fmt, groups_infos=groups_infos
|
2020-09-26 16:19:37 +02:00
|
|
|
),
|
2024-08-24 18:26:51 +02:00
|
|
|
table_html=table_html,
|
|
|
|
title=tab.page_title,
|
|
|
|
title_h2="Lycées d'origine des étudiants",
|
|
|
|
js_coords_lycees=js_coords_lycees(etuds_by_lycee),
|
|
|
|
)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
def qjs(txt): # quote for JS
|
|
|
|
return txt.replace("'", r"\'").replace('"', r"\"")
|
|
|
|
|
|
|
|
|
|
|
|
def js_coords_lycees(etuds_by_lycee):
|
|
|
|
"""Formatte liste des lycees en JSON pour Google Map"""
|
|
|
|
L = []
|
|
|
|
for codelycee in etuds_by_lycee:
|
|
|
|
if codelycee:
|
|
|
|
lyc = etuds_by_lycee[codelycee][0]
|
|
|
|
if not lyc.get("positionlycee", False):
|
|
|
|
continue
|
2022-10-02 23:43:29 +02:00
|
|
|
listeetuds = "<br>%d étudiants: " % len(
|
2020-09-26 16:19:37 +02:00
|
|
|
etuds_by_lycee[codelycee]
|
|
|
|
) + ", ".join(
|
|
|
|
[
|
2021-07-11 17:37:12 +02:00
|
|
|
'<a class="discretelink" href="%s" title="">%s</a>'
|
|
|
|
% (
|
|
|
|
url_for(
|
2024-01-20 14:49:36 +01:00
|
|
|
"scolar.fiche_etud",
|
2021-07-11 17:37:12 +02:00
|
|
|
scodoc_dept=g.scodoc_dept,
|
|
|
|
etudid=e["etudid"],
|
|
|
|
),
|
|
|
|
qjs(e["nomprenom"]),
|
|
|
|
)
|
2020-09-26 16:19:37 +02:00
|
|
|
for e in etuds_by_lycee[codelycee]
|
|
|
|
]
|
|
|
|
)
|
|
|
|
pos = qjs(lyc["positionlycee"])
|
|
|
|
legend = "%s %s" % (qjs("%(nomlycee)s (%(villelycee)s)" % lyc), listeetuds)
|
|
|
|
L.append(
|
|
|
|
"{'position' : '%s', 'name' : '%s', 'number' : %d }"
|
|
|
|
% (pos, legend, len(etuds_by_lycee[codelycee]))
|
|
|
|
)
|
|
|
|
|
|
|
|
return """<script type="text/javascript">
|
|
|
|
var lycees_coords = [%s];
|
|
|
|
</script>""" % ",".join(
|
|
|
|
L
|
|
|
|
)
|