forked from eric.li/EditionPN
Charger
This commit is contained in:
parent
d6b9a7f6bd
commit
18269242b8
17
app/forms.py
17
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 == "":
|
||||
@ -106,3 +107,17 @@ def form_export(form):
|
||||
fichier = REPERTOIRE_YAML + form.code.data + ".yml"
|
||||
with open(fichier, "w", encoding="utf8") as fid:
|
||||
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
|
@ -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)
|
||||
|
@ -24,7 +24,7 @@
|
||||
{{ form.sauvegarder(class="button")}}
|
||||
</div>
|
||||
<div class="control">
|
||||
{{ form.charger(class="button is-static")}}
|
||||
{{ form.charger(class="button")}}
|
||||
</div>
|
||||
<div class="control">
|
||||
{{ form.exporter(class="button")}}
|
||||
|
Loading…
Reference in New Issue
Block a user