Fix: supprime aussi les relations entre refs
This commit is contained in:
parent
0d804af5a1
commit
8b763ad68d
@ -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:
|
||||
|
@ -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 "<AC {}>".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())
|
||||
|
@ -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 %}
|
Loading…
Reference in New Issue
Block a user