diff --git a/README.md b/README.md old mode 100755 new mode 100644 index 375ffdef..8ae84c1f --- a/README.md +++ b/README.md @@ -240,6 +240,9 @@ Puis dérouler les tests unitaires: pytest tests/unit +Ou avec couverture (`pip install pytest-cov`) + + pytest --cov=app --cov-report=term-missing --cov-branch tests/unit/* ## TODO diff --git a/app/decorators.py b/app/decorators.py index 412b5940..161ab8b5 100644 --- a/app/decorators.py +++ b/app/decorators.py @@ -164,8 +164,7 @@ def scodoc7func(context): req_args = REQUEST.form # args from query string (get) or form (post) # --- Add positional arguments pos_arg_values = [] - # PY3 à remplacer par inspect.getfullargspec en py3: TODO - argspec = inspect.getargspec(func) + argspec = inspect.getfullargspec(func) # current_app.logger.info("argspec=%s" % str(argspec)) nb_default_args = len(argspec.defaults) if argspec.defaults else 0 if nb_default_args: diff --git a/app/scodoc/notes_log.py b/app/scodoc/notes_log.py index 7b0b7288..ba52d494 100644 --- a/app/scodoc/notes_log.py +++ b/app/scodoc/notes_log.py @@ -2,14 +2,13 @@ # -*- coding: utf-8 -*- import os -import re -import inspect import time import traceback from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from email.header import Header -from flask import current_app + +from flask import g, current_app """Simple & stupid file logguer, used only to debug (logging to SQL is done in scolog) @@ -18,7 +17,7 @@ from flask import current_app LOG_FILENAME = "notes.log" # empty to disable logging DEFAULT_LOG_DIR = "/tmp" # clients should call set_log_directory to change this -ALARM_DESTINATION = "emmanuel.viennet@univ-paris13.fr" # XXX a mettre en preference +ALARM_DESTINATION = "emmanuel.viennet@gmail.com" # XXX a mettre en preference class _logguer(object): @@ -46,7 +45,11 @@ class _logguer(object): if not self.file: self._open() if self.file: - dept = retreive_dept() + try: + dept = getattr(g, "scodoc_dept", "") + except RuntimeError: + # Flask Working outside of application context. + dept = "" if dept: dept = " (%s)" % dept msg = dept + " " + msg @@ -60,42 +63,6 @@ class _logguer(object): log = _logguer() -def retreive_request(skip=0): - """Try to retreive a REQUEST variable in caller stack. - This is a hack, used only in log functions. - """ - - def search(frame): - if "REQUEST" in frame.f_locals: - return frame.f_locals["REQUEST"] - if frame.f_back: - return search(frame.f_back) - else: - return None - - frame = inspect.currentframe() - if frame: # not supported by all pythons - startframe = frame - while skip and startframe.f_back: - startframe = startframe.f_back - return search(startframe) - else: - return None - - -def retreive_dept(): - """Try to retreive departement (from REQUEST URL)""" - REQUEST = retreive_request() - if not REQUEST: - return "" - try: - url = REQUEST.URL - m = re.match(r"^.*ScoDoc/(\w+).*$", url) - return m.group(1) - except: - return "" - - # Alarms by email: def sendAlarm(context, subj, txt): from . import sco_utils diff --git a/app/scodoc/sco_abs.py b/app/scodoc/sco_abs.py index 34116e13..ee3455e4 100644 --- a/app/scodoc/sco_abs.py +++ b/app/scodoc/sco_abs.py @@ -617,7 +617,6 @@ def add_absence( vars(), ) logdb( - REQUEST, cnx, "AddAbsence", etudid=etudid, @@ -642,7 +641,6 @@ def add_justif(context, etudid, jour, matin, REQUEST, description=None): vars(), ) logdb( - REQUEST, cnx, "AddJustif", etudid=etudid, @@ -679,7 +677,6 @@ def annule_absence(context, etudid, jour, matin, moduleimpl_id=None, REQUEST=Non req += " and moduleimpl_id=%(moduleimpl_id)s" cursor.execute(req, vars()) logdb( - REQUEST, cnx, "AnnuleAbsence", etudid=etudid, @@ -704,7 +701,6 @@ def annule_justif(context, etudid, jour, matin, REQUEST=None): vars(), ) logdb( - REQUEST, cnx, "AnnuleJustif", etudid=etudid, diff --git a/app/scodoc/sco_abs_views.py b/app/scodoc/sco_abs_views.py index 80693c8b..06ea8e9d 100644 --- a/app/scodoc/sco_abs_views.py +++ b/app/scodoc/sco_abs_views.py @@ -652,7 +652,6 @@ def AnnuleAbsencesDatesNoJust(context, etudid, dates, moduleimpl_id=None, REQUES else: date1 = None logdb( - REQUEST, cnx, "AnnuleAbsencesDatesNoJust", etudid=etudid, diff --git a/app/scodoc/sco_archives.py b/app/scodoc/sco_archives.py index a6a37d43..3d80b46a 100644 --- a/app/scodoc/sco_archives.py +++ b/app/scodoc/sco_archives.py @@ -488,7 +488,7 @@ enregistrés et non modifiables, on peut les retrouver ultérieurement. msg = "Nouvelle%20archive%20créée" # submitted or cancelled: - return REQUEST.RESPONSE.redirect( + return flask.redirect( "formsemestre_list_archives?formsemestre_id=%s&head_message=%s" % (formsemestre_id, msg) ) @@ -566,12 +566,10 @@ def formsemestre_delete_archive( if not dialog_confirmed: return scu.confirm_dialog( - context, """
La suppression sera définitive.
""" % PVArchive.get_archive_date(archive_id).strftime("%d/%m/%Y %H:%M"), dest_url="", - REQUEST=REQUEST, cancel_url=dest_url, parameters={ "formsemestre_id": formsemestre_id, @@ -580,4 +578,4 @@ def formsemestre_delete_archive( ) PVArchive.delete_archive(archive_id) - return REQUEST.RESPONSE.redirect(dest_url + "&head_message=Archive%20supprimée") + return flask.redirect(dest_url + "&head_message=Archive%20supprimée") diff --git a/app/scodoc/sco_archives_etud.py b/app/scodoc/sco_archives_etud.py index 19539657..94aad219 100644 --- a/app/scodoc/sco_archives_etud.py +++ b/app/scodoc/sco_archives_etud.py @@ -29,6 +29,7 @@ Il s'agit de fichiers quelconques, généralement utilisés pour conserver les dossiers d'admission et autres pièces utiles. """ +import flask from flask import url_for, g import app.scodoc.sco_utils as scu @@ -164,7 +165,7 @@ def etud_upload_file_form(context, REQUEST, etudid): if tf[0] == 0: return "\n".join(H) + tf[1] + html_sco_header.sco_footer() elif tf[0] == -1: - return REQUEST.RESPONSE.redirect( + return flask.redirect( url_for("scolar.ficheEtud", scodoc_dept=g.scodoc_dept, etudid=etudid) ) else: @@ -174,7 +175,7 @@ def etud_upload_file_form(context, REQUEST, etudid): _store_etud_file_to_new_archive( context, REQUEST, etudid, data, filename, description=descr ) - return REQUEST.RESPONSE.redirect( + return flask.redirect( url_for("scolar.ficheEtud", scodoc_dept=g.scodoc_dept, etudid=etudid) ) @@ -201,7 +202,6 @@ def etud_delete_archive(context, REQUEST, etudid, archive_name, dialog_confirmed archive_id = EtudsArchive.get_id_from_name(context, etudid, archive_name) if not dialog_confirmed: return scu.confirm_dialog( - context, """Fichier associé le %s à l'étudiant %s
La suppression sera définitive.
""" @@ -210,7 +210,6 @@ def etud_delete_archive(context, REQUEST, etudid, archive_name, dialog_confirmed etud["nomprenom"], ), dest_url="", - REQUEST=REQUEST, cancel_url=url_for( "scolar.ficheEtud", scodoc_dept=g.scodoc_dept, @@ -221,7 +220,7 @@ def etud_delete_archive(context, REQUEST, etudid, archive_name, dialog_confirmed ) EtudsArchive.delete_archive(archive_id) - return REQUEST.RESPONSE.redirect( + return flask.redirect( url_for( "scolar.ficheEtud", scodoc_dept=g.scodoc_dept, @@ -311,9 +310,13 @@ def etudarchive_import_files_form(context, group_id, REQUEST=None): return "\n".join(H) + tf[1] + "" + F elif tf[0] == -1: # retrouve le semestre à partir du groupe: - g = sco_groups.get_group(context, group_id) - return REQUEST.RESPONSE.redirect( - "formsemestre_status?formsemestre_id=" + g["formsemestre_id"] + group = sco_groups.get_group(context, group_id) + return flask.redirect( + url_for( + "notes.formsemestre_status", + scodoc_dept=g.scodoc_dept, + formsemestre_id=group["formsemestre_id"], + ) ) else: return etudarchive_import_files( diff --git a/app/scodoc/sco_debouche.py b/app/scodoc/sco_debouche.py index 6c7cf7a6..fba445ec 100644 --- a/app/scodoc/sco_debouche.py +++ b/app/scodoc/sco_debouche.py @@ -256,7 +256,7 @@ def itemsuivi_suppress(context, itemsuivi_id, REQUEST=None): item = itemsuivi_get(cnx, itemsuivi_id, ignore_errors=True) if item: _itemsuivi_delete(cnx, itemsuivi_id) - logdb(REQUEST, cnx, method="itemsuivi_suppress", etudid=item["etudid"]) + logdb(cnx, method="itemsuivi_suppress", etudid=item["etudid"]) log("suppressed itemsuivi %s" % (itemsuivi_id,)) @@ -270,7 +270,7 @@ def itemsuivi_create( itemsuivi_id = _itemsuivi_create( cnx, args={"etudid": etudid, "item_date": item_date, "situation": situation} ) - logdb(REQUEST, cnx, method="itemsuivi_create", etudid=etudid) + logdb(cnx, method="itemsuivi_create", etudid=etudid) log("created itemsuivi %s for %s" % (itemsuivi_id, etudid)) item = itemsuivi_get(cnx, itemsuivi_id) if format == "json": diff --git a/app/scodoc/sco_edit_formation.py b/app/scodoc/sco_edit_formation.py index 7edc901d..0f7c13af 100644 --- a/app/scodoc/sco_edit_formation.py +++ b/app/scodoc/sco_edit_formation.py @@ -73,19 +73,17 @@ def formation_delete(context, formation_id=None, dialog_confirmed=False, REQUEST else: if not dialog_confirmed: return scu.confirm_dialog( - context, """Attention: la suppression d'une formation est irréversible et implique la supression de toutes les UE, matières et modules de la formation !
""" % F, - REQUEST=REQUEST, OK="Supprimer cette formation", cancel_url=scu.NotesURL(), parameters={"formation_id": formation_id}, ) else: - do_formation_delete(context, F["formation_id"], REQUEST) + do_formation_delete(context, F["formation_id"]) H.append( """OK, formation supprimée.
""" @@ -96,7 +94,7 @@ def formation_delete(context, formation_id=None, dialog_confirmed=False, REQUEST return "\n".join(H) -def do_formation_delete(context, oid, REQUEST): +def do_formation_delete(context, oid): """delete a formation (and all its UE, matieres, modules) XXX delete all ues, will break if there are validations ! USE WITH CARE ! """ @@ -107,7 +105,7 @@ def do_formation_delete(context, oid, REQUEST): # delete all UE in this formation ues = sco_edit_ue.do_ue_list(context, {"formation_id": oid}) for ue in ues: - sco_edit_ue.do_ue_delete(context, ue["ue_id"], REQUEST=REQUEST, force=True) + sco_edit_ue.do_ue_delete(context, ue["ue_id"], force=True) sco_formations._formationEditor.delete(cnx, oid) @@ -222,7 +220,7 @@ def formation_edit(context, formation_id=None, create=False, REQUEST=None): if tf[0] == 0: return "\n".join(H) + tf[1] + html_sco_header.sco_footer() elif tf[0] == -1: - return REQUEST.RESPONSE.redirect(scu.NotesURL()) + return flask.redirect(scu.NotesURL()) else: # check unicity : constraint UNIQUE(acronyme,titre,version) if create: @@ -247,13 +245,13 @@ def formation_edit(context, formation_id=None, create=False, REQUEST=None): ) # if create: - formation_id = do_formation_create(context, tf[2], REQUEST) + formation_id = do_formation_create(context, tf[2]) else: do_formation_edit(context, tf[2]) - return REQUEST.RESPONSE.redirect("ue_list?formation_id=%s" % formation_id) + return flask.redirect("ue_list?formation_id=%s" % formation_id) -def do_formation_create(context, args, REQUEST): +def do_formation_create(context, args): "create a formation" cnx = ndb.GetDBConnexion() # check unique acronyme/titre/version @@ -338,7 +336,7 @@ def module_move(context, module_id, after=0, REQUEST=None, redirect=1): # redirect to ue_list page: if redirect: - return REQUEST.RESPONSE.redirect("ue_list?formation_id=" + formation_id) + return flask.redirect("ue_list?formation_id=" + formation_id) def ue_move(context, ue_id, after=0, REQUEST=None, redirect=1): @@ -369,4 +367,4 @@ def ue_move(context, ue_id, after=0, REQUEST=None, redirect=1): sco_edit_ue._ueEditor.edit(cnx, neigh) # redirect to ue_list page if redirect: - return REQUEST.RESPONSE.redirect("ue_list?formation_id=" + o["formation_id"]) \ No newline at end of file + return flask.redirect("ue_list?formation_id=" + o["formation_id"]) \ No newline at end of file diff --git a/app/scodoc/sco_edit_matiere.py b/app/scodoc/sco_edit_matiere.py index 8693ccbb..bb337e5b 100644 --- a/app/scodoc/sco_edit_matiere.py +++ b/app/scodoc/sco_edit_matiere.py @@ -68,7 +68,7 @@ def do_matiere_edit(context, *args, **kw): sco_edit_formation.invalidate_sems_in_formation(formation_id) -def do_matiere_create(context, args, REQUEST): +def do_matiere_create(context, args): "create a matiere" from app.scodoc import sco_edit_ue from app.scodoc import sco_formations @@ -138,7 +138,7 @@ associé. if tf[0] == 0: return "\n".join(H) + tf[1] + html_sco_header.sco_footer() elif tf[0] == -1: - return REQUEST.RESPONSE.redirect(dest_url) + return flask.redirect(dest_url) else: # check unicity mats = do_matiere_list(context, args={"ue_id": ue_id, "titre": tf[2]["titre"]}) @@ -149,11 +149,11 @@ associé. + tf[1] + html_sco_header.sco_footer() ) - _ = do_matiere_create(context, tf[2], REQUEST) - return REQUEST.RESPONSE.redirect(dest_url) + _ = do_matiere_create(context, tf[2]) + return flask.redirect(dest_url) -def do_matiere_delete(context, oid, REQUEST): +def do_matiere_delete(context, oid): "delete matiere and attached modules" from app.scodoc import sco_formations from app.scodoc import sco_edit_ue @@ -174,7 +174,7 @@ def do_matiere_delete(context, oid, REQUEST): # delete all modules in this matiere mods = sco_edit_module.do_module_list(context, {"matiere_id": oid}) for mod in mods: - sco_edit_module.do_module_delete(context, mod["module_id"], REQUEST) + sco_edit_module.do_module_delete(context, mod["module_id"]) _matiereEditor.delete(cnx, oid) # news @@ -211,10 +211,10 @@ def matiere_delete(context, matiere_id=None, REQUEST=None): if tf[0] == 0: return "\n".join(H) + tf[1] + html_sco_header.sco_footer() elif tf[0] == -1: - return REQUEST.RESPONSE.redirect(dest_url) + return flask.redirect(dest_url) else: - do_matiere_delete(context, matiere_id, REQUEST) - return REQUEST.RESPONSE.redirect(dest_url) + do_matiere_delete(context, matiere_id) + return flask.redirect(dest_url) def matiere_edit(context, matiere_id=None, REQUEST=None): @@ -284,7 +284,7 @@ associé. if tf[0] == 0: return "\n".join(H) + tf[1] + help + html_sco_header.sco_footer() elif tf[0] == -1: - return REQUEST.RESPONSE.redirect(dest_url) + return flask.redirect(dest_url) else: # check unicity mats = do_matiere_list( @@ -308,7 +308,7 @@ associé. do_matiere_edit(context, tf[2]) - return REQUEST.RESPONSE.redirect(dest_url) + return flask.redirect(dest_url) def matiere_is_locked(context, matiere_id): diff --git a/app/scodoc/sco_edit_module.py b/app/scodoc/sco_edit_module.py index 7e840abc..f98beb49 100644 --- a/app/scodoc/sco_edit_module.py +++ b/app/scodoc/sco_edit_module.py @@ -28,6 +28,9 @@ """Ajout/Modification/Suppression modules (portage from DTML) """ +import flask +from flask import url_for, g + import app.scodoc.notesdb as ndb import app.scodoc.sco_utils as scu from app.scodoc.notes_log import log @@ -96,7 +99,7 @@ def do_module_list(context, *args, **kw): return _moduleEditor.list(cnx, *args, **kw) -def do_module_create(context, args, REQUEST): +def do_module_create(context, args): "create a module" # create from app.scodoc import sco_formations @@ -237,13 +240,17 @@ def module_create(context, matiere_id=None, REQUEST=None): if tf[0] == 0: return "\n".join(H) + tf[1] + html_sco_header.sco_footer() else: - do_module_create(context, tf[2], REQUEST) - return REQUEST.RESPONSE.redirect( - scu.NotesURL() + "/ue_list?formation_id=" + UE["formation_id"] + do_module_create(context, tf[2]) + return flask.redirect( + url_for( + "notes.ue_list", + scodoc_dept=g.scodoc_dept, + formation_id=UE["formation_id"], + ) ) -def do_module_delete(context, oid, REQUEST): +def do_module_delete(context, oid): "delete module" from app.scodoc import sco_formations @@ -255,12 +262,10 @@ def do_module_delete(context, oid, REQUEST): mods = sco_moduleimpl.do_moduleimpl_list(context, module_id=oid) if mods: err_page = scu.confirm_dialog( - context, message="""%d étudiants ont validé l'UE %s (%s)
Si vous supprimez cette UE, ces validations vont être supprimées !
" % (len(validations), ue["acronyme"], ue["titre"]), dest_url="", - REQUEST=REQUEST, target_variable="delete_validations", cancel_url="ue_list?formation_id=%s" % ue["formation_id"], parameters={"ue_id": ue_id, "dialog_confirmed": 1}, @@ -149,7 +151,7 @@ def do_ue_delete(context, ue_id, delete_validations=False, REQUEST=None, force=F # delete all matiere in this UE mats = sco_edit_matiere.do_matiere_list(context, {"ue_id": ue_id}) for mat in mats: - sco_edit_matiere.do_matiere_delete(context, mat["matiere_id"], REQUEST) + sco_edit_matiere.do_matiere_delete(context, mat["matiere_id"]) # delete uecoef and events ndb.SimpleQuery( "DELETE FROM notes_formsemestre_uecoef WHERE ue_id=%(ue_id)s", @@ -171,8 +173,12 @@ def do_ue_delete(context, ue_id, delete_validations=False, REQUEST=None, force=F ) # if not force: - return REQUEST.RESPONSE.redirect( - scu.NotesURL() + "/ue_list?formation_id=" + str(ue["formation_id"]) + return flask.redirect( + url_for( + "notes.ue_list", + scodoc_dept=g.scodoc_dept, + formation_id=ue["formation_id"], + ) ) else: return None @@ -337,12 +343,11 @@ def ue_edit(context, ue_id=None, create=False, formation_id=None, REQUEST=None): context, formation_id, int(tf[2]["semestre_id"] or 0) ) - ue_id = do_ue_create(context, tf[2], REQUEST) + ue_id = do_ue_create(context, tf[2]) if parcours.UE_IS_MODULE or tf[2]["create_matiere"]: matiere_id = sco_edit_matiere.do_matiere_create( context, {"ue_id": ue_id, "titre": tf[2]["titre"], "numero": 1}, - REQUEST, ) if parcours.UE_IS_MODULE: # dans ce mode, crée un (unique) module dans l'UE: @@ -357,12 +362,13 @@ def ue_edit(context, ue_id=None, create=False, formation_id=None, REQUEST=None): "formation_id": formation_id, "semestre_id": tf[2]["semestre_id"], }, - REQUEST, ) else: do_ue_edit(context, tf[2]) - return REQUEST.RESPONSE.redirect( - scu.NotesURL() + "/ue_list?formation_id=" + formation_id + return flask.redirect( + url_for( + "notes.ue_list", scodoc_dept=g.scodoc_dept, formation_id=formation_id + ) ) @@ -409,10 +415,8 @@ def ue_delete( if not dialog_confirmed: return scu.confirm_dialog( - context, "La suppression sera définitive.
""" % (etape_apo,), dest_url="", - REQUEST=REQUEST, cancel_url=dest_url, parameters={"semset_id": semset_id, "etape_apo": etape_apo}, ) @@ -684,7 +682,7 @@ def view_apo_csv_delete( context, etape_apo, semset["annee_scolaire"], semset["sem_id"] ) sco_etape_apogee.apo_csv_delete(context, info["archive_id"]) - return REQUEST.RESPONSE.redirect(dest_url + "&head_message=Archive%20supprimée") + return flask.redirect(dest_url + "&head_message=Archive%20supprimée") def view_apo_csv(context, etape_apo="", semset_id="", format="html", REQUEST=None): diff --git a/app/scodoc/sco_etud.py b/app/scodoc/sco_etud.py index a80fa0ea..f2a0cf1c 100644 --- a/app/scodoc/sco_etud.py +++ b/app/scodoc/sco_etud.py @@ -351,7 +351,6 @@ def _check_duplicate_code(cnx, args, code_name, context, edit=True, REQUEST=None parameters = {} if context: err_page = scu.confirm_dialog( - context, message="""Le programme pédagogique ("formation") va être dupliqué pour que vous puissiez le modifier sans affecter les autres semestres. Les autres paramètres (étudiants, notes...) du semestre seront inchangés.
Veillez à ne pas abuser de cette possibilité, car créer trop de versions de formations va vous compliquer la gestion (à vous de garder trace des différences et à ne pas vous tromper par la suite...). @@ -1183,7 +1182,6 @@ def formsemestre_associate_new_version( + "", OK="Associer ces semestres à une nouvelle version", dest_url="", - REQUEST=REQUEST, cancel_url="formsemestre_status?formsemestre_id=%s" % formsemestre_id, parameters={"formsemestre_id": formsemestre_id}, ) @@ -1191,7 +1189,7 @@ def formsemestre_associate_new_version( do_formsemestres_associate_new_version( context, [formsemestre_id] + other_formsemestre_ids, REQUEST=REQUEST ) - return REQUEST.RESPONSE.redirect( + return flask.redirect( "formsemestre_status?formsemestre_id=%s&head_message=Formation%%20dupliquée" % formsemestre_id ) @@ -1315,13 +1313,11 @@ def formsemestre_delete(context, formsemestre_id, REQUEST=None): H.append(tf[1]) return "\n".join(H) + html_sco_header.sco_footer() elif tf[0] == -1: # cancel - return REQUEST.RESPONSE.redirect( + return flask.redirect( scu.NotesURL() + "/formsemestre_status?formsemestre_id=" + formsemestre_id ) else: - return REQUEST.RESPONSE.redirect( - "formsemestre_delete2?formsemestre_id=" + formsemestre_id - ) + return flask.redirect("formsemestre_delete2?formsemestre_id=" + formsemestre_id) def formsemestre_delete2( @@ -1331,16 +1327,14 @@ def formsemestre_delete2( # Confirmation dialog if not dialog_confirmed: return scu.confirm_dialog( - context, """
(opération irréversible)
""", dest_url="", - REQUEST=REQUEST, cancel_url="formsemestre_status?formsemestre_id=%s" % formsemestre_id, parameters={"formsemestre_id": formsemestre_id}, ) # Bon, s'il le faut... - do_formsemestre_delete(context, formsemestre_id, REQUEST) - return REQUEST.RESPONSE.redirect(scu.ScoURL() + "?head_message=Semestre%20supprimé") + do_formsemestre_delete(context, formsemestre_id) + return flask.redirect(scu.ScoURL() + "?head_message=Semestre%20supprimé") def formsemestre_has_decisions_or_compensations(context, formsemestre_id): @@ -1354,7 +1348,7 @@ def formsemestre_has_decisions_or_compensations(context, formsemestre_id): return r -def do_formsemestre_delete(context, formsemestre_id, REQUEST): +def do_formsemestre_delete(context, formsemestre_id): """delete formsemestre, and all its moduleimpls. No checks, no warnings: erase all ! """ @@ -1444,9 +1438,7 @@ def formsemestre_edit_options(context, formsemestre_id, target_url=None, REQUEST (accessible par ScoImplement ou dir. etudes) """ log("formsemestre_edit_options") - ok, err = sco_permissions_check.check_access_diretud( - context, formsemestre_id, REQUEST - ) + ok, err = sco_permissions_check.check_access_diretud(formsemestre_id) if not ok: return err return sco_preferences.SemPreferences(formsemestre_id).edit( @@ -1460,9 +1452,7 @@ def formsemestre_change_lock( """Change etat (verrouille si ouvert, déverrouille si fermé) nota: etat (1 ouvert, 0 fermé) """ - ok, err = sco_permissions_check.check_access_diretud( - context, formsemestre_id, REQUEST - ) + ok, err = sco_permissions_check.check_access_diretud(formsemestre_id) if not ok: return err sem = sco_formsemestre.get_formsemestre(context, formsemestre_id) @@ -1474,7 +1464,6 @@ def formsemestre_change_lock( else: msg = "verrouillage" return scu.confirm_dialog( - context, "Les groupes %s de cette partition seront supprimés
""" % (partition["partition_name"], grnames), dest_url="", - REQUEST=REQUEST, cancel_url="editPartitionForm?formsemestre_id=%s" % formsemestre_id, parameters={"redirect": redirect, "partition_id": partition_id}, ) @@ -977,9 +973,7 @@ def partition_delete( # redirect to partition edit page: if redirect: - return REQUEST.RESPONSE.redirect( - "editPartitionForm?formsemestre_id=" + formsemestre_id - ) + return flask.redirect("editPartitionForm?formsemestre_id=" + formsemestre_id) def partition_move(context, partition_id, after=0, REQUEST=None, redirect=1): @@ -1012,9 +1006,7 @@ def partition_move(context, partition_id, after=0, REQUEST=None, redirect=1): # redirect to partition edit page: if redirect: - return REQUEST.RESPONSE.redirect( - "editPartitionForm?formsemestre_id=" + formsemestre_id - ) + return flask.redirect("editPartitionForm?formsemestre_id=" + formsemestre_id) def partition_rename(context, partition_id, REQUEST=None): @@ -1051,9 +1043,7 @@ def partition_rename(context, partition_id, REQUEST=None): + html_sco_header.sco_footer() ) elif tf[0] == -1: - return REQUEST.RESPONSE.redirect( - "editPartitionForm?formsemestre_id=" + formsemestre_id - ) + return flask.redirect("editPartitionForm?formsemestre_id=" + formsemestre_id) else: # form submission return partition_set_name( @@ -1091,9 +1081,7 @@ def partition_set_name(context, partition_id, partition_name, REQUEST=None, redi # redirect to partition edit page: if redirect: - return REQUEST.RESPONSE.redirect( - "editPartitionForm?formsemestre_id=" + formsemestre_id - ) + return flask.redirect("editPartitionForm?formsemestre_id=" + formsemestre_id) def group_set_name(context, group_id, group_name, REQUEST=None, redirect=1): @@ -1114,9 +1102,7 @@ def group_set_name(context, group_id, group_name, REQUEST=None, redirect=1): # redirect to partition edit page: if redirect: - return REQUEST.RESPONSE.redirect( - "affectGroups?partition_id=" + group["partition_id"] - ) + return flask.redirect("affectGroups?partition_id=" + group["partition_id"]) def group_rename(context, group_id, REQUEST=None): @@ -1153,9 +1139,7 @@ def group_rename(context, group_id, REQUEST=None): + html_sco_header.sco_footer() ) elif tf[0] == -1: - return REQUEST.RESPONSE.redirect( - "affectGroups?partition_id=" + group["partition_id"] - ) + return flask.redirect("affectGroups?partition_id=" + group["partition_id"]) else: # form submission return group_set_name( @@ -1213,7 +1197,7 @@ def groups_auto_repartition(context, partition_id=None, REQUEST=None): if tf[0] == 0: return "\n".join(H) + "\n" + tf[1] + html_sco_header.sco_footer() elif tf[0] == -1: - return REQUEST.RESPONSE.redirect(dest_url) + return flask.redirect(dest_url) else: # form submission log( @@ -1263,7 +1247,7 @@ def groups_auto_repartition(context, partition_id=None, REQUEST=None): context, etudid, group_id, partition, REQUEST=REQUEST ) log("%s in group %s" % (etudid, group_id)) - return REQUEST.RESPONSE.redirect(dest_url) + return flask.redirect(dest_url) def get_prev_moy(context, etudid, formsemestre_id): diff --git a/app/scodoc/sco_inscr_passage.py b/app/scodoc/sco_inscr_passage.py index 0e86b360..e5f6f87f 100644 --- a/app/scodoc/sco_inscr_passage.py +++ b/app/scodoc/sco_inscr_passage.py @@ -350,7 +350,6 @@ def formsemestre_inscr_passage( H.append("""(vérifiez que le semestre n'est pas verrouillé et que vous diff --git a/app/scodoc/sco_preferences.py b/app/scodoc/sco_preferences.py index 615e72ad..1ae6d5c3 100644 --- a/app/scodoc/sco_preferences.py +++ b/app/scodoc/sco_preferences.py @@ -1975,14 +1975,12 @@ class BasePreferences(object): if tf[0] == 0: return "\n".join(H) + tf[1] + html_sco_header.sco_footer() elif tf[0] == -1: - return REQUEST.RESPONSE.redirect(scu.ScoURL()) # cancel + return flask.redirect(scu.ScoURL()) # cancel else: for pref in self.prefs_definition: self.prefs[None][pref[0]] = tf[2][pref[0]] self.save() - return REQUEST.RESPONSE.redirect( - scu.ScoURL() + "?head_message=Préférences modifiées" - ) + return flask.redirect(scu.ScoURL() + "?head_message=Préférences modifiées") def build_tf_form(self, categories=[], formsemestre_id=None): """Build list of elements for TrivialFormulator. @@ -2151,9 +2149,7 @@ function set_global_pref(el, pref_name) { if tf[0] == 0: return "\n".join(H) + tf[1] + html_sco_header.sco_footer() elif tf[0] == -1: - return REQUEST.RESPONSE.redirect( - dest_url + "&head_message=Annulé" - ) # cancel + return flask.redirect(dest_url + "&head_message=Annulé") # cancel else: # Supprime pref locale du semestre (retour à la valeur globale) if tf[2]["suppress"]: @@ -2187,15 +2183,13 @@ function set_global_pref(el, pref_name) { # done: change prefs and redirect to semestre status destination = tf[2]["destination"] if destination == "done" or destination == "": - return REQUEST.RESPONSE.redirect( - dest_url + "&head_message=Préférences modifiées" - ) + return flask.redirect(dest_url + "&head_message=Préférences modifiées") elif destination == "again": - return REQUEST.RESPONSE.redirect( + return flask.redirect( REQUEST.URL0 + "?formsemestre_id=" + self.formsemestre_id ) elif destination == "global": - return REQUEST.RESPONSE.redirect(scu.ScoURL() + "/edit_preferences") + return flask.redirect(scu.ScoURL() + "/edit_preferences") # diff --git a/app/scodoc/sco_pvjury.py b/app/scodoc/sco_pvjury.py index f4a288aa..3ea8853a 100644 --- a/app/scodoc/sco_pvjury.py +++ b/app/scodoc/sco_pvjury.py @@ -687,7 +687,7 @@ def formsemestre_pvjury_pdf( if tf[0] == 0: return "\n".join(H) + "\n" + tf[1] + "\n".join(F) elif tf[0] == -1: - return REQUEST.RESPONSE.redirect( + return flask.redirect( "formsemestre_pvjury?formsemestre_id=%s" % (formsemestre_id) ) else: @@ -861,7 +861,7 @@ def formsemestre_lettres_individuelles( if tf[0] == 0: return "\n".join(H) + "\n" + tf[1] + F elif tf[0] == -1: - return REQUEST.RESPONSE.redirect( + return flask.redirect( "formsemestre_pvjury?formsemestre_id=%s" % (formsemestre_id) ) else: @@ -881,7 +881,7 @@ def formsemestre_lettres_individuelles( finally: PDFLOCK.release() if not pdfdoc: - return REQUEST.RESPONSE.redirect( + return flask.redirect( "formsemestre_status?formsemestre_id={}&head_message=Aucun%20%C3%A9tudiant%20n%27a%20de%20d%C3%A9cision%20de%20jury".format( formsemestre_id ) diff --git a/app/scodoc/sco_saisie_notes.py b/app/scodoc/sco_saisie_notes.py index 6c89e8fb..bb9bf24a 100644 --- a/app/scodoc/sco_saisie_notes.py +++ b/app/scodoc/sco_saisie_notes.py @@ -33,6 +33,8 @@ import time import datetime import psycopg2 +from flask_login import current_user + import app.scodoc.sco_utils as scu import app.scodoc.notesdb as ndb from app.scodoc.notes_log import log @@ -171,7 +173,7 @@ def do_evaluation_upload_xls(context, REQUEST): )[0] # Check access # (admin, respformation, and responsable_id) - if not sco_permissions_check.can_edit_notes(context, authuser, E["moduleimpl_id"]): + if not sco_permissions_check.can_edit_notes(authuser, E["moduleimpl_id"]): # XXX imaginer un redirect + msg erreur raise AccessDenied("Modification des notes impossible pour %s" % authuser) # @@ -280,21 +282,19 @@ def do_evaluation_upload_xls(context, REQUEST): return 0, msg + "
(pas de notes modifiées)
" -def do_evaluation_set_missing( - context, evaluation_id, value, REQUEST=None, dialog_confirmed=False -): +def do_evaluation_set_missing(evaluation_id, value, dialog_confirmed=False): """Initialisation des notes manquantes""" - authuser = REQUEST.AUTHENTICATED_USER - evaluation_id = REQUEST.form["evaluation_id"] + # ? evaluation_id = REQUEST.form["evaluation_id"] + context = None # XXX #context E = sco_evaluations.do_evaluation_list({"evaluation_id": evaluation_id})[0] M = sco_moduleimpl.do_moduleimpl_withmodule_list( context, moduleimpl_id=E["moduleimpl_id"] )[0] # Check access # (admin, respformation, and responsable_id) - if not sco_permissions_check.can_edit_notes(context, authuser, E["moduleimpl_id"]): + if not sco_permissions_check.can_edit_notes(current_user, E["moduleimpl_id"]): # XXX imaginer un redirect + msg erreur - raise AccessDenied("Modification des notes impossible pour %s" % authuser) + raise AccessDenied("Modification des notes impossible pour %s" % current_user) # NotesDB = sco_evaluations.do_evaluation_get_all_notes(evaluation_id) etudids = sco_groups.do_evaluation_listeetuds_groups( @@ -319,7 +319,6 @@ def do_evaluation_set_missing( # Confirm action if not dialog_confirmed: return scu.confirm_dialog( - context, """Seuls les étudiants pour lesquels aucune note (ni valeur, ni ABS, ni EXC) @@ -329,13 +328,12 @@ def do_evaluation_set_missing( """ % (value, len(L)), dest_url="", - REQUEST=REQUEST, cancel_url="saisie_notes?evaluation_id=%s" % evaluation_id, parameters={"evaluation_id": evaluation_id, "value": value}, ) # ok comment = "Initialisation notes manquantes" - nb_changed, _, _ = _notes_add(context, authuser, evaluation_id, L, comment) + nb_changed, _, _ = _notes_add(context, current_user, evaluation_id, L, comment) # news M = sco_moduleimpl.do_moduleimpl_list(context, moduleimpl_id=E["moduleimpl_id"])[0] mod = sco_edit_module.do_module_list(context, args={"module_id": M["module_id"]})[0] @@ -362,41 +360,39 @@ def do_evaluation_set_missing( ) -def evaluation_suppress_alln(context, evaluation_id, REQUEST, dialog_confirmed=False): +def evaluation_suppress_alln(evaluation_id, dialog_confirmed=False): "suppress all notes in this eval" - authuser = REQUEST.AUTHENTICATED_USER + context = None # XXX #context E = sco_evaluations.do_evaluation_list({"evaluation_id": evaluation_id})[0] if sco_permissions_check.can_edit_notes( - context, authuser, E["moduleimpl_id"], allow_ens=False + current_user, E["moduleimpl_id"], allow_ens=False ): # On a le droit de modifier toutes les notes # recupere les etuds ayant une note NotesDB = sco_evaluations.do_evaluation_get_all_notes(evaluation_id) elif sco_permissions_check.can_edit_notes( - context, authuser, E["moduleimpl_id"], allow_ens=True + current_user, E["moduleimpl_id"], allow_ens=True ): # Enseignant associé au module: ne peut supprimer que les notes qu'il a saisi NotesDB = sco_evaluations.do_evaluation_get_all_notes( - evaluation_id, by_uid=str(authuser) + evaluation_id, by_uid=current_user.user_name ) else: - raise AccessDenied("Modification des notes impossible pour %s" % authuser) + raise AccessDenied("Modification des notes impossible pour %s" % current_user) notes = [(etudid, scu.NOTES_SUPPRESS) for etudid in NotesDB.keys()] if not dialog_confirmed: nb_changed, nb_suppress, existing_decisions = _notes_add( - context, authuser, evaluation_id, notes, do_it=False + context, current_user, evaluation_id, notes, do_it=False ) msg = "
Confirmer la suppression des %d notes ?
" % nb_suppress if existing_decisions: msg += """Important: il y a déjà des décisions de jury enregistrées, qui seront potentiellement à revoir suite à cette modification !
""" return scu.confirm_dialog( - context, msg, dest_url="", - REQUEST=REQUEST, OK="Supprimer les notes", cancel_url="moduleimpl_status?moduleimpl_id=%s" % E["moduleimpl_id"], parameters={"evaluation_id": evaluation_id}, @@ -404,7 +400,7 @@ def evaluation_suppress_alln(context, evaluation_id, REQUEST, dialog_confirmed=F # modif nb_changed, nb_suppress, existing_decisions = _notes_add( - context, authuser, evaluation_id, notes, comment="effacer tout" + context, current_user, evaluation_id, notes, comment="effacer tout" ) assert nb_changed == nb_suppress H = ["%s notes supprimées
" % nb_suppress] @@ -572,7 +568,7 @@ def saisie_notes_tableur(context, evaluation_id, group_ids=[], REQUEST=None): E = evals[0] M = sco_moduleimpl.do_moduleimpl_list(context, moduleimpl_id=E["moduleimpl_id"])[0] formsemestre_id = M["formsemestre_id"] - if not sco_permissions_check.can_edit_notes(context, authuser, E["moduleimpl_id"]): + if not sco_permissions_check.can_edit_notes(authuser, E["moduleimpl_id"]): return ( html_sco_header.sco_header() + "