diff --git a/app/scodoc/sco_edit_ue.py b/app/scodoc/sco_edit_ue.py index a5710c825d..623753ddb8 100644 --- a/app/scodoc/sco_edit_ue.py +++ b/app/scodoc/sco_edit_ue.py @@ -28,6 +28,8 @@ """Ajout/Modification/Suppression UE """ +import re + import flask from flask import flash, render_template, url_for from flask import g, request @@ -267,10 +269,19 @@ def ue_edit(ue_id=None, create=False, formation_id=None, default_semestre_idx=No else: ue = None title = "Création d'une UE" + + exp = re.compile(r"UCOD(\d+)$") + matches = {exp.match(u.ue_code) for u in UniteEns.query if exp.match(u.ue_code)} + max_code = ( + max(int(match.group(1)) for match in matches if match) if matches else 0 + ) + proposed_code = f"UCOD{max_code+1}" + initvalues = { "semestre_idx": default_semestre_idx, "color": ue_guess_color_default(formation_id, default_semestre_idx), "coef_rcue": 1.0, + "ue_code": proposed_code, } submitlabel = "Créer cette UE" can_change_semestre_id = True