From 320a0f110f2b62634fc1720cbc6f56d005aa15a3 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Tue, 26 Sep 2023 22:40:34 +0200 Subject: [PATCH] =?UTF-8?q?Renforce=20les=20v=C3=A9rifications=20clonage?= =?UTF-8?q?=20=C3=A9tudiant=20dans=20autre=20dept?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/etudiants.py | 19 +++++++++++++++++++ sco_version.py | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/models/etudiants.py b/app/models/etudiants.py index a033bbce6..6dc036782 100644 --- a/app/models/etudiants.py +++ b/app/models/etudiants.py @@ -96,6 +96,25 @@ class Identite(db.Model): raise ScoValueError( "clonage étudiant: le département destination est identique à celui de départ" ) + # Vérifie les contraintes d'unicité + # ("dept_id", "code_nip") et ("dept_id", "code_ine") + if ( + self.code_nip is not None + and Identite.query.filter_by( + dept_id=new_dept_id, code_nip=self.code_nip + ).count() + > 0 + ) or ( + self.code_ine is not None + and Identite.query.filter_by( + dept_id=new_dept_id, code_ine=self.code_ine + ).count() + > 0 + ): + raise ScoValueError( + """clonage étudiant: un étudiant de même code existe déjà + dans le département destination""" + ) d = dict(self.__dict__) d.pop("id", None) # get rid of id d.pop("_sa_instance_state", None) # get rid of SQLAlchemy special attr diff --git a/sco_version.py b/sco_version.py index 61dc9fa95..3a4b4fc5f 100644 --- a/sco_version.py +++ b/sco_version.py @@ -1,7 +1,7 @@ # -*- mode: python -*- # -*- coding: utf-8 -*- -SCOVERSION = "9.6.35" +SCOVERSION = "9.6.36" SCONAME = "ScoDoc"