forked from ScoDoc/ScoDoc
initialise numéros partitions pour tri (#225)
This commit is contained in:
parent
5f409f0267
commit
40b31602d2
@ -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
|
||||
|
@ -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))
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user