diff --git a/README.md b/README.md index 2073093..0430159 100644 --- a/README.md +++ b/README.md @@ -9,4 +9,5 @@ ### Pour lancer l'app - flask run \ No newline at end of file + flask run + diff --git a/app.db b/app.db index a80baa8..c5fec63 100644 Binary files a/app.db and b/app.db differ diff --git a/app/forms.py b/app/forms.py index 8025ff2..bc909cb 100644 --- a/app/forms.py +++ b/app/forms.py @@ -38,11 +38,16 @@ class AccueilForm(FlaskForm): exporter = SubmitField("Exporter") importer = SubmitField("Importer") +class CoefForm(FlaskForm): + objetformation = HiddenField("Objet de formation") + coef = StringField("Coef") + class UEForm(FlaskForm): ue = HiddenField("Competence") acs = RefListField("Liste des ACs", query_factory=lambda: models.AC.query.all(), get_label=lambda ref: ref.getLabel()) ressources = RefListField("Liste des Ressources inclus dans les ACs", query_factory=lambda: [], get_label=lambda ref: ref.getLabel()) saes = RefListField("Liste des SAEs inclus dans les ACs", query_factory=lambda: [], get_label=lambda ref: ref.getLabel()) + coef = FieldList(FormField(CoefForm)) class SemestreForm(FlaskForm): ues = RefListField("Liste des UEs", query_factory=lambda: models.Competence.query.all(), get_label=lambda ref: ref.getLabel()) @@ -119,7 +124,7 @@ class Form(ModelForm): model = getattr(models, self.__class__.__name__[:-4]) referentiel = model.query.filter_by(code=self.code.data).first() if referentiel == None: referentiel = model() - self.populate_obj(referentiel) + self.populate_obj(referentiel) db.session.add(referentiel) db.session.commit() @@ -128,7 +133,8 @@ class PNForm(Form): class Meta: model = models.PN - type_map = ClassMap({ChoiceType: RadioField}) + + type = RadioField("Type", choices=["1","2","3"]) class ACForm(Form): diff --git a/app/models.py b/app/models.py index 9aa1c46..f3c0609 100644 --- a/app/models.py +++ b/app/models.py @@ -1,5 +1,4 @@ from app import db -from sqlalchemy_utils import ChoiceType Semestres_Competences = db.Table("Semestres_Competences", db.Column("Semestre_num", db.String(1), db.ForeignKey("semestre.num")), @@ -11,16 +10,6 @@ ACs_Competences = db.Table("ACs_Competences", db.Column("Competence_code", db.String(3), db.ForeignKey("competence.code")) ) -SAEs_Competences = db.Table("SAEs_Competences", - db.Column("SAE_code", db.String(6), db.ForeignKey("SAE.code")), - db.Column("Competence_code", db.String(3), db.ForeignKey("competence.code")) -) - -Ressources_Competences = db.Table("Ressources_Competences", - db.Column("Ressource_code", db.String(6), db.ForeignKey("ressource.code")), - db.Column("Competence_code", db.String(3), db.ForeignKey("competence.code")) -) - Ressources_ACs = db.Table("Ressources_ACs", db.Column("Ressource_code", db.String(4), db.ForeignKey("ressource.code")), db.Column("AC_code", db.String(6), db.ForeignKey("AC.code")) @@ -52,9 +41,30 @@ class Competence(db.Model): situations = db.Column(db.Text(), info={'label': 'Situations'}) niveaux = db.Column(db.Text(), info={'label': 'Niveaux'}) acs = db.relationship("AC", order_by="AC.code", secondary=ACs_Competences, lazy=False, backref=db.backref("competences", lazy=False)) - #objets de formation - saes = db.relationship("SAE", secondary=SAEs_Competences, lazy=False, backref=db.backref("competences", lazy=False)) - ressources = db.relationship("Ressource", secondary=Ressources_Competences, lazy=False, backref=db.backref("competences", lazy=False)) + + def updateCoefSAE(self, saes, coef=0): + listeSAE = [coefsae.sae for coefsae in self.saes] + for sae in saes: + if sae in listeSAE: + CoefSAE.query.filter_by(sae=sae, competence=self).first().coef = coef + listeSAE.remove(sae) + else: + self.saes.append(CoefSAE(competence=self, sae=sae, coef=coef)) + for sae in listeSAE: + db.session.delete(CoefSAE.query.filter_by(sae=sae, competence=self).first()) + db.session.commit() + + def updateCoefRessource(self, ressources, coef=0): + listeRessource = [coefressource.ressource for coefressource in self.ressources] + for ressource in ressources: + if ressource in listeRessource: + CoefRessource.query.filter_by(ressource=ressource, competence=self).first().coef = coef + listeRessource.remove(ressource) + else: + self.ressources.append(CoefRessource(competence=self, ressource=ressource, coef=coef)) + for ressource in listeRessource: + db.session.delete(CoefRessource.query.filter_by(ressource=ressource, competence=self).first()) + db.session.commit() def getLabel(self): return self.code + " - " + self.nom @@ -62,12 +72,26 @@ class Competence(db.Model): def __repr__(self): return "".format(self.code) +class CoefSAE(db.Model): + competence_code = db.Column(db.String(3), db.ForeignKey("competence.code"), primary_key=True) + sae_code = db.Column(db.String(6), db.ForeignKey("SAE.code"), primary_key=True) + coef = db.Column(db.String(2)) + competence = db.relationship("Competence", lazy=False, backref=db.backref("saes")) + sae = db.relationship("SAE", lazy=False, backref=db.backref("competences")) + +class CoefRessource(db.Model): + competence_code = db.Column(db.String(3), db.ForeignKey("competence.code"), primary_key=True) + ressource_code = db.Column(db.String(4), db.ForeignKey("ressource.code"), primary_key=True) + coef = db.Column(db.String(2)) + competence = db.relationship("Competence", lazy=False, backref=db.backref("ressources")) + ressource = db.relationship("Ressource", lazy=False, backref=db.backref("competences")) + class AC(db.Model): code = db.Column(db.String(6), primary_key = True, info={'label': 'Code'}) titre = db.Column(db.String(255), info={'label': 'Titre'}) saes = db.relationship("SAE", secondary=SAEs_ACs, lazy=False, backref=db.backref("acs", lazy=False)) ressources = db.relationship("Ressource", order_by="Ressource.code", secondary=Ressources_ACs, lazy=False, backref=db.backref("acs", lazy=False)) - + def getLabel(self): return self.code + " - " + self.titre @@ -79,9 +103,7 @@ class PN(db.Model): nom = db.Column(db.String(255), info={'label': 'Nom'}) diminutif = db.Column(db.String(30), info={'label': 'Diminutif'}) description = db.Column(db.Text(), info={'label': 'Description'}) - - TYPES = [("1","1"),("2","2"),("3","3")] - type = db.Column(ChoiceType(TYPES)) + type = db.Column(db.String(1)) def __repr__(self): return "".format(self.code) @@ -94,11 +116,19 @@ class SAE(db.Model): heures_tp = db.Column(db.String(3), info={'label': 'Heures TP'}) projet = db.Column(db.String(3), info={'label': 'Projet'}) description = db.Column(db.Text(), info={'label': 'Description'}) - coef = db.Column(db.String(255), info={'label': 'Coef.'}) ressources = db.relationship("Ressource", order_by="Ressource.code", secondary=Ressources_SAEs, lazy=False, backref=db.backref("saes", lazy=False)) livrables = db.Column(db.Text(), info={'label': 'Livrables'}) motscles = db.Column(db.String(255), info={'label': 'Mots Clés'}) + def getCoef(self,competence): + return CoefSAE.query.filter_by(sae=self, competence=competence).first().coef + + def setCoef(self,coef,competence): + CoefSAE.query.filter_by(sae=self, competence=competence).first().coef = coef + + def getCode(self): + return self.code[3:] + def getLabel(self): return self.code + " - " + self.titre @@ -111,12 +141,20 @@ class Ressource(db.Model): semestre = db.Column(db.String(255), info={'label': 'Semestre'}) heures_formation = db.Column(db.String(3), info={'label': 'Heures Formation'}) heures_tp = db.Column(db.String(3), info={'label': 'Heures TP'}) - coef = db.Column(db.String(255), info={'label': 'Coef.'}) prerequis = db.Column(db.String(255), info={'label': 'Prerequis'}) contexte = db.Column(db.Text(), info={'label': 'Contexte'}) contenu = db.Column(db.Text(), info={'label': 'Contenu'}) motscles = db.Column(db.String(255), info={'label': 'Mots Clés'}) + def getCoef(self,competence): + return CoefRessource.query.filter_by(ressource=self, competence=competence).first().coef + + def setCoef(self,coef,competence): + CoefRessource.query.filter_by(ressource=self, competence=competence).first().coef = coef + + def getCode(self): + return self.code[1:] + def getLabel(self): return self.code + " - " + self.nom diff --git a/app/routes.py b/app/routes.py index 022d01c..e2974f0 100644 --- a/app/routes.py +++ b/app/routes.py @@ -37,24 +37,35 @@ def Semestre(num): if ressource not in queryRessource: queryRessource.append(ressource) form.ueform.__getitem__(i).saes.query=querySAE form.ueform.__getitem__(i).ressources.query=queryRessource + if not form.update.data: + for coefsae in ue.saes: + form.ueform.__getitem__(i).coef.append_entry(data={"objetformation": coefsae.sae}) + for coefressource in ue.ressources: + form.ueform.__getitem__(i).coef.append_entry(data={"objetformation": coefressource.ressource}) # Appuie sur Update if form.update.data: semestre.ues = [ue for ue in form.ues.data] + form.validate_on_submit() for i, field in enumerate(form.ueform): ue = models.Competence.query.filter_by(code=field.ue.data).first() ue.acs = field.acs.data - ue.saes = field.saes.data - ue.ressources = field.ressources.data + ue.updateCoefSAE(field.saes.data) + ue.updateCoefRessource(field.ressources.data) + for coeffield in field.coef: + codeClass, code = coeffield.objetformation.data[1:-1].split() + model = getattr(models, codeClass) + model.query.filter_by(code=code).first().setCoef(coeffield.coef.data, ue) db.session.commit() return redirect(url_for("Semestre", num=num)) - # Coche les référentiels que l'ue possède + # Remplis les fields des informations que l'ue possède for i, ue in enumerate(semestre.ues): form.ueform.__getitem__(i).acs.process_data(ue.acs) - form.ueform.__getitem__(i).saes.process_data(ue.saes) - form.ueform.__getitem__(i).ressources.process_data(ue.ressources) + form.ueform.__getitem__(i).saes.process_data([coefsae.sae for coefsae in ue.saes]) + form.ueform.__getitem__(i).ressources.process_data([coefressource.ressource for coefressource in ue.ressources]) + for field in form.ueform.__getitem__(i).coef: + field.coef.process_data(field.objetformation.data.getCoef(ue)) # Coche les ues que le semestre possède - form.ues.process_data(semestre.ues) - + form.ues.process_data(semestre.ues) return render_template("semestre.html", semestre=semestre, form=form) @app.route("/PN", defaults={"code":None}, methods=["GET","POST"]) @@ -168,7 +179,7 @@ def Competence(code): elif form.importer.data: form.importerRef() elif form.supprimer.data: - if form.supprimerRef(): return redirect(url_for("Compentence")) + if form.supprimerRef(): return redirect(url_for("Competence")) elif form.validate_on_submit() and not form.charger.data: if form.exporter.data: flash("Export du référentielCompetence: {} ".format(form.code.data)) diff --git a/app/templates/Ressource.html b/app/templates/Ressource.html index 4516d22..276ebd2 100644 --- a/app/templates/Ressource.html +++ b/app/templates/Ressource.html @@ -10,7 +10,6 @@ {{ render_field(form.semestre,"input") }} {{ render_field(form.heures_formation,"input") }} {{ render_field(form.heures_tp,"input") }} -{{ render_field(form.coef,"input") }} {{ render_list(form.acs) }}
{{ render_dropdown(form.acs) }}
{{ render_list(form.saes) }} diff --git a/app/templates/SAE.html b/app/templates/SAE.html index 75961ef..71b9709 100644 --- a/app/templates/SAE.html +++ b/app/templates/SAE.html @@ -12,7 +12,6 @@ {{ render_field(form.heures_tp,"input") }} {{ render_field(form.projet,"input") }} {{ render_field(form.description,"textarea") }} -{{ render_field(form.coef,"input") }} {{ render_list(form.acs) }}
{{ render_dropdown(form.acs) }}
{{ render_list(form.ressources) }} diff --git a/app/templates/semestre.html b/app/templates/semestre.html index afedc2b..eddd116 100644 --- a/app/templates/semestre.html +++ b/app/templates/semestre.html @@ -16,18 +16,28 @@ {{ form.ueform.__getitem__(loop.index0).ue }} {{ render_dropdown(form.ueform.__getitem__(loop.index0).acs) }} -

Objets de formation

-