From ce5e379d29b65561755d255c80425b8f60865682 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Tue, 1 Feb 2022 17:42:43 +0100 Subject: [PATCH] formules d'UE: affichage pour suppression --- app/models/formsemestre.py | 13 +++- app/scodoc/sco_formsemestre_status.py | 23 ++----- app/views/notes.py | 96 ++++++--------------------- 3 files changed, 40 insertions(+), 92 deletions(-) diff --git a/app/models/formsemestre.py b/app/models/formsemestre.py index d059701ae..599fcda20 100644 --- a/app/models/formsemestre.py +++ b/app/models/formsemestre.py @@ -22,6 +22,7 @@ from app.models.etudiants import Identite from app.scodoc import sco_codes_parcours from app.scodoc import sco_preferences from app.scodoc.sco_vdi import ApoEtapeVDI +from app.scodoc.sco_permissions import Permission class FormSemestre(db.Model): @@ -177,6 +178,16 @@ class FormSemestre(db.Model): ) return modimpls + def can_be_edited_by(self, user): + """Vrai si user peut modifier ce semestre""" + if not user.has_permission(Permission.ScoImplement): # pas chef + if not self.resp_can_edit or user.id not in [ + resp.id for resp in self.responsables + ]: + return False + + return True + def est_courant(self) -> bool: """Vrai si la date actuelle (now) est dans le semestre (les dates de début et fin sont incluses) @@ -425,7 +436,7 @@ class FormSemestreUECoef(db.Model): class FormSemestreUEComputationExpr(db.Model): - """Formules utilisateurs pour calcul moyenne UE""" + """Formules utilisateurs pour calcul moyenne UE (désactivées en 9.2+).""" __tablename__ = "notes_formsemestre_ue_computation_expr" __table_args__ = (db.UniqueConstraint("formsemestre_id", "ue_id"),) diff --git a/app/scodoc/sco_formsemestre_status.py b/app/scodoc/sco_formsemestre_status.py index 97ac05dd6..1f440c8f2 100644 --- a/app/scodoc/sco_formsemestre_status.py +++ b/app/scodoc/sco_formsemestre_status.py @@ -1152,30 +1152,19 @@ def formsemestre_tableau_modules( f""" {ue["acronyme"]} {titre} - """ + """ ) - if can_edit: - H.append( - ' ' - % (formsemestre_id, ue["ue_id"]) - ) - H.append( - scu.icontag( - "formula", - title="Mode calcul moyenne d'UE", - style="vertical-align:middle", - ) - ) - if can_edit: - H.append("") expr = sco_compute_moy.get_ue_expression( formsemestre_id, ue["ue_id"], html_quote=True ) if expr: H.append( - """ %s""" - % expr + f""" {expr} + formule inutilisée en 9.2: supprimer""" ) H.append("") diff --git a/app/views/notes.py b/app/views/notes.py index b17036316..4b299ee52 100644 --- a/app/views/notes.py +++ b/app/views/notes.py @@ -30,23 +30,19 @@ Module notes: issu de ScoDoc7 / ZNotes.py Emmanuel Viennet, 2021 """ -import sys -import time -import datetime -import pprint + from operator import itemgetter from xml.etree import ElementTree import flask -from flask import url_for, jsonify, render_template +from flask import flash, jsonify, render_template, url_for from flask import current_app, g, request from flask_login import current_user from werkzeug.utils import redirect from app.models.formsemestre import FormSemestre +from app.models.formsemestre import FormSemestreUEComputationExpr from app.models.ues import UniteEns -from config import Config - from app import api from app import db from app import models @@ -1245,76 +1241,28 @@ def view_module_abs(moduleimpl_id, format="html"): return "\n".join(H) + tab.html() + html_sco_header.sco_footer() -@bp.route("/edit_ue_expr", methods=["GET", "POST"]) +@bp.route("/delete_ue_expr//", methods=["GET", "POST"]) @scodoc -@permission_required(Permission.ScoView) -@scodoc7func -def edit_ue_expr(formsemestre_id, ue_id): - """Edition formule calcul moyenne UE""" - # Check access - sem = sco_formsemestre_edit.can_edit_sem(formsemestre_id) - if not sem: +def delete_ue_expr(formsemestre_id: int, ue_id: int): + """Efface une expression de calcul d'UE""" + formsemestre = FormSemestre.query.get_or_404(formsemestre_id) + if not formsemestre.can_be_edited_by(current_user): raise AccessDenied("vous n'avez pas le droit d'effectuer cette opération") - cnx = ndb.GetDBConnexion() - # - ue = sco_edit_ue.ue_list({"ue_id": ue_id})[0] - H = [ - html_sco_header.html_sem_header( - "Modification règle de calcul de l'UE %s (%s)" - % (ue["acronyme"], ue["titre"]), - ), - _EXPR_HELP % {"target": "de l'UE", "objs": "modules", "ordre": ""}, - ] - el = sco_compute_moy.formsemestre_ue_computation_expr_list( - cnx, {"formsemestre_id": formsemestre_id, "ue_id": ue_id} - ) - if el: - initvalues = el[0] - else: - initvalues = {} - form = [ - ("ue_id", {"input_type": "hidden"}), - ("formsemestre_id", {"input_type": "hidden"}), - ( - "computation_expr", - { - "title": "Formule de calcul", - "input_type": "textarea", - "rows": 4, - "cols": 60, - "explanation": "formule de calcul (expérimental)", - }, - ), - ] - tf = TrivialFormulator( - request.base_url, - scu.get_request_args(), - form, - submitlabel="Modifier formule de calcul", - cancelbutton="Annuler", - initvalues=initvalues, - ) - if tf[0] == 0: - return "\n".join(H) + tf[1] + html_sco_header.sco_footer() - elif tf[0] == -1: - return flask.redirect( - "formsemestre_status?formsemestre_id=" + str(formsemestre_id) - ) - else: - if el: - el[0]["computation_expr"] = tf[2]["computation_expr"] - sco_compute_moy.formsemestre_ue_computation_expr_edit(cnx, el[0]) - else: - sco_compute_moy.formsemestre_ue_computation_expr_create(cnx, tf[2]) - - sco_cache.invalidate_formsemestre( - formsemestre_id=formsemestre_id - ) # > modif regle calcul - return flask.redirect( - "formsemestre_status?formsemestre_id=" - + str(formsemestre_id) - + "&head_message=règle%20de%20calcul%20modifiée" + expr = FormSemestreUEComputationExpr.query.filter_by( + formsemestre_id=formsemestre_id, ue_id=ue_id + ).first() + if expr is not None: + db.session.delete(expr) + db.session.commit() + flash("formule supprimée") + return flask.redirect( + url_for( + "notes.formsemestre_status", + scodoc_dept=g.scodoc_dept, + formsemestre_id=formsemestre_id, + head_message="formule supprimée", ) + ) @bp.route("/formsemestre_enseignants_list")