diff --git a/app/auth/models.py b/app/auth/models.py index 1278d9c05..ed29772f4 100644 --- a/app/auth/models.py +++ b/app/auth/models.py @@ -102,6 +102,8 @@ class User(UserMixin, ScoDocModel): token = db.Column(db.Text(), index=True, unique=True) 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) Permission = Permission @@ -245,24 +247,26 @@ class User(UserMixin, ScoDocModel): def to_dict(self, include_email=True): """l'utilisateur comme un dict, avec des champs supplémentaires""" data = { - "date_expiration": self.date_expiration.isoformat() + "Z" - if self.date_expiration - else None, - "date_modif_passwd": self.date_modif_passwd.isoformat() + "Z" - if self.date_modif_passwd - else None, - "date_created": self.date_created.isoformat() + "Z" - if self.date_created - else None, + "date_expiration": ( + self.date_expiration.isoformat() + "Z" if self.date_expiration else None + ), + "date_modif_passwd": ( + self.date_modif_passwd.isoformat() + "Z" + if self.date_modif_passwd + else None + ), + "date_created": ( + self.date_created.isoformat() + "Z" if self.date_created else None + ), "dept": self.dept, "id": self.id, "active": self.active, "cas_id": self.cas_id, "cas_allow_login": self.cas_allow_login, "cas_allow_scodoc_login": self.cas_allow_scodoc_login, - "cas_last_login": self.cas_last_login.isoformat() + "Z" - if self.cas_last_login - else None, + "cas_last_login": ( + self.cas_last_login.isoformat() + "Z" if self.cas_last_login else None + ), "edt_id": self.edt_id, "status_txt": "actif" if self.active else "fermé", "last_seen": self.last_seen.isoformat() + "Z" if self.last_seen else None, diff --git a/app/models/moduleimpls.py b/app/models/moduleimpls.py index 9d2c2b2c8..97dc82e32 100644 --- a/app/models/moduleimpls.py +++ b/app/models/moduleimpls.py @@ -37,7 +37,10 @@ class ModuleImpl(ScoDocModel): index=True, 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: computation_expr = db.Column(db.Text()) @@ -54,6 +57,7 @@ class ModuleImpl(ScoDocModel): lazy="dynamic", backref="moduleimpl", ) + "enseignants du module (sans le responsable)" def __repr__(self): return f"<{self.__class__.__name__} {self.id} module={repr(self.module)}>" diff --git a/app/views/notes.py b/app/views/notes.py index b8a5f9daa..77a92e7d0 100644 --- a/app/views/notes.py +++ b/app/views/notes.py @@ -539,9 +539,9 @@ def ue_sharing_code(): return sco_edit_ue.ue_sharing_code( ue_code=ue_code, ue_id=None if ((ue_id is None) or ue_id == "") else int(ue_id), - hide_ue_id=None - if ((hide_ue_id is None) or hide_ue_id == "") - else int(hide_ue_id), + hide_ue_id=( + None if ((hide_ue_id is None) or 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 H = [ html_sco_header.html_sem_header( - f"""Modification du responsable du module {modimpl.module.titre or ""}""", @@ -1156,8 +1156,8 @@ def edit_moduleimpl_resp(moduleimpl_id: int): ) ) else: - responsable_id = User.get_user_from_nomplogin(tf[2]["responsable_id"]) - if not responsable_id: + responsable = User.get_user_from_nomplogin(tf[2]["responsable_id"]) + if not responsable: # presque impossible: tf verifie les valeurs (mais qui peuvent changer entre temps) return flask.redirect( 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.commit() flash("Responsable modifié") @@ -1192,8 +1192,6 @@ def view_module_abs(moduleimpl_id, fmt="html"): .filter_by(dept_id=g.scodoc_dept_id) ).first_or_404() - debut_sem = modimpl.formsemestre.date_debut - fin_sem = modimpl.formsemestre.date_fin inscrits: list[Identite] = sorted( [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) # resp. de modules et charges de TD - sem_ens: dict[ - int, list[ModuleImpl] - ] = {} # uid : { "mods" : liste des modimpls, ... } + # uid : { "mods" : liste des modimpls, ... } + sem_ens: dict[int, list[ModuleImpl]] = {} modimpls = formsemestre.modimpls_sorted for modimpl in modimpls: if not modimpl.responsable_id in sem_ens: