From 8b763ad68dc9898d9ddbe5bdcbc8fe61a5f77fca Mon Sep 17 00:00:00 2001 From: Nekori Date: Mon, 10 May 2021 12:43:45 +0200 Subject: [PATCH] Fix: supprime aussi les relations entre refs --- app.db | Bin 65536 -> 65536 bytes app/forms.py | 4 +++- app/models.py | 8 +++----- app/templates/AC.html | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app.db b/app.db index faf2d52ee59bc9af3ec2a4619241bbb581089bab..5e8f86223a1c123814b502300a442b7a80bce733 100644 GIT binary patch delta 216 zcmZo@U}y6dGs;eMl-#s|LxG9^ zJy7opehERCphjB%T8P%003kUFg*YO delta 254 zcmZo@U}VSY? zM^{550VXsNLjguq5d#B|CCvPf8Th~RzvX`nH0dh8EGM%#BiI0D7|W1}gISytC}v== yDS$&^F-HIpCkSljNch9g#mN7Gf&T;l1^x>_?ML}1U;ZyEz{kieE(ul-aWMdf4><(@ diff --git a/app/forms.py b/app/forms.py index 8b210c6..d8d700c 100644 --- a/app/forms.py +++ b/app/forms.py @@ -47,6 +47,7 @@ class ACForm(Form): code = StringField("Code", validators=[DataRequired(), Regexp("^AC\d{4}$", message="Le code doit être de la forme AC0000.")]) titre = StringField("Titre", validators=[DataRequired()] ) saes = StringField("SAEs", validators=[DataRequired(), validate_ref_list("^(\s*(SAE\d{2}\s+)*)$", message="Les saes doit être de la forme SAE00.")] ) + ressources = StringField("Ressources", validators=[DataRequired(), validate_ref_list("^(\s*(R\d{3}\s+)*)$", message="Les ressources doit être de la forme R000.")] ) class SAEForm(Form): regex = "^SAE\d{2}$" @@ -92,6 +93,7 @@ class CompetenceForm(Form): niveaux = TextAreaField("Niveaux", validators=[DataRequired()] ) categorie_liste = ["saes","ressources","acs"] +categorie_to_model = {"saes": "SAE", "ressources": "Ressource", "acs": "AC"} separateur = None def form_import(form): @@ -154,7 +156,7 @@ def form_sauvegarder(form): if categorie in categorie_liste: resultat = [] refs = [ ref for ref in form[categorie].data.split(separateur) ] - ref_model = getattr(models, categorie.upper()[:-1]) + ref_model = getattr(models, categorie_to_model[categorie]) for ref in refs: ref_bdd = ref_model.query.filter_by(code=ref).first() if ref_bdd == None: diff --git a/app/models.py b/app/models.py index 157a1bd..d276a74 100644 --- a/app/models.py +++ b/app/models.py @@ -28,7 +28,8 @@ class PN(db.Model): class AC(db.Model): code = db.Column(db.String(6), primary_key = True) titre = db.Column(db.String(255)) - saes = db.relationship("SAE", secondary=SAEs_ACs, lazy=False, backref=db.backref("acs", lazy=False)) + saes = db.relationship("SAE", secondary=SAEs_ACs, cascade="all, delete", lazy=False, backref=db.backref("acs", lazy=False)) + ressources = db.relationship("Ressource", secondary=Ressources_ACs, cascade="all, delete", lazy=False, backref=db.backref("acs", lazy=False)) def __repr__(self): return "".format(self.code) @@ -42,8 +43,7 @@ class SAE(db.Model): projet = db.Column(db.String(3)) description = db.Column(db.Text()) coef = db.Column(db.String(255)) - #acs = db.relationship("AC", secondary=SAEs_ACs, lazy=True, backref=db.backref("saes", lazy=True)) - ressources = db.relationship("Ressource", secondary=Ressources_SAEs, lazy=False, backref=db.backref("saes", lazy=False)) + ressources = db.relationship("Ressource", secondary=Ressources_SAEs, cascade="all, delete", lazy=False, backref=db.backref("saes", lazy=False)) livrables = db.Column(db.Text()) motscles = db.Column(db.String(255)) @@ -57,8 +57,6 @@ class Ressource(db.Model): heures_formation = db.Column(db.String(3)) heures_tp = db.Column(db.String(3)) coef = db.Column(db.String(255)) - #acs = db.relationship("AC", secondary=Ressources_ACs, lazy=True, backref=db.backref("ressources", lazy=True)) - #saes = db.relationship("SAE", secondary=Ressources_SAEs, lazy=True, backref=db.backref("ressources", lazy=True)) prerequis = db.Column(db.String(255)) contexte = db.Column(db.Text()) contenu = db.Column(db.Text()) diff --git a/app/templates/AC.html b/app/templates/AC.html index 78490a4..e371e32 100644 --- a/app/templates/AC.html +++ b/app/templates/AC.html @@ -8,6 +8,6 @@ {{ render_field(form.code,"input") }} {{ render_field(form.titre,"input") }} {{ render_field(form.saes,"input") }} - +{{ render_field(form.ressources,"input") }} {% endblock %} \ No newline at end of file