Améliore formsemestre_list_saisies_notes

This commit is contained in:
Emmanuel Viennet 2024-11-08 10:58:05 +01:00
parent 6cd28853bc
commit d98eb7dc6b
3 changed files with 125 additions and 49 deletions

View File

@ -180,7 +180,28 @@ def evaluation_list_operations(evaluation_id: int):
return tab.make_page() return tab.make_page()
def formsemestre_list_saisies_notes(formsemestre_id, only_modifs=False, fmt="html"): def formsemestre_list_notes_intervenants(formsemestre: FormSemestre) -> list[User]:
"Liste des comptes ayant saisi au moins une note dans le semestre"
q1 = (
User.query.join(NotesNotes)
.join(Evaluation)
.join(ModuleImpl)
.filter_by(formsemestre_id=formsemestre.id)
.distinct()
)
q2 = (
User.query.join(NotesNotesLog)
.join(Evaluation, Evaluation.id == NotesNotesLog.evaluation_id)
.join(ModuleImpl)
.filter_by(formsemestre_id=formsemestre.id)
.distinct()
)
return sorted(q1.union(q2).all(), key=lambda x: x.sort_key())
def formsemestre_list_saisies_notes(
formsemestre_id, only_modifs=False, user_name: str | None = None, fmt="html"
):
"""Table listant toutes les opérations de saisies de notes, dans toutes """Table listant toutes les opérations de saisies de notes, dans toutes
les évaluations du semestre. les évaluations du semestre.
""" """
@ -194,52 +215,67 @@ def formsemestre_list_saisies_notes(formsemestre_id, only_modifs=False, fmt="htm
.filter_by(formsemestre_id=formsemestre.id) .filter_by(formsemestre_id=formsemestre.id)
.order_by(model.date.desc()) .order_by(model.date.desc())
) )
if user_name:
user = db.session.query(User).filter_by(user_name=user_name).first()
if user:
notes_query = notes_query.join(User).filter(model.uid == user.id)
# Formate les notes # Formate les notes
keep_numeric = fmt in scu.FORMATS_NUMERIQUES keep_numeric = fmt in scu.FORMATS_NUMERIQUES
rows = [] rows = []
for note in notes_query: for note in notes_query:
ens = User.get_user(note.uid) ens = User.get_user(note.uid)
evaluation = note.evaluation evaluation = note.evaluation
rows.append( row = {
{ "date": note.date.strftime(scu.DATEATIME_FMT),
"date": note.date.strftime(scu.DATEATIME_FMT), "_date_order": note.date.isoformat(),
"_date_order": note.date.isoformat(), "code_nip": note.etudiant.code_nip,
"code_nip": note.etudiant.code_nip, "nom": note.etudiant.nom_disp(),
"nom": note.etudiant.nom_disp(), "prenom": note.etudiant.prenom_str,
"prenom": note.etudiant.prenom_str, "date_evaluation": (
"date_evaluation": ( evaluation.date_debut.strftime(scu.DATEATIME_FMT)
evaluation.date_debut.strftime(scu.DATEATIME_FMT) if evaluation and note.evaluation.date_debut
if evaluation and note.evaluation.date_debut else ""
else "" ),
), "_date_evaluation_order": (
"_date_evaluation_order": ( note.evaluation.date_debut.isoformat()
note.evaluation.date_debut.isoformat() if evaluation and note.evaluation.date_debut
if evaluation and note.evaluation.date_debut else ""
else "" ),
), "value": scu.fmt_note(note.value, keep_numeric=keep_numeric),
"value": scu.fmt_note(note.value, keep_numeric=keep_numeric), "module": (
"module": ( (
( note.evaluation.moduleimpl.module.code
note.evaluation.moduleimpl.module.code or note.evaluation.moduleimpl.module.titre
or note.evaluation.moduleimpl.module.titre )
) if evaluation
if evaluation else ""
else "" ),
), "evaluation": note.evaluation.description if evaluation else "",
"evaluation": note.evaluation.description if evaluation else "", "_evaluation_target": (
"_evaluation_target": ( url_for(
url_for( "notes.evaluation_listenotes",
"notes.evaluation_listenotes", scodoc_dept=g.scodoc_dept,
scodoc_dept=g.scodoc_dept, evaluation_id=note.evaluation_id,
evaluation_id=note.evaluation_id, )
) if evaluation
if evaluation else ""
else "" ),
), "user_name": ens.user_name if ens else "",
"user_name": ens.user_name if ens else "", }
}
) if only_modifs:
# si c'est une modif de note, ajoute une colonne avec la nouvelle valeur
new = NotesNotes.query.filter_by(
evaluation_id=note.evaluation_id, etudid=note.etudid
).first()
if new:
row["new_value"] = scu.fmt_note(new.value, keep_numeric=keep_numeric)
row["old_date"] = row["date"]
row["_old_date_order"] = row["_date_order"]
row["date"] = new.date.strftime(scu.DATEATIME_FMT)
row["_date_order"] = new.date.isoformat()
rows.append(row)
columns_ids = ( columns_ids = (
"date", "date",
@ -247,6 +283,13 @@ def formsemestre_list_saisies_notes(formsemestre_id, only_modifs=False, fmt="htm
"nom", "nom",
"prenom", "prenom",
"value", "value",
)
if only_modifs:
columns_ids += (
"new_value",
"old_date",
)
columns_ids += (
"user_name", "user_name",
"module", "module",
"evaluation", "evaluation",
@ -257,7 +300,8 @@ def formsemestre_list_saisies_notes(formsemestre_id, only_modifs=False, fmt="htm
"code_nip": "NIP", "code_nip": "NIP",
"nom": "nom", "nom": "nom",
"prenom": "prenom", "prenom": "prenom",
"date": "Date", "date": "Date modif." if only_modifs else "Date saisie",
"old_date": "Date saisie précédente",
"value": "Note", "value": "Note",
"comment": "Remarque", "comment": "Remarque",
"user_name": "Enseignant", "user_name": "Enseignant",
@ -266,6 +310,9 @@ def formsemestre_list_saisies_notes(formsemestre_id, only_modifs=False, fmt="htm
"evaluation": "Evaluation", "evaluation": "Evaluation",
"date_evaluation": "Date éval.", "date_evaluation": "Date éval.",
} }
if only_modifs:
titles["value"] = "Ancienne note"
titles["new_value"] = "Nouvelle note"
table = GenTable( table = GenTable(
titles=titles, titles=titles,
columns_ids=columns_ids, columns_ids=columns_ids,
@ -277,13 +324,17 @@ def formsemestre_list_saisies_notes(formsemestre_id, only_modifs=False, fmt="htm
caption=f"Saisies de notes dans {formsemestre.titre_annee()}", caption=f"Saisies de notes dans {formsemestre.titre_annee()}",
preferences=sco_preferences.SemPreferences(formsemestre_id), preferences=sco_preferences.SemPreferences(formsemestre_id),
base_url=f"""{request.base_url}?formsemestre_id={ base_url=f"""{request.base_url}?formsemestre_id={
formsemestre_id}&only_modifs={int(only_modifs)}""", formsemestre_id}&only_modifs={int(only_modifs)}"""
+ (f"&user_name={user_name}" if user_name else ""),
origin=f"Généré par {sco_version.SCONAME} le " + scu.timedate_human_repr() + "", origin=f"Généré par {sco_version.SCONAME} le " + scu.timedate_human_repr() + "",
table_id="formsemestre_list_saisies_notes", table_id="formsemestre_list_saisies_notes",
filename=( filename=(
f"modifs_notes_S{formsemestre.semestre_id}" (
if only_modifs f"modifs_notes-S{formsemestre.semestre_id}"
else f"saisies_notes_S{formsemestre.semestre_id}" if only_modifs
else f"saisies_notes_S{formsemestre.semestre_id}"
)
+ ("-" + user_name if user_name else "")
), ),
) )
if fmt == "html": if fmt == "html":
@ -293,6 +344,8 @@ def formsemestre_list_saisies_notes(formsemestre_id, only_modifs=False, fmt="htm
title="Opérations de saisies de notes", title="Opérations de saisies de notes",
only_modifs=only_modifs, only_modifs=only_modifs,
formsemestre_id=formsemestre.id, formsemestre_id=formsemestre.id,
intervenants=formsemestre_list_notes_intervenants(formsemestre),
user_name=user_name,
) )
return table.make_page(fmt=fmt, page_title="Opérations de saisies de notes") return table.make_page(fmt=fmt, page_title="Opérations de saisies de notes")

View File

@ -3,7 +3,7 @@
{% block styles %} {% block styles %}
{{super()}} {{super()}}
<style> <style>
.export_xls_but { .h-spaced {
margin-left: 32px; margin-left: 32px;
} }
</style> </style>
@ -22,7 +22,19 @@
{% if only_modifs %}checked{% endif %}> {% if only_modifs %}checked{% endif %}>
Lister uniquement les modifications Lister uniquement les modifications
</label> </label>
<span class="export_xls_but">{{table.xls_export_button()|safe}} excel</span>
<label class="h-spaced" for="user-select">Restreindre à un enseignant&nbsp;:</label>
<select id="user-select" name="user_name">
<option value="">Choisir...</option>
{% for user in intervenants %}
<option value="{{ user.user_name }}"
{% if user.user_name == user_name %}selected{% endif %}>
{{ user.get_nomplogin() }}
</option>
{% endfor %}
</select>
<span class="h-spaced">{{table.xls_export_button()|safe}} excel</span>
</form> </form>
{{table.html()|safe}} {{table.html()|safe}}
@ -44,5 +56,16 @@
window.location.href = url.toString(); window.location.href = url.toString();
}); });
document.getElementById('user-select').addEventListener('change', function() {
var form = document.getElementById('filter-form');
var userName = this.value;
var url = new URL(window.location.href);
url.searchParams.set('formsemestre_id', {{formsemestre_id}});
url.searchParams.set('user_name', userName);
window.location.href = url.toString();
});
</script> </script>
{% endblock %} {% endblock %}

View File

@ -3,7 +3,7 @@
"Infos sur version ScoDoc" "Infos sur version ScoDoc"
SCOVERSION = "9.7.40" SCOVERSION = "9.7.41"
SCONAME = "ScoDoc" SCONAME = "ScoDoc"