EditionPN/app/models.py

206 lines
8.7 KiB
Python
Raw Permalink Normal View History

2021-05-06 10:26:28 +02:00
from app import db
2021-06-01 19:31:24 +02:00
Semestres_Competences = db.Table("Semestres_Competences",
2021-06-11 14:34:43 +02:00
db.Column("Semestre_num", db.String(32), db.ForeignKey("semestre.num")),
db.Column("Competence_code", db.String(32), db.ForeignKey("competence.code"))
2021-06-01 19:31:24 +02:00
)
ACs_Competences = db.Table("ACs_Competences",
2021-06-11 14:34:43 +02:00
db.Column("AC_code", db.String(32), db.ForeignKey("AC.code")),
db.Column("Competence_code", db.String(32), db.ForeignKey("competence.code"))
2021-06-01 19:31:24 +02:00
)
2021-05-07 14:27:06 +02:00
Ressources_ACs = db.Table("Ressources_ACs",
2021-06-11 14:34:43 +02:00
db.Column("Ressource_code", db.String(32), db.ForeignKey("ressource.code")),
db.Column("AC_code", db.String(32), db.ForeignKey("AC.code"))
2021-05-07 14:27:06 +02:00
)
Ressources_SAEs = db.Table("Ressources_SAEs",
2021-06-11 14:34:43 +02:00
db.Column("Ressource_code", db.String(32), db.ForeignKey("ressource.code")),
db.Column("SAE_code", db.String(32), db.ForeignKey("SAE.code"))
2021-05-07 14:27:06 +02:00
)
SAEs_ACs = db.Table("SAEs_ACs",
2021-06-11 14:34:43 +02:00
db.Column("SAE_code", db.String(32), db.ForeignKey("SAE.code")),
db.Column("AC_code", db.String(32), db.ForeignKey("AC.code"))
2021-05-07 14:27:06 +02:00
)
2021-06-01 19:31:24 +02:00
class Semestre(db.Model):
num = db.Column(db.String(1), primary_key = True)
ues = db.relationship("Competence", order_by="Competence.code", secondary=Semestres_Competences, lazy=False, backref=db.backref("semestres", lazy=False))
2021-05-06 10:26:28 +02:00
2021-06-09 12:19:14 +02:00
def export(self):
result = dict(self.__dict__)
result.pop("_sa_instance_state", None)
return result
2021-05-06 10:26:28 +02:00
def __repr__(self):
2021-06-01 19:31:24 +02:00
return "<Semestre {}>".format(self.num)
class Competence(db.Model):
2021-06-11 14:34:43 +02:00
code = db.Column(db.String(32), primary_key = True, info={'label': 'Code'})
2021-06-01 19:31:24 +02:00
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'})
composantes = db.Column(db.Text(), info={'label': 'Composantes'})
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))
2021-06-09 10:21:19 +02:00
2021-06-10 17:05:57 +02:00
def updateCoefSAE(self, saes, query, coef=0):
2021-06-09 10:21:19 +02:00
listeSAE = [coefsae.sae for coefsae in self.saes]
for sae in saes:
2021-06-10 17:05:57 +02:00
if sae in query:
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))
2021-06-09 10:21:19 +02:00
for sae in listeSAE:
db.session.delete(CoefSAE.query.filter_by(sae=sae, competence=self).first())
2021-06-10 17:05:57 +02:00
db.session.commit()
2021-06-09 10:21:19 +02:00
2021-06-10 17:05:57 +02:00
def updateCoefRessource(self, ressources, query, coef=0):
2021-06-09 10:21:19 +02:00
listeRessource = [coefressource.ressource for coefressource in self.ressources]
for ressource in ressources:
2021-06-10 17:05:57 +02:00
if ressource in query:
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))
2021-06-09 10:21:19 +02:00
for ressource in listeRessource:
db.session.delete(CoefRessource.query.filter_by(ressource=ressource, competence=self).first())
2021-06-10 17:05:57 +02:00
db.session.commit()
2021-06-01 19:31:24 +02:00
2021-06-09 12:19:14 +02:00
def export(self):
result = dict(self.__dict__)
result.pop("_sa_instance_state", None)
return result
2021-06-01 19:31:24 +02:00
def getLabel(self):
return self.code + " - " + self.nom
def __repr__(self):
return "<Competence {}>".format(self.code)
2021-06-09 10:21:19 +02:00
class CoefSAE(db.Model):
2021-06-11 14:34:43 +02:00
competence_code = db.Column(db.String(32), db.ForeignKey("competence.code"), primary_key=True)
sae_code = db.Column(db.String(32), db.ForeignKey("SAE.code"), primary_key=True)
2021-06-09 10:21:19 +02:00
coef = db.Column(db.String(2))
2021-06-15 12:07:27 +02:00
competence = db.relationship("Competence", lazy=False, backref=db.backref("saes", cascade="save-update, merge, delete, delete-orphan"))
sae = db.relationship("SAE", lazy=False, backref=db.backref("competences", cascade="save-update, merge, delete, delete-orphan"))
2021-06-09 10:21:19 +02:00
2021-06-09 12:19:14 +02:00
def export(self):
result = dict(self.__dict__)
result.pop("_sa_instance_state", None)
return result
2021-06-09 10:21:19 +02:00
class CoefRessource(db.Model):
2021-06-11 14:34:43 +02:00
competence_code = db.Column(db.String(32), db.ForeignKey("competence.code"), primary_key=True)
ressource_code = db.Column(db.String(32), db.ForeignKey("ressource.code"), primary_key=True)
2021-06-09 10:21:19 +02:00
coef = db.Column(db.String(2))
2021-06-15 12:07:27 +02:00
competence = db.relationship("Competence", lazy=False, backref=db.backref("ressources", cascade="save-update, merge, delete, delete-orphan"))
ressource = db.relationship("Ressource", lazy=False, backref=db.backref("competences", cascade="save-update, merge, delete, delete-orphan"))
2021-06-09 10:21:19 +02:00
2021-06-09 12:19:14 +02:00
def export(self):
result = dict(self.__dict__)
result.pop("_sa_instance_state", None)
return result
class AC(db.Model):
2021-06-11 14:34:43 +02:00
code = db.Column(db.String(32), primary_key = True, info={'label': 'Code'})
2021-06-01 19:31:24 +02:00
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))
2021-06-09 10:21:19 +02:00
2021-06-09 12:19:14 +02:00
def export(self):
result = dict(self.__dict__)
result.pop("_sa_instance_state", None)
return result
2021-06-01 19:31:24 +02:00
def getLabel(self):
return self.code + " - " + self.titre
def __repr__(self):
return "<AC {}>".format(self.code)
2021-06-01 19:31:24 +02:00
class PN(db.Model):
2021-06-11 14:34:43 +02:00
code = db.Column(db.String(32), primary_key = True, info={'label': 'Code'})
2021-06-01 19:31:24 +02:00
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'})
2021-06-09 10:21:19 +02:00
type = db.Column(db.String(1))
2021-06-01 19:31:24 +02:00
2021-06-09 12:19:14 +02:00
def export(self):
result = dict(self.__dict__)
result.pop("_sa_instance_state", None)
return result
2021-06-01 19:31:24 +02:00
def __repr__(self):
return "<PN {}>".format(self.code)
class SAE(db.Model):
2021-06-11 14:34:43 +02:00
code = db.Column(db.String(32), primary_key = True, info={'label': 'Code'})
2021-06-01 19:31:24 +02:00
titre = db.Column(db.String(255), info={'label': 'Titre'})
semestre = db.Column(db.String(255), info={'label': 'Semestre'})
heures_encadrees = db.Column(db.String(3), info={'label': 'Heures Encadrées'})
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'})
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'})
2021-06-09 10:21:19 +02:00
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:]
2021-06-09 12:19:14 +02:00
def export(self):
result = dict(self.__dict__)
result.pop("_sa_instance_state", None)
return result
2021-06-01 19:31:24 +02:00
def getLabel(self):
return self.code + " - " + self.titre
def __repr__(self):
return "<SAE {}>".format(self.code)
class Ressource(db.Model):
2021-06-11 14:34:43 +02:00
code = db.Column(db.String(32), primary_key = True, info={'label': 'Code'})
2021-06-01 19:31:24 +02:00
nom = db.Column(db.String(255), info={'label': 'Nom'})
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'})
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'})
2021-06-09 10:21:19 +02:00
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:]
2021-06-09 12:19:14 +02:00
def export(self):
result = dict(self.__dict__)
result.pop("_sa_instance_state", None)
return result
2021-06-01 19:31:24 +02:00
def getLabel(self):
return self.code + " - " + self.nom
def __repr__(self):
return "<Ressource {}>".format(self.code)