forked from eric.li/EditionPN
Ajout de supprimer
This commit is contained in:
parent
3c18b88f2e
commit
0d804af5a1
21
app/forms.py
21
app/forms.py
@ -1,3 +1,4 @@
|
|||||||
|
from flask import redirect, url_for
|
||||||
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
|
||||||
@ -25,6 +26,7 @@ class Form(FlaskForm):
|
|||||||
|
|
||||||
sauvegarder = SubmitField("Sauvegarder")
|
sauvegarder = SubmitField("Sauvegarder")
|
||||||
charger = SubmitField("Charger")
|
charger = SubmitField("Charger")
|
||||||
|
supprimer = SubmitField("Supprimer")
|
||||||
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")
|
||||||
@ -114,7 +116,7 @@ def form_import(form):
|
|||||||
def form_export(form):
|
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())[6:-1]:
|
for categorie, valeur in list(form.data.items())[7:-1]:
|
||||||
if categorie in categorie_liste:
|
if categorie in categorie_liste:
|
||||||
output[categorie] = [ referentiel for referentiel in valeur.split(separateur) ]
|
output[categorie] = [ referentiel for referentiel in valeur.split(separateur) ]
|
||||||
else:
|
else:
|
||||||
@ -148,7 +150,7 @@ def form_sauvegarder(form):
|
|||||||
if referentiel == None:
|
if referentiel == None:
|
||||||
referentiel = model()
|
referentiel = model()
|
||||||
# Si le référentiel contient une catégorie avec une liste de référentiels
|
# 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:
|
if categorie in categorie_liste:
|
||||||
resultat = []
|
resultat = []
|
||||||
refs = [ ref for ref in form[categorie].data.split(separateur) ]
|
refs = [ ref for ref in form[categorie].data.split(separateur) ]
|
||||||
@ -165,4 +167,17 @@ def form_sauvegarder(form):
|
|||||||
|
|
||||||
form.populate_obj(referentiel)
|
form.populate_obj(referentiel)
|
||||||
db.session.add(referentiel)
|
db.session.add(referentiel)
|
||||||
db.session.commit()
|
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_validation = form.validate_on_submit()
|
||||||
form = form_import(form)
|
form = form_import(form)
|
||||||
form = form_charger(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_validation and not form.charger.data:
|
||||||
if form.exporter.data:
|
if form.exporter.data:
|
||||||
flash("Ajout du référentiel PN: {} ".format(form.code.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_validation = form.validate_on_submit()
|
||||||
form = form_import(form)
|
form = form_import(form)
|
||||||
form = form_charger(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_validation and not form.charger.data:
|
||||||
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))
|
||||||
@ -47,6 +53,9 @@ def SAE():
|
|||||||
form_validation = form.validate_on_submit()
|
form_validation = form.validate_on_submit()
|
||||||
form = form_import(form)
|
form = form_import(form)
|
||||||
form = form_charger(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_validation and not form.charger.data:
|
||||||
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))
|
||||||
@ -62,6 +71,9 @@ def Ressource():
|
|||||||
form_validation = form.validate_on_submit()
|
form_validation = form.validate_on_submit()
|
||||||
form = form_import(form)
|
form = form_import(form)
|
||||||
form = form_charger(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_validation and not form.charger.data:
|
||||||
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))
|
||||||
@ -77,6 +89,9 @@ def Competence():
|
|||||||
form_validation = form.validate_on_submit()
|
form_validation = form.validate_on_submit()
|
||||||
form = form_import(form)
|
form = form_import(form)
|
||||||
form = form_charger(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_validation and not form.charger.data:
|
||||||
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))
|
||||||
|
@ -19,41 +19,52 @@
|
|||||||
|
|
||||||
{% block formulaire %}{% endblock %}
|
{% block formulaire %}{% endblock %}
|
||||||
|
|
||||||
<div class="field is-grouped">
|
<div class="field is-grouped">
|
||||||
<div class="control">
|
<div class="control">
|
||||||
{{ form.sauvegarder(class="button")}}
|
{{ 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>
|
</div>
|
||||||
<ul>
|
<div class="control">
|
||||||
{% for referentiel in form.referentiel %}
|
{{ form.charger(class="button")}}
|
||||||
<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>
|
||||||
|
<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 %}
|
{% 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>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
{% endblock %}
|
{% endblock %}
|
Loading…
Reference in New Issue
Block a user