From 18269242b835b15abfadb8a782cb66411a83cff5 Mon Sep 17 00:00:00 2001 From: Nekori Date: Fri, 7 May 2021 12:32:10 +0200 Subject: [PATCH] Charger --- app.db | Bin 53248 -> 53248 bytes app/forms.py | 19 +++++++++++++++++-- app/routes.py | 15 ++++++++++----- app/templates/form.html | 2 +- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/app.db b/app.db index 9721fb179ded099d314d876f2769a6dc3be517ab..4f8dc27415cd2dcfe51c3646700e04742721f01d 100644 GIT binary patch delta 63 zcmZozz}&Ead4e>fz(g5mMuCk9%l%my`Css#+$<=tmw)ofcsWT1F-8_iNl8a%10V>= QEGbGgOern|qD2V>09zyzR{#J2 delta 63 zcmZozz}&Ead4e<}|3n#QM*fWn%l%my_@DEi+$<=tmw)ofcsWUNMixnFNk?Y`APC7U SDN0o^EKW= 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")}}
- {{ form.charger(class="button is-static")}} + {{ form.charger(class="button")}}
{{ form.exporter(class="button")}}