forked from eric.li/EditionPN
Ajout de supprimer
This commit is contained in:
parent
3c18b88f2e
commit
0d804af5a1
19
app/forms.py
19
app/forms.py
@ -1,3 +1,4 @@
|
||||
from flask import redirect, url_for
|
||||
from flask_wtf import FlaskForm
|
||||
from flask_wtf.file import FileAllowed
|
||||
from wtforms import StringField, SubmitField, FileField, TextAreaField, RadioField
|
||||
@ -25,6 +26,7 @@ class Form(FlaskForm):
|
||||
|
||||
sauvegarder = SubmitField("Sauvegarder")
|
||||
charger = SubmitField("Charger")
|
||||
supprimer = SubmitField("Supprimer")
|
||||
exporter = SubmitField("Exporter")
|
||||
fichier = FileField("Choisir fichier", validators=[FileAllowed(["yml"], "Fichier Yaml seulement!")])
|
||||
importer = SubmitField("Importer")
|
||||
@ -114,7 +116,7 @@ def form_import(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]:
|
||||
for categorie, valeur in list(form.data.items())[7:-1]:
|
||||
if categorie in categorie_liste:
|
||||
output[categorie] = [ referentiel for referentiel in valeur.split(separateur) ]
|
||||
else:
|
||||
@ -148,7 +150,7 @@ def form_sauvegarder(form):
|
||||
if referentiel == None:
|
||||
referentiel = model()
|
||||
# Si le référentiel contient une catégorie avec une liste de référentiels
|
||||
for categorie, valeur in list(form.data.items())[6:-1]:
|
||||
for categorie, valeur in list(form.data.items())[7:-1]:
|
||||
if categorie in categorie_liste:
|
||||
resultat = []
|
||||
refs = [ ref for ref in form[categorie].data.split(separateur) ]
|
||||
@ -166,3 +168,16 @@ def form_sauvegarder(form):
|
||||
form.populate_obj(referentiel)
|
||||
db.session.add(referentiel)
|
||||
db.session.commit()
|
||||
|
||||
def form_supprimer(form):
|
||||
if form.supprimer.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()
|
||||
db.session.delete(referentiel)
|
||||
db.session.commit()
|
||||
return True, redirect(url_for(temp[0]))
|
||||
return False, form
|
@ -17,6 +17,9 @@ def PN():
|
||||
form_validation = form.validate_on_submit()
|
||||
form = form_import(form)
|
||||
form = form_charger(form)
|
||||
temp = form_supprimer(form)
|
||||
if temp[0] == True: return temp[1]
|
||||
else: form = temp[1]
|
||||
if form_validation and not form.charger.data:
|
||||
if form.exporter.data:
|
||||
flash("Ajout du référentiel PN: {} ".format(form.code.data))
|
||||
@ -32,6 +35,9 @@ def AC():
|
||||
form_validation = form.validate_on_submit()
|
||||
form = form_import(form)
|
||||
form = form_charger(form)
|
||||
temp = form_supprimer(form)
|
||||
if temp[0] == True: return temp[1]
|
||||
else: form = temp[1]
|
||||
if form_validation and not form.charger.data:
|
||||
if form.exporter.data:
|
||||
flash("Ajout du référentiel AC: {} ".format(form.code.data))
|
||||
@ -47,6 +53,9 @@ def SAE():
|
||||
form_validation = form.validate_on_submit()
|
||||
form = form_import(form)
|
||||
form = form_charger(form)
|
||||
temp = form_supprimer(form)
|
||||
if temp[0] == True: return temp[1]
|
||||
else: form = temp[1]
|
||||
if form_validation and not form.charger.data:
|
||||
if form.exporter.data:
|
||||
flash("Ajout du référentiel SAE: {} ".format(form.code.data))
|
||||
@ -62,6 +71,9 @@ def Ressource():
|
||||
form_validation = form.validate_on_submit()
|
||||
form = form_import(form)
|
||||
form = form_charger(form)
|
||||
temp = form_supprimer(form)
|
||||
if temp[0] == True: return temp[1]
|
||||
else: form = temp[1]
|
||||
if form_validation and not form.charger.data:
|
||||
if form.exporter.data:
|
||||
flash("Ajout du référentiel Ressource: {} ".format(form.code.data))
|
||||
@ -77,6 +89,9 @@ def Competence():
|
||||
form_validation = form.validate_on_submit()
|
||||
form = form_import(form)
|
||||
form = form_charger(form)
|
||||
temp = form_supprimer(form)
|
||||
if temp[0] == True: return temp[1]
|
||||
else: form = temp[1]
|
||||
if form_validation and not form.charger.data:
|
||||
if form.exporter.data:
|
||||
flash("Ajout du référentielCompetence: {} ".format(form.code.data))
|
||||
|
@ -19,41 +19,52 @@
|
||||
|
||||
{% block formulaire %}{% endblock %}
|
||||
|
||||
<div class="field is-grouped">
|
||||
<div class="control">
|
||||
{{ form.sauvegarder(class="button")}}
|
||||
</div>
|
||||
<div class="control">
|
||||
{{ form.charger(class="button")}}
|
||||
</div>
|
||||
<div class="control">
|
||||
{{ form.exporter(class="button")}}
|
||||
</div>
|
||||
<div class="control">
|
||||
<div class="file has-name">
|
||||
<label class="file-label">
|
||||
{{ form.fichier(class="file-input") }}
|
||||
<span class="file-cta">
|
||||
<span class="file-icon">
|
||||
<i class="fas fa-file-import"></i>
|
||||
</span>
|
||||
<span class="file-label">
|
||||
{{ form.fichier.label}}
|
||||
</span>
|
||||
</span>
|
||||
{{ form.importer(class="button file-name", accept=".yml")}}
|
||||
</label>
|
||||
</div>
|
||||
{% for error in form.fichier.errors %}
|
||||
<p class="help is-danger">{{error}}</p>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="field is-grouped">
|
||||
<div class="control">
|
||||
{{ form.sauvegarder(class="button")}}
|
||||
</div>
|
||||
<ul>
|
||||
{% for referentiel in form.referentiel %}
|
||||
<li>{{ referentiel }} {{ referentiel.data.code }} - {% if referentiel.data.nom == None or referentiel.data.titre == None %}/!\ Référentiel à compléter /!\{% else %}{{ referentiel.data.nom }}{{ referentiel.data.titre }}{% endif %}</li>
|
||||
<div class="control">
|
||||
{{ form.charger(class="button")}}
|
||||
</div>
|
||||
<div class="control">
|
||||
{{ form.exporter(class="button")}}
|
||||
</div>
|
||||
<div class="control">
|
||||
<div class="file has-name">
|
||||
<label class="file-label">
|
||||
{{ form.fichier(class="file-input") }}
|
||||
<span class="file-cta">
|
||||
<span class="file-icon">
|
||||
<i class="fas fa-file-import"></i>
|
||||
</span>
|
||||
<span class="file-label">
|
||||
{{ form.fichier.label }}
|
||||
</span>
|
||||
</span>
|
||||
{{ form.importer(class="button file-name") }}
|
||||
</label>
|
||||
</div>
|
||||
{% for error in form.fichier.errors %}
|
||||
<p class="help is-danger">{{error}}</p>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
{% for error in form.charger.errors %}
|
||||
<p class="help is-danger">{{error}}</p>
|
||||
{% endfor %}
|
||||
{% if form.referentiel.choices|length != 0 %}
|
||||
<ul>
|
||||
{% for referentiel in form.referentiel %}
|
||||
<li>{{ referentiel }} {{ referentiel.data.code }} - {% if referentiel.data.nom == None or referentiel.data.titre == None %}/!\ Référentiel à compléter /!\{% else %}{{ referentiel.data.nom }}{{ referentiel.data.titre }}{% endif %}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<div class="control">
|
||||
{{ form.supprimer(class="button is-danger") }}
|
||||
{% for error in form.supprimer.errors %}
|
||||
<p class="help is-danger">{{error}}</p>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</form>
|
||||
{% endblock %}
|
Loading…
Reference in New Issue
Block a user