Fix: association nouvelle version

This commit is contained in:
Emmanuel Viennet 2021-09-24 20:20:45 +02:00
parent 7879c176dd
commit c41726c4a8
5 changed files with 36 additions and 33 deletions

View File

@ -311,7 +311,7 @@ def invalidate_sems_in_formation(formation_id):
) # > formation modif. ) # > formation modif.
def module_move(module_id, after=0, REQUEST=None, redirect=1): def module_move(module_id, after=0, redirect=1):
"""Move before/after previous one (decrement/increment numero)""" """Move before/after previous one (decrement/increment numero)"""
module = sco_edit_module.do_module_list({"module_id": module_id})[0] module = sco_edit_module.do_module_list({"module_id": module_id})[0]
redirect = int(redirect) redirect = int(redirect)

View File

@ -93,9 +93,7 @@ def formation_has_locked_sems(formation_id):
return sems return sems
def formation_export( def formation_export(formation_id, export_ids=False, export_tags=True, format=None):
formation_id, export_ids=False, export_tags=True, format=None, REQUEST=None
):
"""Get a formation, with UE, matieres, modules """Get a formation, with UE, matieres, modules
in desired format in desired format
""" """
@ -161,20 +159,18 @@ def formation_import_xml(doc: str, import_tags=True):
D = sco_xml.xml_to_dicts(f) D = sco_xml.xml_to_dicts(f)
assert D[0] == "formation" assert D[0] == "formation"
F = D[1] F = D[1]
F_quoted = F.copy() # F_quoted = F.copy()
log("F=%s" % F) # ndb.quote_dict(F_quoted)
ndb.quote_dict(F_quoted) F["dept_id"] = g.scodoc_dept_id
log("F_quoted=%s" % F_quoted)
# find new version number # find new version number
cnx = ndb.GetDBConnexion() cnx = ndb.GetDBConnexion()
cursor = cnx.cursor(cursor_factory=ndb.ScoDocCursor) cursor = cnx.cursor(cursor_factory=ndb.ScoDocCursor)
log(
"select max(version) from notes_formations where acronyme=%(acronyme)s and titre=%(titre)s"
% F_quoted
)
cursor.execute( cursor.execute(
"select max(version) from notes_formations where acronyme=%(acronyme)s and titre=%(titre)s", """SELECT max(version)
F_quoted, FROM notes_formations
WHERE acronyme=%(acronyme)s and titre=%(titre)s and dept_id=%(dept_id)s
""",
F,
) )
res = cursor.fetchall() res = cursor.fetchall()
try: try:
@ -195,7 +191,7 @@ def formation_import_xml(doc: str, import_tags=True):
assert ue_info[0] == "ue" assert ue_info[0] == "ue"
ue_info[1]["formation_id"] = formation_id ue_info[1]["formation_id"] = formation_id
if "ue_id" in ue_info[1]: if "ue_id" in ue_info[1]:
xml_ue_id = ue_info[1]["ue_id"] xml_ue_id = int(ue_info[1]["ue_id"])
del ue_info[1]["ue_id"] del ue_info[1]["ue_id"]
else: else:
xml_ue_id = None xml_ue_id = None
@ -211,7 +207,7 @@ def formation_import_xml(doc: str, import_tags=True):
for mod_info in mat_info[2]: for mod_info in mat_info[2]:
assert mod_info[0] == "module" assert mod_info[0] == "module"
if "module_id" in mod_info[1]: if "module_id" in mod_info[1]:
xml_module_id = mod_info[1]["module_id"] xml_module_id = int(mod_info[1]["module_id"])
del mod_info[1]["module_id"] del mod_info[1]["module_id"]
else: else:
xml_module_id = None xml_module_id = None
@ -229,7 +225,7 @@ def formation_import_xml(doc: str, import_tags=True):
return formation_id, modules_old2new, ues_old2new return formation_id, modules_old2new, ues_old2new
def formation_list_table(formation_id=None, args={}, REQUEST=None): def formation_list_table(formation_id=None, args={}):
"""List formation, grouped by titre and sorted by versions """List formation, grouped by titre and sorted by versions
and listing associated semestres and listing associated semestres
returns a table returns a table
@ -353,10 +349,11 @@ def formation_list_table(formation_id=None, args={}, REQUEST=None):
) )
def formation_create_new_version(formation_id, redirect=True, REQUEST=None): def formation_create_new_version(formation_id, redirect=True):
"duplicate formation, with new version number" "duplicate formation, with new version number"
xml = formation_export(formation_id, export_ids=True, format="xml") resp = formation_export(formation_id, export_ids=True, format="xml")
new_id, modules_old2new, ues_old2new = formation_import_xml(xml) xml_data = resp.get_data(as_text=True)
new_id, modules_old2new, ues_old2new = formation_import_xml(xml_data)
# news # news
F = formation_list(args={"formation_id": new_id})[0] F = formation_list(args={"formation_id": new_id})[0]
sco_news.add( sco_news.add(

View File

@ -96,6 +96,7 @@ _formsemestreEditor = ndb.EditableTable(
def get_formsemestre(formsemestre_id): def get_formsemestre(formsemestre_id):
"list ONE formsemestre" "list ONE formsemestre"
if not isinstance(formsemestre_id, int): if not isinstance(formsemestre_id, int):
raise ValueError()
raise ScoValueError( raise ScoValueError(
"""Semestre invalide, reprenez l'opération au départ ou si le problème persiste signalez l'erreur sur scodoc-devel@listes.univ-paris13.fr""" """Semestre invalide, reprenez l'opération au départ ou si le problème persiste signalez l'erreur sur scodoc-devel@listes.univ-paris13.fr"""
) )
@ -566,7 +567,7 @@ def list_formsemestre_by_etape(etape_apo=False, annee_scolaire=False):
return sems return sems
def view_formsemestre_by_etape(etape_apo=None, format="html", REQUEST=None): def view_formsemestre_by_etape(etape_apo=None, format="html"):
"""Affiche table des semestres correspondants à l'étape""" """Affiche table des semestres correspondants à l'étape"""
if etape_apo: if etape_apo:
html_title = ( html_title = (

View File

@ -1118,10 +1118,11 @@ def do_formsemestre_clone(
def formsemestre_associate_new_version( def formsemestre_associate_new_version(
formsemestre_id, formsemestre_id,
other_formsemestre_ids=[], other_formsemestre_ids=[],
REQUEST=None,
dialog_confirmed=False, dialog_confirmed=False,
): ):
"""Formulaire changement formation d'un semestre""" """Formulaire changement formation d'un semestre"""
formsemestre_id = int(formsemestre_id)
other_formsemestre_ids = [int(x) for x in other_formsemestre_ids]
if not dialog_confirmed: if not dialog_confirmed:
# dresse le liste des semestres de la meme formation et version # dresse le liste des semestres de la meme formation et version
sem = sco_formsemestre.get_formsemestre(formsemestre_id) sem = sco_formsemestre.get_formsemestre(formsemestre_id)
@ -1166,15 +1167,19 @@ def formsemestre_associate_new_version(
) )
else: else:
do_formsemestres_associate_new_version( do_formsemestres_associate_new_version(
[formsemestre_id] + other_formsemestre_ids, REQUEST=REQUEST [formsemestre_id] + other_formsemestre_ids
) )
return flask.redirect( return flask.redirect(
"formsemestre_status?formsemestre_id=%s&head_message=Formation%%20dupliquée" url_for(
% formsemestre_id "notes.formsemestre_status",
scodoc_dept=g.scodoc_dept,
formsemestre_id=formsemestre_id,
head_message="Formation dupliquée",
)
) )
def do_formsemestres_associate_new_version(formsemestre_ids, REQUEST=None): def do_formsemestres_associate_new_version(formsemestre_ids):
"""Cree une nouvelle version de la formation du semestre, et y rattache les semestres. """Cree une nouvelle version de la formation du semestre, et y rattache les semestres.
Tous les moduleimpl sont -associés à la nouvelle formation, ainsi que les decisions de jury Tous les moduleimpl sont -associés à la nouvelle formation, ainsi que les decisions de jury
si elles existent (codes d'UE validées). si elles existent (codes d'UE validées).
@ -1184,9 +1189,11 @@ def do_formsemestres_associate_new_version(formsemestre_ids, REQUEST=None):
if not formsemestre_ids: if not formsemestre_ids:
return return
# Check: tous de la même formation # Check: tous de la même formation
assert isinstance(formsemestre_ids[0], int)
sem = sco_formsemestre.get_formsemestre(formsemestre_ids[0]) sem = sco_formsemestre.get_formsemestre(formsemestre_ids[0])
formation_id = sem["formation_id"] formation_id = sem["formation_id"]
for formsemestre_id in formsemestre_ids[1:]: for formsemestre_id in formsemestre_ids[1:]:
assert isinstance(formsemestre_id, int)
sem = sco_formsemestre.get_formsemestre(formsemestre_id) sem = sco_formsemestre.get_formsemestre(formsemestre_id)
if formation_id != sem["formation_id"]: if formation_id != sem["formation_id"]:
raise ScoValueError("les semestres ne sont pas tous de la même formation !") raise ScoValueError("les semestres ne sont pas tous de la même formation !")
@ -1197,9 +1204,7 @@ def do_formsemestres_associate_new_version(formsemestre_ids, REQUEST=None):
formation_id, formation_id,
modules_old2new, modules_old2new,
ues_old2new, ues_old2new,
) = sco_formations.formation_create_new_version( ) = sco_formations.formation_create_new_version(formation_id, redirect=False)
formation_id, redirect=False, REQUEST=REQUEST
)
for formsemestre_id in formsemestre_ids: for formsemestre_id in formsemestre_ids:
sem = sco_formsemestre.get_formsemestre(formsemestre_id) sem = sco_formsemestre.get_formsemestre(formsemestre_id)

View File

@ -421,7 +421,7 @@ def index_html(REQUEST=None):
"""<h2>Programmes pédagogiques</h2> """<h2>Programmes pédagogiques</h2>
""", """,
] ]
T = sco_formations.formation_list_table(REQUEST=REQUEST) T = sco_formations.formation_list_table()
H.append(T.html()) H.append(T.html())
@ -464,7 +464,7 @@ sco_publish(
@scodoc @scodoc
@permission_required(Permission.ScoView) @permission_required(Permission.ScoView)
@scodoc7func @scodoc7func
def formation_list(format=None, REQUEST=None, formation_id=None, args={}): def formation_list(format=None, formation_id=None, args={}):
"""List formation(s) with given id, or matching args """List formation(s) with given id, or matching args
(when args is given, formation_id is ignored). (when args is given, formation_id is ignored).
""" """
@ -476,10 +476,10 @@ def formation_list(format=None, REQUEST=None, formation_id=None, args={}):
@scodoc @scodoc
@permission_required(Permission.ScoView) @permission_required(Permission.ScoView)
@scodoc7func @scodoc7func
def formation_export(formation_id, export_ids=False, format=None, REQUEST=None): def formation_export(formation_id, export_ids=False, format=None):
"Export de la formation au format indiqué (xml ou json)" "Export de la formation au format indiqué (xml ou json)"
return sco_formations.formation_export( return sco_formations.formation_export(
formation_id, export_ids=export_ids, format=format, REQUEST=REQUEST formation_id, export_ids=export_ids, format=format
) )