VisualisationAssiduitesGroupe: améliore table + export excel

This commit is contained in:
Emmanuel Viennet 2023-07-20 15:53:59 +02:00
parent 9bdeda7559
commit fb5cdc2624
5 changed files with 62 additions and 35 deletions

View File

@ -33,7 +33,6 @@
import collections
import datetime
import operator
import urllib
from urllib.parse import parse_qs
import time
@ -42,6 +41,8 @@ import time
from flask import url_for, g, request
from flask_login import current_user
from app import db
from app.models import FormSemestre
import app.scodoc.sco_utils as scu
from app.scodoc import html_sco_header
from app.scodoc import sco_abs
@ -65,6 +66,7 @@ JAVASCRIPTS = html_sco_header.BOOTSTRAP_MULTISELECT_JS + [
CSSSTYLES = html_sco_header.BOOTSTRAP_MULTISELECT_CSS
# view:
def groups_view(
group_ids=(),
@ -422,6 +424,13 @@ class DisplayedGroupsInfos(object):
H.append(f'<input type="hidden" name="group_ids" value="{group_id}"/>')
return "\n".join(H)
def get_formsemestre(self) -> FormSemestre:
return (
db.session.get(FormSemestre, self.formsemestre_id)
if self.formsemestre_id
else None
)
# Ancien ZScolar.group_list renommé ici en group_table
def groups_table(

View File

@ -8,7 +8,7 @@
"""
from flask import g, url_for
from app.models import Identite, Assiduite, Justificatif
from app.models import Identite, Justificatif
from app.tables import table_builder as tb
import app.scodoc.sco_assiduites as scass
from app.scodoc import sco_preferences
@ -65,31 +65,35 @@ class RowAssi(tb.Row):
}
)
bilan_etud = f"{url_for('assiduites.bilan_etud', scodoc_dept=g.scodoc_dept)}?etudid={etud.id}"
bilan_etud = url_for(
"assiduites.bilan_etud", scodoc_dept=g.scodoc_dept, etudid=etud.id
)
self.add_cell(
"nom_disp",
"Nom",
etud.nom_disp(),
"identite_detail",
"etudinfo",
attrs={"id": str(etud.id)},
data={"order": etud.sort_key},
target=bilan_etud,
target_attrs={"class": "discretelink", "id": str(etud.id)},
target_attrs={"class": "discretelink"},
)
self.add_cell(
"prenom",
"Prénom",
etud.prenom,
"identite_detail",
etud.prenom_str,
"etudinfo",
attrs={"id": str(etud.id)},
data={"order": etud.sort_key},
target=bilan_etud,
target_attrs={"class": "discretelink", "id": str(etud.id)},
target_attrs={"class": "discretelink"},
)
stats = self._get_etud_stats(etud)
for key, value in stats.items():
self.add_cell(key, value[0], f"{value[1] - value[2]}", "assi_stats")
self.add_cell(
key + "_justi",
value[0] + " Justifiée(s)",
value[0] + " Justifiées",
f"{value[2]}",
"assi_stats",
)
@ -102,9 +106,9 @@ class RowAssi(tb.Row):
def _get_etud_stats(self, etud: Identite) -> dict[str, list[str, float, float]]:
retour: dict[str, tuple[str, float, float]] = {
"present": ["Présence(s)", 0.0, 0.0],
"retard": ["Retard(s)", 0.0, 0.0],
"absent": ["Absence(s)", 0.0, 0.0],
"present": ["Présences", 0.0, 0.0],
"retard": ["Retards", 0.0, 0.0],
"absent": ["Absences", 0.0, 0.0],
}
assi_metric = {

View File

@ -1,11 +1,22 @@
{% extends "sco_page.j2" %}
{% block scripts %}
{{ super() }}
<script src="{{scu.STATIC_DIR}}/js/etud_info.js"></script>
{% endblock %}
{% block app_content %}
<h2>Visualisation de l'assiduité {{gr_tit|safe}}</h2>
<div class="stats-inputs">
<label class="stats-label"> Date de début<input type="date" name="stats_date_debut" id="stats_date_debut"
<label class="stats-label"> Date de début <input type="date" name="stats_date_debut" id="stats_date_debut"
value="{{date_debut}}"></label>
<label class="stats-label"> Date de fin<input type="date" name="stats_date_fin" id="stats_date_fin"
<label class="stats-label"> Date de fin <input type="date" name="stats_date_fin" id="stats_date_fin"
value="{{date_fin}}"></label>
<button onclick="stats()">Changer la période</button>
<button onclick="stats()">Changer</button>
<a style="margin-left:32px;" href="{{request.url}}&format=xlsx">{{scu.ICON_XLS|safe}}</a>
</div>
{{tableau | safe}}
@ -26,4 +37,6 @@
document.querySelector('#stats_date_fin').value = date_fin;
})
</script>
</script>
{% endblock %}

View File

@ -649,6 +649,7 @@ def visu_assi_group():
"debut": request.args.get("date_debut"),
"fin": request.args.get("date_fin"),
}
fmt = request.args.get("format", "html")
group_ids: list[int] = request.args.get("group_ids", None)
etudiants: list[dict] = []
@ -662,14 +663,16 @@ def visu_assi_group():
groups_infos = sco_groups_view.DisplayedGroupsInfos(group_ids)
etuds = etuds_sorted_from_ids([m["etudid"] for m in groups_infos.members])
header: str = html_sco_header.sco_header(
page_title="Visualisation des assiduités",
init_qtip=True,
)
table: TableAssi = TableAssi(etuds=etuds, dates=list(dates.values()))
if fmt.startswith("xls"):
return scu.send_file(
table.excel(),
filename=f"assiduite-{groups_infos.groups_filename}",
mime=scu.XLSX_MIMETYPE,
suffix=scu.XLSX_SUFFIX,
)
if groups_infos.tous_les_etuds_du_sem:
gr_tit = "en"
else:
@ -681,18 +684,16 @@ def visu_assi_group():
grp + ' <span class="fontred">' + groups_infos.groups_titles + "</span>"
)
return HTMLBuilder(
header,
render_template(
"assiduites/pages/visu_assi.j2",
tableau=table.html(),
gr_tit=gr_tit,
date_debut=dates["debut"],
date_fin=dates["fin"],
group_ids=request.args.get("group_ids", None),
),
html_sco_header.sco_footer(),
).build()
return render_template(
"assiduites/pages/visu_assi.j2",
tableau=table.html(),
gr_tit=gr_tit,
date_debut=dates["debut"],
date_fin=dates["fin"],
group_ids=request.args.get("group_ids", None),
sco=ScoData(formsemestre=groups_infos.get_formsemestre()),
title=f"Assiduité {grp} {groups_infos.groups_titles}",
)
@bp.route("/SignalAssiduiteDifferee")

View File

@ -1,7 +1,7 @@
# -*- mode: python -*-
# -*- coding: utf-8 -*-
SCOVERSION = "9.6.2"
SCOVERSION = "9.6.3"
SCONAME = "ScoDoc"