1
0
forked from ScoDoc/ScoDoc

Fix edition resp. modimpl. Une migration devra etre ajoutée plus tard.

This commit is contained in:
Emmanuel Viennet 2024-02-05 17:35:46 +01:00
parent bbdf5da2e8
commit 072d013590
3 changed files with 30 additions and 25 deletions

View File

@ -102,6 +102,8 @@ class User(UserMixin, ScoDocModel):
token = db.Column(db.Text(), index=True, unique=True) token = db.Column(db.Text(), index=True, unique=True)
token_expiration = db.Column(db.DateTime) token_expiration = db.Column(db.DateTime)
# Define the back reference from User to ModuleImpl
modimpls = db.relationship("ModuleImpl", back_populates="responsable")
roles = db.relationship("Role", secondary="user_role", viewonly=True) roles = db.relationship("Role", secondary="user_role", viewonly=True)
Permission = Permission Permission = Permission
@ -245,24 +247,26 @@ class User(UserMixin, ScoDocModel):
def to_dict(self, include_email=True): def to_dict(self, include_email=True):
"""l'utilisateur comme un dict, avec des champs supplémentaires""" """l'utilisateur comme un dict, avec des champs supplémentaires"""
data = { data = {
"date_expiration": self.date_expiration.isoformat() + "Z" "date_expiration": (
if self.date_expiration self.date_expiration.isoformat() + "Z" if self.date_expiration else None
else None, ),
"date_modif_passwd": self.date_modif_passwd.isoformat() + "Z" "date_modif_passwd": (
if self.date_modif_passwd self.date_modif_passwd.isoformat() + "Z"
else None, if self.date_modif_passwd
"date_created": self.date_created.isoformat() + "Z" else None
if self.date_created ),
else None, "date_created": (
self.date_created.isoformat() + "Z" if self.date_created else None
),
"dept": self.dept, "dept": self.dept,
"id": self.id, "id": self.id,
"active": self.active, "active": self.active,
"cas_id": self.cas_id, "cas_id": self.cas_id,
"cas_allow_login": self.cas_allow_login, "cas_allow_login": self.cas_allow_login,
"cas_allow_scodoc_login": self.cas_allow_scodoc_login, "cas_allow_scodoc_login": self.cas_allow_scodoc_login,
"cas_last_login": self.cas_last_login.isoformat() + "Z" "cas_last_login": (
if self.cas_last_login self.cas_last_login.isoformat() + "Z" if self.cas_last_login else None
else None, ),
"edt_id": self.edt_id, "edt_id": self.edt_id,
"status_txt": "actif" if self.active else "fermé", "status_txt": "actif" if self.active else "fermé",
"last_seen": self.last_seen.isoformat() + "Z" if self.last_seen else None, "last_seen": self.last_seen.isoformat() + "Z" if self.last_seen else None,

View File

@ -37,7 +37,10 @@ class ModuleImpl(ScoDocModel):
index=True, index=True,
nullable=False, nullable=False,
) )
responsable_id = db.Column("responsable_id", db.Integer, db.ForeignKey("user.id")) responsable_id = db.Column(
"responsable_id", db.Integer, db.ForeignKey("user.id", ondelete="SET NULL")
)
responsable = db.relationship("User", back_populates="modimpls")
# formule de calcul moyenne: # formule de calcul moyenne:
computation_expr = db.Column(db.Text()) computation_expr = db.Column(db.Text())
@ -54,6 +57,7 @@ class ModuleImpl(ScoDocModel):
lazy="dynamic", lazy="dynamic",
backref="moduleimpl", backref="moduleimpl",
) )
"enseignants du module (sans le responsable)"
def __repr__(self): def __repr__(self):
return f"<{self.__class__.__name__} {self.id} module={repr(self.module)}>" return f"<{self.__class__.__name__} {self.id} module={repr(self.module)}>"

View File

@ -539,9 +539,9 @@ def ue_sharing_code():
return sco_edit_ue.ue_sharing_code( return sco_edit_ue.ue_sharing_code(
ue_code=ue_code, ue_code=ue_code,
ue_id=None if ((ue_id is None) or ue_id == "") else int(ue_id), ue_id=None if ((ue_id is None) or ue_id == "") else int(ue_id),
hide_ue_id=None hide_ue_id=(
if ((hide_ue_id is None) or hide_ue_id == "") None if ((hide_ue_id is None) or hide_ue_id == "") else int(hide_ue_id)
else int(hide_ue_id), ),
) )
@ -1093,7 +1093,7 @@ def edit_moduleimpl_resp(moduleimpl_id: int):
modimpl.can_change_responsable(current_user, raise_exc=True) # access control modimpl.can_change_responsable(current_user, raise_exc=True) # access control
H = [ H = [
html_sco_header.html_sem_header( html_sco_header.html_sem_header(
f"""Modification du responsable du <a href="{ f"""Modification du responsable du <a class="stdlink" href="{
url_for("notes.moduleimpl_status", url_for("notes.moduleimpl_status",
scodoc_dept=g.scodoc_dept, moduleimpl_id=moduleimpl_id) scodoc_dept=g.scodoc_dept, moduleimpl_id=moduleimpl_id)
}">module {modimpl.module.titre or ""}</a>""", }">module {modimpl.module.titre or ""}</a>""",
@ -1156,8 +1156,8 @@ def edit_moduleimpl_resp(moduleimpl_id: int):
) )
) )
else: else:
responsable_id = User.get_user_from_nomplogin(tf[2]["responsable_id"]) responsable = User.get_user_from_nomplogin(tf[2]["responsable_id"])
if not responsable_id: if not responsable:
# presque impossible: tf verifie les valeurs (mais qui peuvent changer entre temps) # presque impossible: tf verifie les valeurs (mais qui peuvent changer entre temps)
return flask.redirect( return flask.redirect(
url_for( url_for(
@ -1167,7 +1167,7 @@ def edit_moduleimpl_resp(moduleimpl_id: int):
) )
) )
modimpl.responsable_id = responsable_id modimpl.responsable = responsable
db.session.add(modimpl) db.session.add(modimpl)
db.session.commit() db.session.commit()
flash("Responsable modifié") flash("Responsable modifié")
@ -1192,8 +1192,6 @@ def view_module_abs(moduleimpl_id, fmt="html"):
.filter_by(dept_id=g.scodoc_dept_id) .filter_by(dept_id=g.scodoc_dept_id)
).first_or_404() ).first_or_404()
debut_sem = modimpl.formsemestre.date_debut
fin_sem = modimpl.formsemestre.date_fin
inscrits: list[Identite] = sorted( inscrits: list[Identite] = sorted(
[i.etud for i in modimpl.inscriptions], key=lambda e: e.sort_key [i.etud for i in modimpl.inscriptions], key=lambda e: e.sort_key
) )
@ -1286,9 +1284,8 @@ def formsemestre_enseignants_list(formsemestre_id, fmt="html"):
""" """
formsemestre = FormSemestre.get_formsemestre(formsemestre_id) formsemestre = FormSemestre.get_formsemestre(formsemestre_id)
# resp. de modules et charges de TD # resp. de modules et charges de TD
sem_ens: dict[ # uid : { "mods" : liste des modimpls, ... }
int, list[ModuleImpl] sem_ens: dict[int, list[ModuleImpl]] = {}
] = {} # uid : { "mods" : liste des modimpls, ... }
modimpls = formsemestre.modimpls_sorted modimpls = formsemestre.modimpls_sorted
for modimpl in modimpls: for modimpl in modimpls:
if not modimpl.responsable_id in sem_ens: if not modimpl.responsable_id in sem_ens: