From 40b31602d214ae2337ab45a8c0da6a4a2419d86f Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Thu, 16 Dec 2021 21:42:23 +0100 Subject: [PATCH] =?UTF-8?q?initialise=20num=C3=A9ros=20partitions=20pour?= =?UTF-8?q?=20tri=20(#225)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/scodoc/sco_edit_formation.py | 11 +---------- app/scodoc/sco_groups.py | 11 +++++++++++ app/scodoc/sco_utils.py | 10 ++++++++++ 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/app/scodoc/sco_edit_formation.py b/app/scodoc/sco_edit_formation.py index f5327584..050623ec 100644 --- a/app/scodoc/sco_edit_formation.py +++ b/app/scodoc/sco_edit_formation.py @@ -307,15 +307,6 @@ def do_formation_edit(args): formation.force_semestre_modules_aux_ues() -def objects_renumber(obj_list) -> None: - "fixe les numeros des objets de la liste pour ne pas changer son ordre" - log(f"objects_renumber {obj_list}") - for i, obj in enumerate(obj_list): - obj.numero = i - db.session.add(obj) - db.session.commit() - - def module_move(module_id, after=0, redirect=True): """Move before/after previous one (decrement/increment numero)""" redirect = bool(redirect) @@ -335,7 +326,7 @@ def module_move(module_id, after=0, redirect=True): modules = query.order_by(Module.numero, Module.code).all() if len({o.numero for o in modules}) != len(modules): # il y a des numeros identiques ! - objects_renumber(modules) + scu.objects_renumber(modules) if len(modules) > 1: idx = [m.id for m in modules].index(module.id) neigh = None # object to swap with diff --git a/app/scodoc/sco_groups.py b/app/scodoc/sco_groups.py index f8b84fb4..3f3f167f 100644 --- a/app/scodoc/sco_groups.py +++ b/app/scodoc/sco_groups.py @@ -45,6 +45,7 @@ import flask from flask import g, request from flask import url_for, make_response +from app.models import Partition import app.scodoc.sco_utils as scu import app.scodoc.notesdb as ndb from app import log, cache @@ -1059,6 +1060,16 @@ def partition_move(partition_id, after=0, redirect=1): if after not in (0, 1): raise ValueError('invalid value for "after"') others = get_partitions_list(formsemestre_id) + + objs = ( + Partition.query.filter_by(formsemestre_id=formsemestre_id) + .order_by(Partition.numero, Partition.partition_name) + .all() + ) + if len({o.numero for o in objs}) != len(objs): + # il y a des numeros identiques ! + scu.objects_renumber(objs) + if len(others) > 1: pidx = [p["partition_id"] for p in others].index(partition_id) # log("partition_move: after=%s pidx=%s" % (after, pidx)) diff --git a/app/scodoc/sco_utils.py b/app/scodoc/sco_utils.py index a9f0552a..dfb9946d 100644 --- a/app/scodoc/sco_utils.py +++ b/app/scodoc/sco_utils.py @@ -990,3 +990,13 @@ def confirm_dialog( ) else: return "\n".join(H) + + +def objects_renumber(obj_list) -> None: + """fixe les numeros des objets d'une liste de modèles + pour ne pas changer son ordre""" + log(f"objects_renumber {obj_list}") + for i, obj in enumerate(obj_list): + obj.numero = i + db.session.add(obj) + db.session.commit()