Ajout de sauvegarde/update

This commit is contained in:
Éric Li 2021-05-06 19:26:09 +02:00
parent 16ef57e019
commit 3c6e37f481
3 changed files with 27 additions and 9 deletions

View File

@ -1,7 +1,7 @@
from flask_wtf import FlaskForm from flask_wtf import FlaskForm
from flask_wtf.file import FileAllowed from flask_wtf.file import FileAllowed
from wtforms import StringField, SubmitField, FileField, TextAreaField, RadioField from wtforms import StringField, SubmitField, FileField, TextAreaField, RadioField
from wtforms.validators import DataRequired, Regexp from wtforms.validators import DataRequired, Regexp, Optional
import yaml import yaml
import os import os
@ -19,6 +19,7 @@ class Form(FlaskForm):
exporter = SubmitField("Exporter") exporter = SubmitField("Exporter")
fichier = FileField("Choisir fichier", validators=[FileAllowed(["yml"], "Fichier Yaml seulement!")]) fichier = FileField("Choisir fichier", validators=[FileAllowed(["yml"], "Fichier Yaml seulement!")])
importer = SubmitField("Importer") importer = SubmitField("Importer")
referentiel = RadioField("Liste des référentiels", validators=[Optional()])
class PNForm(Form): class PNForm(Form):
regex = "^PN\d$" regex = "^PN\d$"
@ -36,7 +37,6 @@ class ACForm(Form):
titre = StringField("Titre", validators=[DataRequired()] ) titre = StringField("Titre", validators=[DataRequired()] )
saes = StringField("SAEs", validators=[DataRequired()] ) saes = StringField("SAEs", validators=[DataRequired()] )
class SAEForm(Form): class SAEForm(Form):
regex = "^SAE\d{2}$" regex = "^SAE\d{2}$"
@ -53,7 +53,6 @@ class SAEForm(Form):
livrables = TextAreaField("Livrables", validators=[DataRequired()] ) livrables = TextAreaField("Livrables", validators=[DataRequired()] )
motscles = StringField("Mots clés", validators=[DataRequired()] ) motscles = StringField("Mots clés", validators=[DataRequired()] )
class RessourceForm(Form): class RessourceForm(Form):
regex = "^R\{3}$" 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 """ """ Si le formulaire est valide => exporte dans un fichier yaml avec les informations du formulaire """
output = {} output = {}
for categorie, valeur in list(form.data.items())[5:-1]: for categorie, valeur in list(form.data.items())[6:-1]:
output[categorie] = valeur output[categorie] = valeur
fichier = REPERTOIRE_YAML + form.code.data + ".yml" fichier = REPERTOIRE_YAML + form.code.data + ".yml"

View File

@ -13,6 +13,7 @@ def index():
@app.route("/PN", methods=["GET","POST"]) @app.route("/PN", methods=["GET","POST"])
def PN(): def PN():
form = PNForm() form = PNForm()
form.referentiel.choices = [x for x in models.PN.query.all()]
form_validation = form.validate_on_submit() form_validation = form.validate_on_submit()
form = form_import(form) form = form_import(form)
if form_validation: if form_validation:
@ -20,7 +21,8 @@ def PN():
flash("Ajout du référentiel PN: {} ".format(form.code.data)) flash("Ajout du référentiel PN: {} ".format(form.code.data))
form_export(form) form_export(form)
if form.sauvegarder.data: 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() pn = models.PN()
form.populate_obj(pn) form.populate_obj(pn)
db.session.add(pn) db.session.add(pn)
@ -31,13 +33,16 @@ def PN():
@app.route("/AC", methods=["GET","POST"]) @app.route("/AC", methods=["GET","POST"])
def AC(): def AC():
form = ACForm() form = ACForm()
form.referentiel.choices = [x for x in models.AC.query.all()]
form_validation = form.validate_on_submit() form_validation = form.validate_on_submit()
form = form_import(form) form = form_import(form)
if form_validation: if form_validation:
if form.exporter.data: if form.exporter.data:
flash("Ajout du référentiel AC: {} ".format(form.code.data)) flash("Ajout du référentiel AC: {} ".format(form.code.data))
form_export(form) 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() ac = models.AC()
form.populate_obj(ac) form.populate_obj(ac)
db.session.add(ac) db.session.add(ac)
@ -48,13 +53,16 @@ def AC():
@app.route("/SAE", methods=["GET","POST"]) @app.route("/SAE", methods=["GET","POST"])
def SAE(): def SAE():
form = SAEForm() form = SAEForm()
form.referentiel.choices = [x for x in models.SAE.query.all()]
form_validation = form.validate_on_submit() form_validation = form.validate_on_submit()
form = form_import(form) form = form_import(form)
if form_validation: if form_validation:
if form.exporter.data: if form.exporter.data:
flash("Ajout du référentiel SAE: {} ".format(form.code.data)) flash("Ajout du référentiel SAE: {} ".format(form.code.data))
form_export(form) 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() sae = models.SAE()
form.populate_obj(sae) form.populate_obj(sae)
db.session.add(sae) db.session.add(sae)
@ -65,13 +73,16 @@ def SAE():
@app.route("/Ressource", methods=["GET","POST"]) @app.route("/Ressource", methods=["GET","POST"])
def Ressource(): def Ressource():
form = RessourceForm() form = RessourceForm()
form.referentiel.choices = [x for x in models.Ressource.query.all()]
form_validation = form.validate_on_submit() form_validation = form.validate_on_submit()
form = form_import(form) form = form_import(form)
if form_validation: if form_validation:
if form.exporter.data: if form.exporter.data:
flash("Ajout du référentiel Ressource: {} ".format(form.code.data)) flash("Ajout du référentiel Ressource: {} ".format(form.code.data))
form_export(form) 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() ressource = models.Ressource()
form.populate_obj(ressource) form.populate_obj(ressource)
db.session.add(ressource) db.session.add(ressource)
@ -82,13 +93,16 @@ def Ressource():
@app.route("/Competence", methods=["GET","POST"]) @app.route("/Competence", methods=["GET","POST"])
def Competence(): def Competence():
form = CompetenceForm() form = CompetenceForm()
form.referentiel.choices = [x for x in models.Competence.query.all()]
form_validation = form.validate_on_submit() form_validation = form.validate_on_submit()
form = form_import(form) form = form_import(form)
if form_validation: if form_validation:
if form.exporter.data: if form.exporter.data:
flash("Ajout du référentielCompetence: {} ".format(form.code.data)) flash("Ajout du référentielCompetence: {} ".format(form.code.data))
form_export(form) 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() competence = models.Competence()
form.populate_obj(competence) form.populate_obj(competence)
db.session.add(competence) db.session.add(competence)

View File

@ -49,6 +49,11 @@
{% endfor %} {% endfor %}
</div> </div>
</div> </div>
<ul>
{% for referentiel in form.referentiel %}
<li>{{ referentiel }} {{ referentiel.data.code }} - {{ referentiel.data.nom }}{{ referentiel.data.titre }}</li>
{% endfor %}
</ul>
</div> </div>
</form> </form>
{% endblock %} {% endblock %}