Ajout de sauvegarde/update
This commit is contained in:
parent
16ef57e019
commit
3c6e37f481
@ -1,7 +1,7 @@
|
||||
from flask_wtf import FlaskForm
|
||||
from flask_wtf.file import FileAllowed
|
||||
from wtforms import StringField, SubmitField, FileField, TextAreaField, RadioField
|
||||
from wtforms.validators import DataRequired, Regexp
|
||||
from wtforms.validators import DataRequired, Regexp, Optional
|
||||
|
||||
import yaml
|
||||
import os
|
||||
@ -19,6 +19,7 @@ class Form(FlaskForm):
|
||||
exporter = SubmitField("Exporter")
|
||||
fichier = FileField("Choisir fichier", validators=[FileAllowed(["yml"], "Fichier Yaml seulement!")])
|
||||
importer = SubmitField("Importer")
|
||||
referentiel = RadioField("Liste des référentiels", validators=[Optional()])
|
||||
|
||||
class PNForm(Form):
|
||||
regex = "^PN\d$"
|
||||
@ -36,7 +37,6 @@ class ACForm(Form):
|
||||
titre = StringField("Titre", validators=[DataRequired()] )
|
||||
saes = StringField("SAEs", validators=[DataRequired()] )
|
||||
|
||||
|
||||
class SAEForm(Form):
|
||||
regex = "^SAE\d{2}$"
|
||||
|
||||
@ -53,7 +53,6 @@ class SAEForm(Form):
|
||||
livrables = TextAreaField("Livrables", validators=[DataRequired()] )
|
||||
motscles = StringField("Mots clés", validators=[DataRequired()] )
|
||||
|
||||
|
||||
class RessourceForm(Form):
|
||||
regex = "^R\{3}$"
|
||||
|
||||
@ -101,7 +100,7 @@ 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())[5:-1]:
|
||||
for categorie, valeur in list(form.data.items())[6:-1]:
|
||||
output[categorie] = valeur
|
||||
|
||||
fichier = REPERTOIRE_YAML + form.code.data + ".yml"
|
||||
|
@ -13,6 +13,7 @@ def index():
|
||||
@app.route("/PN", methods=["GET","POST"])
|
||||
def PN():
|
||||
form = PNForm()
|
||||
form.referentiel.choices = [x for x in models.PN.query.all()]
|
||||
form_validation = form.validate_on_submit()
|
||||
form = form_import(form)
|
||||
if form_validation:
|
||||
@ -20,7 +21,8 @@ def PN():
|
||||
flash("Ajout du référentiel PN: {} ".format(form.code.data))
|
||||
form_export(form)
|
||||
if form.sauvegarder.data:
|
||||
if not "pn" in locals():
|
||||
pn = models.PN.query.filter_by(code=form.code.data).first()
|
||||
if pn == None:
|
||||
pn = models.PN()
|
||||
form.populate_obj(pn)
|
||||
db.session.add(pn)
|
||||
@ -31,13 +33,16 @@ def PN():
|
||||
@app.route("/AC", methods=["GET","POST"])
|
||||
def AC():
|
||||
form = ACForm()
|
||||
form.referentiel.choices = [x for x in models.AC.query.all()]
|
||||
form_validation = form.validate_on_submit()
|
||||
form = form_import(form)
|
||||
if form_validation:
|
||||
if form.exporter.data:
|
||||
flash("Ajout du référentiel AC: {} ".format(form.code.data))
|
||||
form_export(form)
|
||||
if not "ac" in locals():
|
||||
if form.sauvegarder.data:
|
||||
ac = models.AC.query.filter_by(code=form.code.data).first()
|
||||
if ac == None:
|
||||
ac = models.AC()
|
||||
form.populate_obj(ac)
|
||||
db.session.add(ac)
|
||||
@ -48,13 +53,16 @@ def AC():
|
||||
@app.route("/SAE", methods=["GET","POST"])
|
||||
def SAE():
|
||||
form = SAEForm()
|
||||
form.referentiel.choices = [x for x in models.SAE.query.all()]
|
||||
form_validation = form.validate_on_submit()
|
||||
form = form_import(form)
|
||||
if form_validation:
|
||||
if form.exporter.data:
|
||||
flash("Ajout du référentiel SAE: {} ".format(form.code.data))
|
||||
form_export(form)
|
||||
if not "sae" in locals():
|
||||
if form.sauvegarder.data:
|
||||
sae = models.SAE.query.filter_by(code=form.code.data).first()
|
||||
if sae == None:
|
||||
sae = models.SAE()
|
||||
form.populate_obj(sae)
|
||||
db.session.add(sae)
|
||||
@ -65,13 +73,16 @@ def SAE():
|
||||
@app.route("/Ressource", methods=["GET","POST"])
|
||||
def Ressource():
|
||||
form = RessourceForm()
|
||||
form.referentiel.choices = [x for x in models.Ressource.query.all()]
|
||||
form_validation = form.validate_on_submit()
|
||||
form = form_import(form)
|
||||
if form_validation:
|
||||
if form.exporter.data:
|
||||
flash("Ajout du référentiel Ressource: {} ".format(form.code.data))
|
||||
form_export(form)
|
||||
if not "ressource" in locals():
|
||||
if form.sauvegarder.data:
|
||||
ressource = models.Ressource.query.filter_by(code=form.code.data).first()
|
||||
if ressource == None:
|
||||
ressource = models.Ressource()
|
||||
form.populate_obj(ressource)
|
||||
db.session.add(ressource)
|
||||
@ -82,13 +93,16 @@ def Ressource():
|
||||
@app.route("/Competence", methods=["GET","POST"])
|
||||
def Competence():
|
||||
form = CompetenceForm()
|
||||
form.referentiel.choices = [x for x in models.Competence.query.all()]
|
||||
form_validation = form.validate_on_submit()
|
||||
form = form_import(form)
|
||||
if form_validation:
|
||||
if form.exporter.data:
|
||||
flash("Ajout du référentielCompetence: {} ".format(form.code.data))
|
||||
form_export(form)
|
||||
if not "competence" in locals():
|
||||
if form.sauvegarder.data:
|
||||
competence = models.Competence.query.filter_by(code=form.code.data).first()
|
||||
if competence == None:
|
||||
competence = models.Competence()
|
||||
form.populate_obj(competence)
|
||||
db.session.add(competence)
|
||||
|
@ -49,6 +49,11 @@
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
<ul>
|
||||
{% for referentiel in form.referentiel %}
|
||||
<li>{{ referentiel }} {{ referentiel.data.code }} - {{ referentiel.data.nom }}{{ referentiel.data.titre }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
</form>
|
||||
{% endblock %}
|
Loading…
Reference in New Issue
Block a user