Génère code par défaut pour les nouvelles UEs

This commit is contained in:
Emmanuel Viennet 2023-02-27 15:39:29 +01:00
parent b449546918
commit 7e6d1ebba0

View File

@ -28,6 +28,8 @@
"""Ajout/Modification/Suppression UE """Ajout/Modification/Suppression UE
""" """
import re
import flask import flask
from flask import flash, render_template, url_for from flask import flash, render_template, url_for
from flask import g, request 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: else:
ue = None ue = None
title = "Création d'une UE" 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 = { initvalues = {
"semestre_idx": default_semestre_idx, "semestre_idx": default_semestre_idx,
"color": ue_guess_color_default(formation_id, default_semestre_idx), "color": ue_guess_color_default(formation_id, default_semestre_idx),
"coef_rcue": 1.0, "coef_rcue": 1.0,
"ue_code": proposed_code,
} }
submitlabel = "Créer cette UE" submitlabel = "Créer cette UE"
can_change_semestre_id = True can_change_semestre_id = True