Compare commits

...

2 Commits

Author SHA1 Message Date
Éric Li 328ce76bb1 gitignore 2021-06-09 20:17:37 +02:00
Éric Li e8eb8242f7 factorisation 2021-06-09 12:48:24 +02:00
6 changed files with 16 additions and 18 deletions

2
.gitignore vendored
View File

@ -3,4 +3,4 @@ migrations/__pycache__/
migrations/versions/__pycache__/ migrations/versions/__pycache__/
export/ export/
app/__pycache__/ app/__pycache__/
app.db

View File

@ -11,3 +11,7 @@
flask run flask run
### Pour initialiser la BDD
flask db migrate

BIN
app.db

Binary file not shown.

View File

@ -1,11 +1,9 @@
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, SelectMultipleField, widgets, FieldList, FormField, HiddenField from wtforms import StringField, SubmitField, FileField, RadioField, widgets, FieldList, FormField, HiddenField
from wtforms.validators import DataRequired, Regexp, Optional, ValidationError from wtforms.validators import DataRequired, Optional
from wtforms_alchemy import model_form_factory, ClassMap from wtforms_alchemy import model_form_factory, ClassMap
from wtforms_alchemy.fields import QuerySelectMultipleField from wtforms_alchemy.fields import QuerySelectMultipleField
from sqlalchemy_utils import ChoiceType
from app import db from app import db
import app.models as models import app.models as models
@ -49,27 +47,26 @@ class AccueilForm(FlaskForm):
importerJSON = SubmitField("ImporterJSON") importerJSON = SubmitField("ImporterJSON")
importerYAML = SubmitField("ImporterYAML") importerYAML = SubmitField("ImporterYAML")
def exportJSON(self): def ListRef(self):
result = {"semestres": [], "competences": [], "acs": [], "pns": [], "saes": [], "coefsaes": [], "ressources": [], "coefressources": []} result = {"semestres": [], "competences": [], "acs": [], "pns": [], "saes": [], "coefsaes": [], "ressources": [], "coefressources": []}
for key in result.keys(): for key in result.keys():
model = getattr(models, categorie_to_model[key]) model = getattr(models, categorie_to_model[key])
for ref in model.query.all(): for ref in model.query.all():
result[key].append(ref.export()) result[key].append(ref.export())
return result
def exportJSON(self):
result = self.ListRef()
fichier = REPERTOIRE_EXPORT + "referentiels" + ".json" fichier = REPERTOIRE_EXPORT + "referentiels" + ".json"
with open(fichier, "w", encoding="utf8") as fid: with open(fichier, "w", encoding="utf8") as fid:
json.dump(result, fid, cls=CustomEncoder, indent=4) json.dump(result, fid, cls=CustomEncoder, indent=4)
def exportYAML(self): def exportYAML(self):
result = {"semestres": [], "competences": [], "acs": [], "pns": [], "saes": [], "coefsaes": [], "ressources": [], "coefressources": []} result = self.ListRef()
for key in result.keys():
model = getattr(models, categorie_to_model[key])
for ref in model.query.all():
result[key].append(ref.export())
fichier = REPERTOIRE_EXPORT + "referentiels" + ".yml" fichier = REPERTOIRE_EXPORT + "referentiels" + ".yml"
with open(fichier, "w", encoding="utf8") as fid: with open(fichier, "w", encoding="utf8") as fid:
yaml.dump(yaml.safe_load(json.dumps(result, cls=CustomEncoder)), fid, indent=4) yaml.dump(yaml.safe_load(json.dumps(result, cls=CustomEncoder)), fid, indent=4)
class CoefForm(FlaskForm): class CoefForm(FlaskForm):
objetformation = HiddenField("Objet de formation") objetformation = HiddenField("Objet de formation")
coef = StringField("Coef") coef = StringField("Coef")
@ -138,7 +135,6 @@ class Form(ModelForm):
fichier = REPERTOIRE_EXPORT + self.code.data + ".yml" fichier = REPERTOIRE_EXPORT + self.code.data + ".yml"
with open(fichier, "w", encoding="utf8") as fid: with open(fichier, "w", encoding="utf8") as fid:
fid.write(yaml.dump(output)) fid.write(yaml.dump(output))
print(yaml.dump(output))
def supprimerRef(self): def supprimerRef(self):
if self.referentiel.data == None: if self.referentiel.data == None:
@ -168,7 +164,6 @@ class PNForm(Form):
type = RadioField("Type", choices=["1","2","3"]) type = RadioField("Type", choices=["1","2","3"])
class ACForm(Form): class ACForm(Form):
regex = "^AC\d{4}$" regex = "^AC\d{4}$"

View File

@ -1,4 +1,4 @@
from flask import render_template, flash, redirect, url_for, request from flask import render_template, flash, redirect, url_for
from app import app, db from app import app, db
from app.forms import * from app.forms import *
import app.models as models import app.models as models

View File

@ -1,7 +1,6 @@
from app import app, db from app import app, db
from app.models import PN from app.models import *
@app.shell_context_processor @app.shell_context_processor
def make_shell_context(): def make_shell_context():
return {"db": db, "PN": PN} return {"db": db}