Ajout des coefs

This commit is contained in:
Éric Li 2021-06-09 10:21:19 +02:00
parent 4e9c35b9e6
commit 095a25b59c
12 changed files with 147 additions and 159 deletions

View File

@ -9,4 +9,5 @@
### Pour lancer l'app
flask run
flask run

BIN
app.db

Binary file not shown.

View File

@ -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):

View File

@ -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 "<Competence {}>".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 "<PN {}>".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

View File

@ -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))

View File

@ -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) }}
<div class="field">{{ render_dropdown(form.acs) }}</div>
{{ render_list(form.saes) }}

View File

@ -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) }}
<div class="field">{{ render_dropdown(form.acs) }}</div>
{{ render_list(form.ressources) }}

View File

@ -16,18 +16,28 @@
</ul>
{{ form.ueform.__getitem__(loop.index0).ue }}
{{ render_dropdown(form.ueform.__getitem__(loop.index0).acs) }}
<p>Objets de formation</p>
<ul>
{% for sae in competence.saes %}
<li><a style="color: inherit;" href="{{ url_for('SAE', code=sae.code[3:]) }}"><span class="tag is-info">{{ sae.code }}</span> - {{ sae.titre }} <i class="far fa-edit fa-sm"></i></a></li>
{% endfor %}
<!-- Affichage des objets de formations contenu dans l'UE avec modification du coef -->
<h1 class="title is-5">Objets de formation</h1>
<ul style="list-style-type: none">
{% for coefForm in form.ueform.__getitem__(loop.index0).coef %}
<li>
<div class="field is-horizontal">
<div class="field-body">
<div class="field">
<p class="control">
{{ coefForm.objetformation }}
<a class="button" href="{{ url_for(coefForm.objetformation.data.__repr__()[1:-1].split()[0], code=coefForm.objetformation.data.getCode()) }}">{{ coefForm.objetformation.data.getLabel() }}<i class="far fa-edit fa-sm"></i></a>
</p>
</div>
<div class="field">
{{ coefForm.coef(class="input is-pulled-right",style="width: 2em") }}
</div>
</div>
</div>
</li>
{% endfor %}
</ul>
{{ render_dropdown(form.ueform.__getitem__(loop.index0).saes) }}
<ul>
{% for ressource in competence.ressources %}
<li><a style="color: inherit;" href="{{ url_for('Ressource', code=ressource.code[1:]) }}"><span class="tag is-info">{{ ressource.code }}</span> - {{ ressource.nom }} <i class="far fa-edit fa-sm"></i></a></li>
{% endfor %}
</ul>
{{ render_dropdown(form.ueform.__getitem__(loop.index0).ressources) }}
{% endfor %}
</div>

View File

@ -1,38 +0,0 @@
"""empty message
Revision ID: 03ec797adcc8
Revises: 15feabeae315
Create Date: 2021-05-12 12:41:11.703242
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '03ec797adcc8'
down_revision = '15feabeae315'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('semestre',
sa.Column('num', sa.String(length=1), nullable=False),
sa.PrimaryKeyConstraint('num')
)
op.create_table('Semestres_Competences',
sa.Column('Semestre_num', sa.String(length=1), nullable=True),
sa.Column('Competence_code', sa.String(length=3), nullable=True),
sa.ForeignKeyConstraint(['Competence_code'], ['competence.code'], ),
sa.ForeignKeyConstraint(['Semestre_num'], ['semestre.num'], )
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('Semestres_Competences')
op.drop_table('semestre')
# ### end Alembic commands ###

View File

@ -1,8 +1,8 @@
"""empty message
Revision ID: 15feabeae315
Revision ID: 7e3f15e7d9d0
Revises:
Create Date: 2021-05-07 16:45:01.928258
Create Date: 2021-06-03 18:25:50.167616
"""
from alembic import op
@ -10,7 +10,7 @@ import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '15feabeae315'
revision = '7e3f15e7d9d0'
down_revision = None
branch_labels = None
depends_on = None
@ -39,7 +39,6 @@ def upgrade():
sa.Column('heures_tp', sa.String(length=3), nullable=True),
sa.Column('projet', sa.String(length=3), nullable=True),
sa.Column('description', sa.Text(), nullable=True),
sa.Column('coef', sa.String(length=255), nullable=True),
sa.Column('livrables', sa.Text(), nullable=True),
sa.Column('motscles', sa.String(length=255), nullable=True),
sa.PrimaryKeyConstraint('code')
@ -60,13 +59,22 @@ def upgrade():
sa.Column('semestre', sa.String(length=255), nullable=True),
sa.Column('heures_formation', sa.String(length=3), nullable=True),
sa.Column('heures_tp', sa.String(length=3), nullable=True),
sa.Column('coef', sa.String(length=255), nullable=True),
sa.Column('prerequis', sa.String(length=255), nullable=True),
sa.Column('contexte', sa.Text(), nullable=True),
sa.Column('contenu', sa.Text(), nullable=True),
sa.Column('motscles', sa.String(length=255), nullable=True),
sa.PrimaryKeyConstraint('code')
)
op.create_table('semestre',
sa.Column('num', sa.String(length=1), nullable=False),
sa.PrimaryKeyConstraint('num')
)
op.create_table('ACs_Competences',
sa.Column('AC_code', sa.String(length=6), nullable=True),
sa.Column('Competence_code', sa.String(length=3), nullable=True),
sa.ForeignKeyConstraint(['AC_code'], ['AC.code'], ),
sa.ForeignKeyConstraint(['Competence_code'], ['competence.code'], )
)
op.create_table('Ressources_ACs',
sa.Column('Ressource_code', sa.String(length=4), nullable=True),
sa.Column('AC_code', sa.String(length=6), nullable=True),
@ -85,14 +93,41 @@ def upgrade():
sa.ForeignKeyConstraint(['AC_code'], ['AC.code'], ),
sa.ForeignKeyConstraint(['SAE_code'], ['SAE.code'], )
)
op.create_table('Semestres_Competences',
sa.Column('Semestre_num', sa.String(length=1), nullable=True),
sa.Column('Competence_code', sa.String(length=3), nullable=True),
sa.ForeignKeyConstraint(['Competence_code'], ['competence.code'], ),
sa.ForeignKeyConstraint(['Semestre_num'], ['semestre.num'], )
)
op.create_table('coefSAE',
sa.Column('competence_code', sa.String(length=3), nullable=False),
sa.Column('sae_code', sa.String(length=6), nullable=False),
sa.Column('coef', sa.String(length=2), nullable=True),
sa.ForeignKeyConstraint(['competence_code'], ['competence.code'], ),
sa.ForeignKeyConstraint(['sae_code'], ['SAE.code'], ),
sa.PrimaryKeyConstraint('competence_code', 'sae_code')
)
op.create_table('coef_ressource',
sa.Column('competence_code', sa.String(length=3), nullable=False),
sa.Column('ressource_code', sa.String(length=4), nullable=False),
sa.Column('coef', sa.String(length=2), nullable=True),
sa.ForeignKeyConstraint(['competence_code'], ['competence.code'], ),
sa.ForeignKeyConstraint(['ressource_code'], ['ressource.code'], ),
sa.PrimaryKeyConstraint('competence_code', 'ressource_code')
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('coef_ressource')
op.drop_table('coefSAE')
op.drop_table('Semestres_Competences')
op.drop_table('SAEs_ACs')
op.drop_table('Ressources_SAEs')
op.drop_table('Ressources_ACs')
op.drop_table('ACs_Competences')
op.drop_table('semestre')
op.drop_table('ressource')
op.drop_table('competence')
op.drop_table('SAE')

View File

@ -1,40 +0,0 @@
"""empty message
Revision ID: 8b0862eb0856
Revises: cff96c022884
Create Date: 2021-06-01 18:50:16.604312
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '8b0862eb0856'
down_revision = 'cff96c022884'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('Ressources_Competences',
sa.Column('Ressource_code', sa.String(length=6), nullable=True),
sa.Column('Competence_code', sa.String(length=3), nullable=True),
sa.ForeignKeyConstraint(['Competence_code'], ['competence.code'], ),
sa.ForeignKeyConstraint(['Ressource_code'], ['ressource.code'], )
)
op.create_table('SAEs_Competences',
sa.Column('SAE_code', sa.String(length=6), nullable=True),
sa.Column('Competence_code', sa.String(length=3), nullable=True),
sa.ForeignKeyConstraint(['Competence_code'], ['competence.code'], ),
sa.ForeignKeyConstraint(['SAE_code'], ['SAE.code'], )
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('SAEs_Competences')
op.drop_table('Ressources_Competences')
# ### end Alembic commands ###

View File

@ -1,33 +0,0 @@
"""empty message
Revision ID: cff96c022884
Revises: 03ec797adcc8
Create Date: 2021-05-13 15:30:50.203249
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'cff96c022884'
down_revision = '03ec797adcc8'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('ACs_Competences',
sa.Column('AC_code', sa.String(length=6), nullable=True),
sa.Column('Competence_code', sa.String(length=3), nullable=True),
sa.ForeignKeyConstraint(['AC_code'], ['AC.code'], ),
sa.ForeignKeyConstraint(['Competence_code'], ['competence.code'], )
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('ACs_Competences')
# ### end Alembic commands ###