petits bugs variés

This commit is contained in:
Emmanuel Viennet 2021-08-15 21:33:47 +02:00
parent 1b2813d7d2
commit 1d1513f782
8 changed files with 59 additions and 43 deletions

View File

@ -129,12 +129,6 @@ def permission_required(permission):
@wraps(f) @wraps(f)
def decorated_function(*args, **kwargs): def decorated_function(*args, **kwargs):
# current_app.logger.info("PERMISSION; kwargs=%s" % str(kwargs)) # current_app.logger.info("PERMISSION; kwargs=%s" % str(kwargs))
if "scodoc_dept" in kwargs:
g.scodoc_dept = kwargs["scodoc_dept"]
del kwargs["scodoc_dept"]
# current_app.logger.info(
# "permission_required: %s in %s" % (permission, g.scodoc_dept)
# )
scodoc_dept = getattr(g, "scodoc_dept", None) scodoc_dept = getattr(g, "scodoc_dept", None)
if not current_user.has_permission(permission, scodoc_dept): if not current_user.has_permission(permission, scodoc_dept):
abort(403) abort(403)
@ -153,7 +147,6 @@ def admin_required(f):
def scodoc7func(context): def scodoc7func(context):
"""Décorateur pour intégrer les fonctions Zope 2 de ScoDoc 7. """Décorateur pour intégrer les fonctions Zope 2 de ScoDoc 7.
Si on a un kwarg `scodoc_dept`(venant de la route), le stocke dans `g.scodoc_dept`.
Ajoute l'argument REQUEST s'il est dans la signature de la fonction. Ajoute l'argument REQUEST s'il est dans la signature de la fonction.
Les paramètres de la query string deviennent des (keywords) paramètres de la fonction. Les paramètres de la query string deviennent des (keywords) paramètres de la fonction.
""" """

View File

@ -161,10 +161,11 @@ def formsemestre_bulletinetud_dict(
if I["etud"]["inscription_formsemestre_id"]: if I["etud"]["inscription_formsemestre_id"]:
I[ I[
"descr_situation_html" "descr_situation_html"
] = """<a href="formsemestre_status?formsemestre_id=%s">%s</a>""" % ( ] = f"""<a href="{url_for(
I["etud"]["inscription_formsemestre_id"], "notes.formsemestre_status",
I["descr_situation"], scodoc_dept=g.scodoc_dept,
) formsemestre_id=I["etud"]["inscription_formsemestre_id"],
)}">{I["descr_situation"]}</a>"""
else: else:
I["descr_situation_html"] = I["descr_situation"] I["descr_situation_html"] = I["descr_situation"]
# Groupes: # Groupes:
@ -811,8 +812,11 @@ def formsemestre_bulletinetud(
H.append("""<p>Situation actuelle: """) H.append("""<p>Situation actuelle: """)
if etud["inscription_formsemestre_id"]: if etud["inscription_formsemestre_id"]:
H.append( H.append(
"""<a class="stdlink" href="formsemestre_status?formsemestre_id=%s">""" f"""<a class="stdlink" href="{url_for(
% etud["inscription_formsemestre_id"] "notes.formsemestre_status",
scodoc_dept=g.scodoc_dept,
formsemestre_id=etud["inscription_formsemestre_id"])
}">"""
) )
H.append(etud["inscriptionstr"]) H.append(etud["inscriptionstr"])
if etud["inscription_formsemestre_id"]: if etud["inscription_formsemestre_id"]:
@ -1054,8 +1058,11 @@ def _formsemestre_bulletinetud_header_html(
""" """
<form name="f" method="GET" action="%s">""" <form name="f" method="GET" action="%s">"""
% REQUEST.URL0, % REQUEST.URL0,
"""Bulletin <span class="bull_liensemestre"><a href="formsemestre_status?formsemestre_id=%(formsemestre_id)s"> f"""Bulletin <span class="bull_liensemestre"><a href="{
%(titremois)s</a></span> url_for("notes.formsemestre_status",
scodoc_dept=g.scodoc_dept,
formsemestre_id=sem["formsemestre_id"])}
">{sem["titremois"]}</a></span>
<br/>""" <br/>"""
% sem, % sem,
"""<table><tr>""", """<table><tr>""",

View File

@ -573,7 +573,7 @@ def _excel_to_list(filelike): # we may need 'encoding' argument ?
wb = load_workbook(filename=filelike, read_only=True, data_only=True) wb = load_workbook(filename=filelike, read_only=True, data_only=True)
except: except:
log("Excel_to_list: failure to import document") log("Excel_to_list: failure to import document")
open("/tmp/last_scodoc_import_failure" + scu.XLSX_SUFFIX, "w").write(filelike) open("/tmp/last_scodoc_import_failure" + scu.XLSX_SUFFIX, "wb").write(filelike)
raise ScoValueError( raise ScoValueError(
"Fichier illisible: assurez-vous qu'il s'agit bien d'un document Excel !" "Fichier illisible: assurez-vous qu'il s'agit bien d'un document Excel !"
) )

View File

@ -106,7 +106,7 @@ def search_etud_in_dept(context, expnom="", REQUEST=None):
Args: Args:
expnom: string, regexp sur le nom ou un code_nip ou un etudid expnom: string, regexp sur le nom ou un code_nip ou un etudid
""" """
if len(expnom) > 1: if isinstance(expnom, int) or len(expnom) > 1:
try: try:
etudid = int(expnom) etudid = int(expnom)
except ValueError: except ValueError:

View File

@ -221,7 +221,9 @@ def get_default_group(formsemestre_id, fix_if_missing=False):
] ]
except ScoException: except ScoException:
log("creating default partition for %s" % formsemestre_id) log("creating default partition for %s" % formsemestre_id)
partition_id = partition_create(context, formsemestre_id, default=True) partition_id = partition_create(
context, formsemestre_id, default=True, redirect=False
)
group_id = createGroup(context, partition_id, default=True) group_id = createGroup(context, partition_id, default=True)
return group_id return group_id
# debug check # debug check
@ -623,17 +625,15 @@ def change_etud_group_in_partition(
partition = get_partition(context, group["partition_id"]) partition = get_partition(context, group["partition_id"])
# 1- Supprime membership dans cette partition # 1- Supprime membership dans cette partition
ndb.SimpleQuery( ndb.SimpleQuery(
"""DELETE FROM group_membership """DELETE FROM group_membership gm
WHERE id IN WHERE EXISTS
(SELECT gm.id (SELECT 1 FROM group_descr gd
FROM group_membership gm, group_descr gd
WHERE gm.etudid = %(etudid)s WHERE gm.etudid = %(etudid)s
AND gm.group_id = gd.id AND gm.group_id = gd.id
AND gd.partition_id = %(partition_id)s) AND gd.partition_id = %(partition_id)s)
""", """,
{"etudid": etudid, "partition_id": partition["partition_id"]}, {"etudid": etudid, "partition_id": partition["partition_id"]},
) )
# 2- associe au nouveau groupe # 2- associe au nouveau groupe
set_group(context, etudid, group_id) set_group(context, etudid, group_id)
@ -810,7 +810,7 @@ def partition_create(
partition_name="", partition_name="",
default=False, default=False,
numero=None, numero=None,
redirect=1, redirect=True,
): ):
"""Create a new partition""" """Create a new partition"""
if not sco_permissions_check.can_change_groups(formsemestre_id): if not sco_permissions_check.can_change_groups(formsemestre_id):

View File

@ -35,6 +35,7 @@ import time
from datetime import date from datetime import date
import flask import flask
from flask import g, url_for
import app.scodoc.sco_utils as scu import app.scodoc.sco_utils as scu
import app.scodoc.notesdb as ndb import app.scodoc.notesdb as ndb
@ -101,8 +102,6 @@ ADMISSION_MODIFIABLE_FIELDS = (
"paysdomicile", "paysdomicile",
"telephone", "telephone",
"telephonemobile", "telephonemobile",
# Debouche
"debouche",
# Groupes # Groupes
"groupes", "groupes",
) )
@ -242,9 +241,13 @@ def students_import_excel(
) )
if REQUEST: if REQUEST:
if formsemestre_id: if formsemestre_id:
dest = "Notes/formsemestre_status?formsemestre_id=%s" % formsemestre_id dest = url_for(
"notes.formsemestre_status",
scodoc_dept=g.scodoc_dept,
formsemestre_id=formsemestre_id,
)
else: else:
dest = scu.NotesURL() dest = url_for("notes.index_html", scodoc_dept=g.scodoc_dept)
H = [html_sco_header.sco_header(page_title="Import etudiants")] H = [html_sco_header.sco_header(page_title="Import etudiants")]
H.append("<ul>") H.append("<ul>")
for d in diag: for d in diag:
@ -467,7 +470,7 @@ def scolars_import_excel_file(
{"etudid": etudid}, {"etudid": etudid},
) )
cursor.execute( cursor.execute(
"delete from identite where etudid=%(etudid)s", {"etudid": etudid} "delete from identite where id=%(etudid)s", {"etudid": etudid}
) )
cnx.commit() cnx.commit()
log("scolars_import_excel_file: re-raising exception") log("scolars_import_excel_file: re-raising exception")
@ -508,8 +511,11 @@ def students_import_admission(
H.append("<p>Import terminé !</p>") H.append("<p>Import terminé !</p>")
H.append( H.append(
'<p><a class="stdlink" href="%s">Continuer</a></p>' '<p><a class="stdlink" href="%s">Continuer</a></p>'
% "formsemestre_status?formsemestre_id=%s" % url_for(
% formsemestre_id "notes.formsemestre_status",
scodoc_dept=g.scodoc_dept,
formsemestre_id=formsemestre_id,
)
) )
if diag: if diag:
H.append("<p>Diagnostic: <ul><li>%s</li></ul></p>" % "</li><li>".join(diag)) H.append("<p>Diagnostic: <ul><li>%s</li></ul></p>" % "</li><li>".join(diag))
@ -649,8 +655,11 @@ def scolars_import_admission(
log("fields titles =" + ", ".join([fields[x][0] for x in fields])) log("fields titles =" + ", ".join([fields[x][0] for x in fields]))
raise FormatError( raise FormatError(
"scolars_import_admission: colonnes nom et prenom requises", "scolars_import_admission: colonnes nom et prenom requises",
dest_url="form_students_import_infos_admissions?formsemestre_id=%s" dest_url=url_for(
% formsemestre_id, "notes.form_students_import_infos_admissions",
scodoc_dept=g.scodoc_dept,
formsemestre_id=formsemestre_id,
),
) )
modifiable_fields = set(ADMISSION_MODIFIABLE_FIELDS) modifiable_fields = set(ADMISSION_MODIFIABLE_FIELDS)
@ -679,8 +688,11 @@ def scolars_import_admission(
raise FormatError( raise FormatError(
'scolars_import_admission: valeur invalide, ligne %d colonne %s: "%s"' 'scolars_import_admission: valeur invalide, ligne %d colonne %s: "%s"'
% (nline, field_name, line[idx]), % (nline, field_name, line[idx]),
dest_url="form_students_import_infos_admissions?formsemestre_id=%s" dest_url=url_for(
% formsemestre_id, "notes.form_students_import_infos_admissions",
scodoc_dept=g.scodoc_dept,
formsemestre_id=formsemestre_id,
),
) )
if val is not None: # note: ne peut jamais supprimer une valeur if val is not None: # note: ne peut jamais supprimer une valeur
args[field_name] = val args[field_name] = val
@ -762,8 +774,11 @@ def adm_get_fields(titles, formsemestre_id):
raise FormatError( raise FormatError(
'scolars_import_admission: titre "%s" en double (ligne 1)' 'scolars_import_admission: titre "%s" en double (ligne 1)'
% (title), % (title),
dest_url="form_students_import_infos_admissions_apb?formsemestre_id=%s" dest_url=url_for(
% formsemestre_id, "notes.form_students_import_infos_admissions_apb",
scodoc_dept=g.scodoc_dept,
formsemestre_id=formsemestre_id,
),
) )
fields[idx] = (k, convertor) fields[idx] = (k, convertor)
idx += 1 idx += 1

View File

@ -354,7 +354,7 @@ def ficheEtud(context, etudid=None, REQUEST=None):
) )
# Devenir de l'étudiant: # Devenir de l'étudiant:
has_debouche = True # info['debouche'] has_debouche = True
if sco_permissions_check.can_edit_suivi(): if sco_permissions_check.can_edit_suivi():
suivi_readonly = "0" suivi_readonly = "0"
link_add_suivi = """<li class="adddebouche"> link_add_suivi = """<li class="adddebouche">

View File

@ -1594,11 +1594,11 @@ def etudident_delete(context, etudid, dialog_confirmed=False, REQUEST=None):
"adresse", "adresse",
"absences", "absences",
"billet_absence", "billet_absence",
"identite",
] ]
cursor = cnx.cursor(cursor_factory=ndb.ScoDocCursor) cursor = cnx.cursor(cursor_factory=ndb.ScoDocCursor)
for table in tables: for table in tables:
cursor.execute("delete from %s where etudid=%%(etudid)s" % table, etud) cursor.execute("delete from %s where etudid=%%(etudid)s" % table, etud)
cursor.execute("delete from identite where id=%(etudid)s", etud)
cnx.commit() cnx.commit()
# Inval semestres où il était inscrit: # Inval semestres où il était inscrit:
to_inval = [s["formsemestre_id"] for s in etud["sems"]] to_inval = [s["formsemestre_id"] for s in etud["sems"]]
@ -1760,6 +1760,7 @@ def check_group_apogee(
@bp.route("/form_students_import_excel", methods=["GET", "POST"]) @bp.route("/form_students_import_excel", methods=["GET", "POST"])
@scodoc
@permission_required(Permission.ScoEtudInscrit) @permission_required(Permission.ScoEtudInscrit)
@scodoc7func(context) @scodoc7func(context)
def form_students_import_excel(context, REQUEST, formsemestre_id=None): def form_students_import_excel(context, REQUEST, formsemestre_id=None):