Fix Charger: données qui s'affiche pas

This commit is contained in:
Éric Li 2021-05-07 12:58:38 +02:00
parent 18269242b8
commit 42334c7946

View File

@ -29,7 +29,7 @@ class PNForm(Form):
nom = StringField("Nom", validators=[DataRequired()] )
diminutif = StringField("Diminutif", validators=[DataRequired()] )
description = TextAreaField("Description", validators=[DataRequired()] )
type = RadioField("Type", choices=[1,2,3], validators=[DataRequired()])
type = RadioField("Type", choices=["1","2","3"], validators=[DataRequired()])
class ACForm(Form):
regex = "^AC\d{4}$"
@ -93,17 +93,15 @@ def form_import(form):
return form
fichier_Yaml = yaml.safe_load(form.fichier.data.read())
for categorie, valeur in fichier_Yaml.items():
form[categorie].data = valeur
form[categorie].process_data(valeur)
form.validate_on_submit() # Réinitialise les messages d'erreur
return form
def form_export(form):
""" Si le formulaire est valide => exporte dans un fichier yaml avec les informations du formulaire """
output = {}
for categorie, valeur in list(form.data.items())[6:-1]:
output[categorie] = valeur
fichier = REPERTOIRE_YAML + form.code.data + ".yml"
with open(fichier, "w", encoding="utf8") as fid:
fid.write(yaml.dump(output))
@ -118,6 +116,6 @@ def form_charger(form):
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[categorie].process_data(referentiel.__dict__[categorie])
form.validate_on_submit()
return form