formules d'UE: affichage pour suppression

This commit is contained in:
Emmanuel Viennet 2022-02-01 17:42:43 +01:00
parent bb40532ca6
commit ce5e379d29
3 changed files with 40 additions and 92 deletions

View File

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

View File

@ -1152,30 +1152,19 @@ def formsemestre_tableau_modules(
f"""<tr class="formsemestre_status_ue"><td colspan="4">
<span class="status_ue_acro">{ue["acronyme"]}</span>
<span class="status_ue_title">{titre}</span>
</td><td>"""
</td><td colspan="2">"""
)
if can_edit:
H.append(
' <a href="edit_ue_expr?formsemestre_id=%s&ue_id=%s">'
% (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("</a>")
expr = sco_compute_moy.get_ue_expression(
formsemestre_id, ue["ue_id"], html_quote=True
)
if expr:
H.append(
""" <span class="formula" title="mode de calcul de la moyenne d'UE">%s</span>"""
% expr
f""" <span class="formula" title="mode de calcul de la moyenne d'UE">{expr}</span>
<span class="warning">formule inutilisée en 9.2: <a href="{
url_for("notes.delete_ue_expr", scodoc_dept=g.scodoc_dept, formsemestre_id=formsemestre_id, ue_id=ue["ue_id"] )
}
">supprimer</a></span>"""
)
H.append("</td></tr>")

View File

@ -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/<int:formsemestre_id>/<int:ue_id>", 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")