Tri date table opérations sur évaluation

This commit is contained in:
Emmanuel Viennet 2024-06-30 00:26:17 +02:00
parent 9a289d5956
commit 8f12c452df

View File

@ -68,17 +68,18 @@ class NotesOperation(dict):
Keys: evaluation_id, date, uid, notes Keys: evaluation_id, date, uid, notes
""" """
def get_comment(self): def get_comment(self) -> str:
"le commentaire ou une chaine vide"
if self["notes"]: if self["notes"]:
return self["notes"][0]["comment"] return self["notes"][0]["comment"]
else:
return "" return ""
def comp_values(self): def comp_values(self):
"compute keys: comment, nb_notes" "compute keys: comment, nb_notes"
self["comment"] = self.get_comment() self["comment"] = self.get_comment()
self["nb_notes"] = len(self["notes"]) self["nb_notes"] = len(self["notes"])
self["datestr"] = self["date"].strftime("%a %d/%m/%y %Hh%M") self["date_str"] = self["date"].strftime("%a %d/%m/%y %Hh%M")
self["_date_str_order"] = self["date"].isoformat()
def undo(self): def undo(self):
"undo operation" "undo operation"
@ -113,12 +114,12 @@ def list_operations(evaluation_id):
).values() ).values()
) )
dt = OPERATION_DATE_TOLERANCE dt = OPERATION_DATE_TOLERANCE
NotesDates = {} # { uid : intervalmap } notes_dates = {} # { uid : intervalmap }
for note in notes + notes_log: for note in notes + notes_log:
if note["uid"] not in NotesDates: if note["uid"] not in notes_dates:
NotesDates[note["uid"]] = intervalmap() notes_dates[note["uid"]] = intervalmap()
nd = NotesDates[note["uid"]] nd = notes_dates[note["uid"]]
if nd[note["date"]] is None: if nd[note["date"]] is None:
nd[note["date"] - dt : note["date"] + dt] = [note] nd[note["date"] - dt : note["date"] + dt] = [note]
else: else:
@ -128,32 +129,32 @@ def list_operations(evaluation_id):
for note in notes: for note in notes:
current_notes_by_etud[note["etudid"]] = note current_notes_by_etud[note["etudid"]] = note
Ops = [] operations = []
for uid in NotesDates.keys(): for uid, note_date in notes_dates.items():
user_name = "{prenomnom} ({user_name})".format(**sco_users.user_info(uid)) user_name = "{prenomnom} ({user_name})".format(**sco_users.user_info(uid))
for (t0, _), notes in NotesDates[uid].items(): for (t0, _), notes in note_date.items():
Op = NotesOperation( operation = NotesOperation(
evaluation_id=evaluation_id, evaluation_id=evaluation_id,
date=t0, date=t0,
uid=uid, uid=uid,
user_name=user_name, user_name=user_name,
notes=NotesDates[uid][t0], notes=note_date[t0],
current_notes_by_etud=current_notes_by_etud, current_notes_by_etud=current_notes_by_etud,
) )
Op.comp_values() operation.comp_values()
Ops.append(Op) operations.append(operation)
return Ops return operations
def evaluation_list_operations(evaluation_id): def evaluation_list_operations(evaluation_id: int):
"""Page listing operations on evaluation""" """Page listing operations on evaluation"""
evaluation = Evaluation.get_evaluation(evaluation_id) evaluation = Evaluation.get_evaluation(evaluation_id)
operations = list_operations(evaluation_id) operations = list_operations(evaluation_id)
columns_ids = ("datestr", "user_name", "nb_notes", "comment") columns_ids = ("date_str", "user_name", "nb_notes", "comment")
titles = { titles = {
"datestr": "Date", "date_str": "Date",
"user_name": "Enseignant", "user_name": "Enseignant",
"nb_notes": "Nb de notes", "nb_notes": "Nb de notes",
"comment": "Commentaire", "comment": "Commentaire",