From 53224fa43fbbf1eeabddfa9a6a484c2dc4768e60 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Tue, 26 Sep 2023 23:15:35 +0200 Subject: [PATCH] Fix evaluations sort --- app/scodoc/sco_evaluation_db.py | 17 +++++++++++------ app/scodoc/sco_evaluations.py | 2 +- app/scodoc/sco_formsemestre_edit.py | 2 +- app/scodoc/sco_formsemestre_status.py | 2 +- app/scodoc/sco_liste_notes.py | 4 ++-- app/scodoc/sco_placement.py | 4 ++-- app/scodoc/sco_undo_notes.py | 2 +- app/views/notes.py | 13 ++++++------- 8 files changed, 25 insertions(+), 21 deletions(-) diff --git a/app/scodoc/sco_evaluation_db.py b/app/scodoc/sco_evaluation_db.py index 38110c6c8..2d58b5773 100644 --- a/app/scodoc/sco_evaluation_db.py +++ b/app/scodoc/sco_evaluation_db.py @@ -31,6 +31,7 @@ import flask from flask import url_for, g from flask_login import current_user +import sqlalchemy as sa from app import db, log @@ -72,7 +73,7 @@ _evaluationEditor = ndb.EditableTable( ) -def get_evaluation_dict(args: dict) -> list[dict]: +def get_evaluations_dict(args: dict) -> list[dict]: """Liste evaluations, triées numero (or most recent date first). Fonction de transition pour ancien code ScoDoc7. @@ -83,7 +84,12 @@ def get_evaluation_dict(args: dict) -> list[dict]: 'descrheure' : ' de 15h00 à 16h30' """ # calcule duree (chaine de car.) de chaque evaluation et ajoute jour_iso, matin, apresmidi - return [e.to_dict() for e in Evaluation.query.filter_by(**args)] + return [ + e.to_dict() + for e in Evaluation.query.filter_by(**args).order_by( + sa.desc(Evaluation.numero), sa.desc(Evaluation.date_debut) + ) + ] def do_evaluation_list_in_formsemestre(formsemestre_id): @@ -91,7 +97,7 @@ def do_evaluation_list_in_formsemestre(formsemestre_id): mods = sco_moduleimpl.moduleimpl_list(formsemestre_id=formsemestre_id) evals = [] for modimpl in mods: - evals += get_evaluation_dict(args={"moduleimpl_id": modimpl["moduleimpl_id"]}) + evals += get_evaluations_dict(args={"moduleimpl_id": modimpl["moduleimpl_id"]}) return evals @@ -161,7 +167,6 @@ def moduleimpl_evaluation_move(evaluation_id: int, after=0, redirect=1): (published) """ evaluation: Evaluation = Evaluation.query.get_or_404(evaluation_id) - moduleimpl_id = evaluation.moduleimpl_id redirect = int(redirect) # access: can change eval ? if not evaluation.moduleimpl.can_edit_evaluation(current_user): @@ -171,12 +176,12 @@ def moduleimpl_evaluation_move(evaluation_id: int, after=0, redirect=1): Evaluation.moduleimpl_evaluation_renumber( evaluation.moduleimpl, only_if_unumbered=True ) - e = get_evaluation_dict(args={"evaluation_id": evaluation_id})[0] + e = get_evaluations_dict(args={"evaluation_id": evaluation_id})[0] after = int(after) # 0: deplace avant, 1 deplace apres if after not in (0, 1): raise ValueError('invalid value for "after"') - mod_evals = get_evaluation_dict({"moduleimpl_id": e["moduleimpl_id"]}) + mod_evals = get_evaluations_dict({"moduleimpl_id": e["moduleimpl_id"]}) if len(mod_evals) > 1: idx = [p["evaluation_id"] for p in mod_evals].index(evaluation_id) neigh = None # object to swap with diff --git a/app/scodoc/sco_evaluations.py b/app/scodoc/sco_evaluations.py index 7c5ffd474..f6beeceb5 100644 --- a/app/scodoc/sco_evaluations.py +++ b/app/scodoc/sco_evaluations.py @@ -133,7 +133,7 @@ def do_evaluation_etat( ) # { etudid : note } # ---- Liste des groupes complets et incomplets - E = sco_evaluation_db.get_evaluation_dict(args={"evaluation_id": evaluation_id})[0] + E = sco_evaluation_db.get_evaluations_dict(args={"evaluation_id": evaluation_id})[0] M = sco_moduleimpl.moduleimpl_list(moduleimpl_id=E["moduleimpl_id"])[0] Mod = sco_edit_module.module_list(args={"module_id": M["module_id"]})[0] is_malus = Mod["module_type"] == ModuleType.MALUS # True si module de malus diff --git a/app/scodoc/sco_formsemestre_edit.py b/app/scodoc/sco_formsemestre_edit.py index 7b1ceb41a..bd0f6f42a 100644 --- a/app/scodoc/sco_formsemestre_edit.py +++ b/app/scodoc/sco_formsemestre_edit.py @@ -1445,7 +1445,7 @@ def do_formsemestre_delete(formsemestre_id): mods = sco_moduleimpl.moduleimpl_list(formsemestre_id=formsemestre_id) for mod in mods: # evaluations - evals = sco_evaluation_db.get_evaluation_dict( + evals = sco_evaluation_db.get_evaluations_dict( args={"moduleimpl_id": mod["moduleimpl_id"]} ) for e in evals: diff --git a/app/scodoc/sco_formsemestre_status.py b/app/scodoc/sco_formsemestre_status.py index 1a0163b4b..9cf40e437 100755 --- a/app/scodoc/sco_formsemestre_status.py +++ b/app/scodoc/sco_formsemestre_status.py @@ -490,7 +490,7 @@ def retreive_formsemestre_from_request() -> int: modimpl = modimpl[0] formsemestre_id = modimpl["formsemestre_id"] elif "evaluation_id" in args: - E = sco_evaluation_db.get_evaluation_dict( + E = sco_evaluation_db.get_evaluations_dict( {"evaluation_id": args["evaluation_id"]} ) if not E: diff --git a/app/scodoc/sco_liste_notes.py b/app/scodoc/sco_liste_notes.py index 6ac88dc51..2f0659938 100644 --- a/app/scodoc/sco_liste_notes.py +++ b/app/scodoc/sco_liste_notes.py @@ -69,10 +69,10 @@ def do_evaluation_listenotes( mode = None if moduleimpl_id: mode = "module" - evals = sco_evaluation_db.get_evaluation_dict({"moduleimpl_id": moduleimpl_id}) + evals = sco_evaluation_db.get_evaluations_dict({"moduleimpl_id": moduleimpl_id}) elif evaluation_id: mode = "eval" - evals = sco_evaluation_db.get_evaluation_dict({"evaluation_id": evaluation_id}) + evals = sco_evaluation_db.get_evaluations_dict({"evaluation_id": evaluation_id}) else: raise ValueError("missing argument: evaluation or module") if not evals: diff --git a/app/scodoc/sco_placement.py b/app/scodoc/sco_placement.py index d0cc4ca1b..daaa2f186 100644 --- a/app/scodoc/sco_placement.py +++ b/app/scodoc/sco_placement.py @@ -138,7 +138,7 @@ class PlacementForm(FlaskForm): def set_evaluation_infos(self, evaluation_id): """Initialise les données du formulaire avec les données de l'évaluation.""" - eval_data = sco_evaluation_db.get_evaluation_dict( + eval_data = sco_evaluation_db.get_evaluations_dict( {"evaluation_id": evaluation_id} ) if not eval_data: @@ -239,7 +239,7 @@ class PlacementRunner: self.groups_ids = [ gid if gid != TOUS else form.tous_id for gid in form["groups"].data ] - self.eval_data = sco_evaluation_db.get_evaluation_dict( + self.eval_data = sco_evaluation_db.get_evaluations_dict( {"evaluation_id": self.evaluation_id} )[0] self.groups = sco_groups.listgroups(self.groups_ids) diff --git a/app/scodoc/sco_undo_notes.py b/app/scodoc/sco_undo_notes.py index 61b84c0c4..dd1895048 100644 --- a/app/scodoc/sco_undo_notes.py +++ b/app/scodoc/sco_undo_notes.py @@ -149,7 +149,7 @@ def list_operations(evaluation_id): def evaluation_list_operations(evaluation_id): """Page listing operations on evaluation""" - E = sco_evaluation_db.get_evaluation_dict({"evaluation_id": evaluation_id})[0] + E = sco_evaluation_db.get_evaluations_dict({"evaluation_id": evaluation_id})[0] M = sco_moduleimpl.moduleimpl_list(moduleimpl_id=E["moduleimpl_id"])[0] Ops = list_operations(evaluation_id) diff --git a/app/views/notes.py b/app/views/notes.py index 9f198ba3b..af1d011af 100644 --- a/app/views/notes.py +++ b/app/views/notes.py @@ -407,14 +407,13 @@ def moduleimpl_evaluation_renumber(moduleimpl_id): ) Evaluation.moduleimpl_evaluation_renumber(modimpl) # redirect to moduleimpl page: - if redirect: - return flask.redirect( - url_for( - "notes.moduleimpl_status", - scodoc_dept=g.scodoc_dept, - moduleimpl_id=moduleimpl_id, - ) + return flask.redirect( + url_for( + "notes.moduleimpl_status", + scodoc_dept=g.scodoc_dept, + moduleimpl_id=moduleimpl_id, ) + ) sco_publish(