initialise numéros partitions pour tri (#225)

This commit is contained in:
Emmanuel Viennet 2021-12-16 21:42:23 +01:00
parent 5f409f0267
commit 40b31602d2
3 changed files with 22 additions and 10 deletions

View File

@ -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

View File

@ -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))

View File

@ -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()