forked from ScoDoc/ScoDoc
Ordre des modules et UE (edition PN et poids)
This commit is contained in:
parent
aeb0d67f38
commit
478688fe49
@ -51,11 +51,13 @@ def df_load_module_coefs(formation_id: int, semestre_idx: int = None) -> pd.Data
|
|||||||
|
|
||||||
Si semestre_idx None, prend toutes les UE de la formation.
|
Si semestre_idx None, prend toutes les UE de la formation.
|
||||||
"""
|
"""
|
||||||
ues = UniteEns.query.filter_by(formation_id=formation_id).filter(
|
ues = (
|
||||||
UniteEns.type != sco_codes_parcours.UE_SPORT
|
UniteEns.query.filter_by(formation_id=formation_id)
|
||||||
|
.filter(UniteEns.type != sco_codes_parcours.UE_SPORT)
|
||||||
|
.order_by(UniteEns.semestre_idx, UniteEns.numero, UniteEns.acronyme)
|
||||||
)
|
)
|
||||||
modules = Module.query.filter_by(formation_id=formation_id).order_by(
|
modules = Module.query.filter_by(formation_id=formation_id).order_by(
|
||||||
Module.semestre_id, Module.numero
|
Module.semestre_id, Module.module_type.desc(), Module.numero, Module.code
|
||||||
)
|
)
|
||||||
if semestre_idx is not None:
|
if semestre_idx is not None:
|
||||||
ues = ues.filter_by(semestre_idx=semestre_idx)
|
ues = ues.filter_by(semestre_idx=semestre_idx)
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
"""ScoDoc 9 models : Modules
|
"""ScoDoc 9 models : Modules
|
||||||
"""
|
"""
|
||||||
from typing import Any
|
|
||||||
|
|
||||||
from app import db
|
from app import db
|
||||||
from app.models import APO_CODE_STR_LEN
|
from app.models import APO_CODE_STR_LEN
|
||||||
|
@ -50,10 +50,10 @@ def html_edit_formation_apc(
|
|||||||
parcours = formation.get_parcours()
|
parcours = formation.get_parcours()
|
||||||
assert parcours.APC_SAE
|
assert parcours.APC_SAE
|
||||||
ressources = formation.modules.filter_by(module_type=ModuleType.RESSOURCE).order_by(
|
ressources = formation.modules.filter_by(module_type=ModuleType.RESSOURCE).order_by(
|
||||||
Module.semestre_id, Module.numero
|
Module.semestre_id, Module.numero, Module.code
|
||||||
)
|
)
|
||||||
saes = formation.modules.filter_by(module_type=ModuleType.SAE).order_by(
|
saes = formation.modules.filter_by(module_type=ModuleType.SAE).order_by(
|
||||||
Module.semestre_id, Module.numero
|
Module.semestre_id, Module.numero, Module.code
|
||||||
)
|
)
|
||||||
if semestre_idx is None:
|
if semestre_idx is None:
|
||||||
semestre_ids = range(1, parcours.NB_SEM + 1)
|
semestre_ids = range(1, parcours.NB_SEM + 1)
|
||||||
@ -61,7 +61,7 @@ def html_edit_formation_apc(
|
|||||||
semestre_ids = [semestre_idx]
|
semestre_ids = [semestre_idx]
|
||||||
other_modules = formation.modules.filter(
|
other_modules = formation.modules.filter(
|
||||||
Module.module_type != ModuleType.SAE, Module.module_type != ModuleType.RESSOURCE
|
Module.module_type != ModuleType.SAE, Module.module_type != ModuleType.RESSOURCE
|
||||||
)
|
).order_by(Module.semestre_id, Module.module_type, Module.numero, Module.code)
|
||||||
arrow_up, arrow_down, arrow_none = sco_groups.get_arrow_icons_tags()
|
arrow_up, arrow_down, arrow_none = sco_groups.get_arrow_icons_tags()
|
||||||
|
|
||||||
icons = {
|
icons = {
|
||||||
|
@ -31,9 +31,12 @@
|
|||||||
import flask
|
import flask
|
||||||
from flask import g, url_for, request
|
from flask import g, url_for, request
|
||||||
|
|
||||||
|
from app import db
|
||||||
|
from app import log
|
||||||
|
from app.models.modules import Module
|
||||||
|
|
||||||
import app.scodoc.notesdb as ndb
|
import app.scodoc.notesdb as ndb
|
||||||
import app.scodoc.sco_utils as scu
|
import app.scodoc.sco_utils as scu
|
||||||
from app import log
|
|
||||||
from app.scodoc.TrivialFormulator import TrivialFormulator, tf_error_message
|
from app.scodoc.TrivialFormulator import TrivialFormulator, tf_error_message
|
||||||
from app.scodoc.sco_exceptions import ScoValueError, ScoLockedFormError
|
from app.scodoc.sco_exceptions import ScoValueError, ScoLockedFormError
|
||||||
|
|
||||||
@ -311,39 +314,54 @@ def invalidate_sems_in_formation(formation_id):
|
|||||||
) # > formation modif.
|
) # > formation modif.
|
||||||
|
|
||||||
|
|
||||||
def module_move(module_id, after=0, redirect=1):
|
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)"""
|
"""Move before/after previous one (decrement/increment numero)"""
|
||||||
module = sco_edit_module.module_list({"module_id": module_id})[0]
|
redirect = bool(redirect)
|
||||||
redirect = int(redirect)
|
module = Module.query.get_or_404(module_id)
|
||||||
after = int(after) # 0: deplace avant, 1 deplace apres
|
after = int(after) # 0: deplace avant, 1 deplace apres
|
||||||
if after not in (0, 1):
|
if after not in (0, 1):
|
||||||
raise ValueError('invalid value for "after"')
|
raise ValueError(f'invalid value for "after" ({after})')
|
||||||
formation_id = module["formation_id"]
|
if module.formation.is_apc():
|
||||||
others = sco_edit_module.module_list({"matiere_id": module["matiere_id"]})
|
# pas de matières, mais on prend tous les modules de même type de la formation
|
||||||
# log('others=%s' % others)
|
query = Module.query.filter_by(
|
||||||
if len(others) > 1:
|
semestre_id=module.semestre_id,
|
||||||
idx = [p["module_id"] for p in others].index(module_id)
|
formation=module.formation,
|
||||||
# log('module_move: after=%s idx=%s' % (after, idx))
|
module_type=module.module_type,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
query = Module.query.filter_by(matiere=module.matiere)
|
||||||
|
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)
|
||||||
|
if len(modules) > 1:
|
||||||
|
idx = [m.id for m in modules].index(module.id)
|
||||||
neigh = None # object to swap with
|
neigh = None # object to swap with
|
||||||
if after == 0 and idx > 0:
|
if after == 0 and idx > 0:
|
||||||
neigh = others[idx - 1]
|
neigh = modules[idx - 1]
|
||||||
elif after == 1 and idx < len(others) - 1:
|
elif after == 1 and idx < len(modules) - 1:
|
||||||
neigh = others[idx + 1]
|
neigh = modules[idx + 1]
|
||||||
if neigh: #
|
if neigh: # échange les numéros
|
||||||
# swap numero between partition and its neighbor
|
module.numero, neigh.numero = neigh.numero, module.numero
|
||||||
# log('moving module %s' % module_id)
|
db.session.add(module)
|
||||||
cnx = ndb.GetDBConnexion()
|
db.session.add(neigh)
|
||||||
module["numero"], neigh["numero"] = neigh["numero"], module["numero"]
|
db.session.commit()
|
||||||
if module["numero"] == neigh["numero"]:
|
|
||||||
neigh["numero"] -= 2 * after - 1
|
|
||||||
sco_edit_module._moduleEditor.edit(cnx, module)
|
|
||||||
sco_edit_module._moduleEditor.edit(cnx, neigh)
|
|
||||||
|
|
||||||
# redirect to ue_list page:
|
# redirect to ue_list page:
|
||||||
if redirect:
|
if redirect:
|
||||||
return flask.redirect(
|
return flask.redirect(
|
||||||
url_for(
|
url_for(
|
||||||
"notes.ue_table", scodoc_dept=g.scodoc_dept, formation_id=formation_id
|
"notes.ue_table",
|
||||||
|
scodoc_dept=g.scodoc_dept,
|
||||||
|
formation_id=module.formation.id,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user