From d8776485465574009876ea5022f09c75324eceb2 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Fri, 18 Feb 2022 22:19:23 +0100 Subject: [PATCH] =?UTF-8?q?empeche=20cr=C3=A9ation=20de=20d=C3=A9partement?= =?UTF-8?q?s=20avec=20m=C3=AAme=20acronyme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/departements.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/models/departements.py b/app/models/departements.py index ebe5cc145..44a963ca0 100644 --- a/app/models/departements.py +++ b/app/models/departements.py @@ -55,6 +55,9 @@ def create_dept(acronym: str, visible=True) -> Departement: "Create new departement" from app.models import ScoPreference + existing = Departement.query.filter_by(acronym=acronym).count() + if existing: + raise ValueError(f"acronyme {acronym} déjà existant") departement = Departement(acronym=acronym, visible=visible) p1 = ScoPreference(name="DeptName", value=acronym, departement=departement) db.session.add(p1)