diff --git a/app.db b/app.db index 9721fb1..4f8dc27 100644 Binary files a/app.db and b/app.db differ diff --git a/app/forms.py b/app/forms.py index d392a68..1cc683b 100644 --- a/app/forms.py +++ b/app/forms.py @@ -3,6 +3,7 @@ from flask_wtf.file import FileAllowed from wtforms import StringField, SubmitField, FileField, TextAreaField, RadioField from wtforms.validators import DataRequired, Regexp, Optional +import app.models as models import yaml import os import re @@ -81,7 +82,7 @@ class CompetenceForm(Form): niveaux = TextAreaField("Niveaux", validators=[DataRequired()] ) def form_import(form): - """ Si import a été appuyé et qu'il n'y a pas d'erreur d'import => importe le fichier yaml""" + """ Si le bouton import a été appuyé et qu'il n'y a pas d'erreur d'import => importe le fichier yaml""" # Bouton import appuyé et fichier yaml selectionné if form.importer.data and len(form.fichier.errors) == 0: if form.fichier.data.filename == "": @@ -105,4 +106,18 @@ def form_export(form): fichier = REPERTOIRE_YAML + form.code.data + ".yml" with open(fichier, "w", encoding="utf8") as fid: - fid.write(yaml.dump(output)) \ No newline at end of file + fid.write(yaml.dump(output)) + +def form_charger(form): + """ Si le bouton charger est appuyé et qu'un référentiel du BDD a été selectionné => remplie le formulaire avec ses informations """ + if form.charger.data: + if form.referentiel.data == None: + form.referentiel.errors.append("Aucun référentiel n'a été selectionné!") + else: + temp = form.referentiel.data[1:-1].split() + model = getattr(models, temp[0]) + referentiel = model.query.filter_by(code=temp[1]).first() + for categorie in list(referentiel.__dict__)[1:]: + form[categorie].data = referentiel.__dict__[categorie] + form.validate_on_submit() + return form \ No newline at end of file diff --git a/app/routes.py b/app/routes.py index 5aa6dc7..d969478 100644 --- a/app/routes.py +++ b/app/routes.py @@ -16,7 +16,8 @@ def PN(): form.referentiel.choices = [x for x in models.PN.query.all()] form_validation = form.validate_on_submit() form = form_import(form) - if form_validation: + form = form_charger(form) + if form_validation and not form.charger.data: if form.exporter.data: flash("Ajout du référentiel PN: {} ".format(form.code.data)) form_export(form) @@ -36,7 +37,8 @@ def AC(): form.referentiel.choices = [x for x in models.AC.query.all()] form_validation = form.validate_on_submit() form = form_import(form) - if form_validation: + form = form_charger(form) + if form_validation and not form.charger.data: if form.exporter.data: flash("Ajout du référentiel AC: {} ".format(form.code.data)) form_export(form) @@ -56,7 +58,8 @@ def SAE(): form.referentiel.choices = [x for x in models.SAE.query.all()] form_validation = form.validate_on_submit() form = form_import(form) - if form_validation: + form = form_charger(form) + if form_validation and not form.charger.data: if form.exporter.data: flash("Ajout du référentiel SAE: {} ".format(form.code.data)) form_export(form) @@ -76,7 +79,8 @@ def Ressource(): form.referentiel.choices = [x for x in models.Ressource.query.all()] form_validation = form.validate_on_submit() form = form_import(form) - if form_validation: + form = form_charger(form) + if form_validation and not form.charger.data: if form.exporter.data: flash("Ajout du référentiel Ressource: {} ".format(form.code.data)) form_export(form) @@ -96,7 +100,8 @@ def Competence(): form.referentiel.choices = [x for x in models.Competence.query.all()] form_validation = form.validate_on_submit() form = form_import(form) - if form_validation: + form = form_charger(form) + if form_validation and not form.charger.data: if form.exporter.data: flash("Ajout du référentielCompetence: {} ".format(form.code.data)) form_export(form) diff --git a/app/templates/form.html b/app/templates/form.html index ac737ad..f67aab8 100644 --- a/app/templates/form.html +++ b/app/templates/form.html @@ -24,7 +24,7 @@ {{ form.sauvegarder(class="button")}}