From eba7e17628cbe3ed7e0b7e4cb19e84c6836abb52 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Fri, 25 Jun 2021 19:24:12 +0200 Subject: [PATCH] =?UTF-8?q?m=C3=A9thodes=20POST.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/scodoc/sco_abs.py | 1 - app/scodoc/sco_archives.py | 4 +- app/scodoc/sco_archives_etud.py | 6 +- app/scodoc/sco_config.py | 2 +- app/views/notes.py | 140 +++++++++++++++++++++++++------- app/views/scolar.py | 25 ++++-- 6 files changed, 132 insertions(+), 46 deletions(-) diff --git a/app/scodoc/sco_abs.py b/app/scodoc/sco_abs.py index 3b9a8d24e..d4d016733 100644 --- a/app/scodoc/sco_abs.py +++ b/app/scodoc/sco_abs.py @@ -61,7 +61,6 @@ def _isFarFutur(jour): def _toboolean(x): "convert a value to boolean" - assert (x is None) or isinstance(x, types.IntType) # sco8 return bool(x) diff --git a/app/scodoc/sco_archives.py b/app/scodoc/sco_archives.py index d9246ff38..2770bcadf 100644 --- a/app/scodoc/sco_archives.py +++ b/app/scodoc/sco_archives.py @@ -124,7 +124,7 @@ class BaseArchiver: base + "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]-[0-9][0-9]-[0-9][0-9]-[0-9][0-9]" ) - dirs = [os.path.join(base, d) for d in dirs] + dirs = [os.path.join(base, d).encode(scu.SCO_ENCODING) for d in dirs] # sco8 dirs = [d for d in dirs if os.path.isdir(d) and os.listdir(d)] # non empty dirs dirs.sort() return dirs @@ -150,7 +150,7 @@ class BaseArchiver: finally: scu.GSL.release() files.sort() - return [f for f in files if f and f[0] != "_"] + return [f.encode(scu.SCO_ENCODING) for f in files if f and f[0] != "_"] # sco8 def get_archive_name(self, archive_id): """name identifying archive, to be used in web URLs""" diff --git a/app/scodoc/sco_archives_etud.py b/app/scodoc/sco_archives_etud.py index 4671176b3..4ffb41793 100644 --- a/app/scodoc/sco_archives_etud.py +++ b/app/scodoc/sco_archives_etud.py @@ -167,13 +167,13 @@ def etud_upload_file_form(context, REQUEST, etudid): elif tf[0] == -1: return REQUEST.RESPONSE.redirect(scu.NotesURL() + "/ficheEtud?etudid=" + etudid) else: - data = tf[2]["datafile"].read() + data = tf[2]["datafile"][0].read() descr = tf[2]["description"] - filename = tf[2]["datafile"].filename + filename = tf[2]["datafile"][0].filename _store_etud_file_to_new_archive( context, REQUEST, etudid, data, filename, description=descr ) - return REQUEST.RESPONSE.redirect(scu.NotesURL() + "/ficheEtud?etudid=" + etudid) + return REQUEST.RESPONSE.redirect(scu.ScoURL() + "/ficheEtud?etudid=" + etudid) def _store_etud_file_to_new_archive( diff --git a/app/scodoc/sco_config.py b/app/scodoc/sco_config.py index 18ddfb1eb..a6eb1101a 100644 --- a/app/scodoc/sco_config.py +++ b/app/scodoc/sco_config.py @@ -93,7 +93,7 @@ CONFIG.ETABL_FILENAME = "config/etablissements.csv" CONFIG.ALLOW_NULL_PRENOM = False # Taille max des fichiers archive etudiants (en octets) -# CONFIG.ETUD_MAX_FILE_SIZE = 10 * 1024 * 1024 +CONFIG.ETUD_MAX_FILE_SIZE = 10 * 1024 * 1024 # Si pas de photo et portail, publie l'url (était vrai jusqu'en oct 2016) CONFIG.PUBLISH_PORTAL_PHOTO_URL = False diff --git a/app/views/notes.py b/app/views/notes.py index 0b27a9aad..e62a3cce7 100644 --- a/app/views/notes.py +++ b/app/views/notes.py @@ -136,11 +136,9 @@ def sco_publish(route, function, permission, methods=["GET"]): """Declare a route for a python function, protected by permission and called following ScoDoc 7 Zope standards. """ - # f = - bp.route(route, methods=methods)( + return bp.route(route, methods=methods)( permission_required(permission)(scodoc7func(context)(function)) ) - # setattr(sys.modules[__name__], f.__name__, f) # --------------------- Quelques essais élémentaires: @@ -277,14 +275,19 @@ sco_publish( "/formation_create", sco_edit_formation.formation_create, Permission.ScoChangeFormation, + methods=["GET", "POST"], ) sco_publish( "/formation_delete", sco_edit_formation.formation_delete, Permission.ScoChangeFormation, + methods=["GET", "POST"], ) sco_publish( - "/formation_edit", sco_edit_formation.formation_edit, Permission.ScoChangeFormation + "/formation_edit", + sco_edit_formation.formation_edit, + Permission.ScoChangeFormation, + methods=["GET", "POST"], ) sco_publish( "/formsemestre_bulletinetud", @@ -316,9 +319,24 @@ sco_publish( sco_undo_notes.formsemestre_list_saisies_notes, Permission.ScoView, ) -sco_publish("/ue_create", sco_edit_ue.ue_create, Permission.ScoChangeFormation) -sco_publish("/ue_delete", sco_edit_ue.ue_delete, Permission.ScoChangeFormation) -sco_publish("/ue_edit", sco_edit_ue.ue_edit, Permission.ScoChangeFormation) +sco_publish( + "/ue_create", + sco_edit_ue.ue_create, + Permission.ScoChangeFormation, + methods=["GET", "POST"], +) +sco_publish( + "/ue_delete", + sco_edit_ue.ue_delete, + Permission.ScoChangeFormation, + methods=["GET", "POST"], +) +sco_publish( + "/ue_edit", + sco_edit_ue.ue_edit, + Permission.ScoChangeFormation, + methods=["GET", "POST"], +) sco_publish("/ue_list", sco_edit_ue.ue_list, Permission.ScoView) sco_publish("/ue_sharing_code", sco_edit_ue.ue_sharing_code, Permission.ScoView) sco_publish( @@ -335,21 +353,41 @@ sco_publish( Permission.ScoChangeFormation, ) sco_publish( - "/matiere_create", sco_edit_matiere.matiere_create, Permission.ScoChangeFormation + "/matiere_create", + sco_edit_matiere.matiere_create, + Permission.ScoChangeFormation, + methods=["GET", "POST"], ) sco_publish( - "/matiere_delete", sco_edit_matiere.matiere_delete, Permission.ScoChangeFormation + "/matiere_delete", + sco_edit_matiere.matiere_delete, + Permission.ScoChangeFormation, + methods=["GET", "POST"], ) sco_publish( - "/matiere_edit", sco_edit_matiere.matiere_edit, Permission.ScoChangeFormation + "/matiere_edit", + sco_edit_matiere.matiere_edit, + Permission.ScoChangeFormation, + methods=["GET", "POST"], ) sco_publish( - "/module_create", sco_edit_module.module_create, Permission.ScoChangeFormation + "/module_create", + sco_edit_module.module_create, + Permission.ScoChangeFormation, + methods=["GET", "POST"], ) sco_publish( - "/module_delete", sco_edit_module.module_delete, Permission.ScoChangeFormation + "/module_delete", + sco_edit_module.module_delete, + Permission.ScoChangeFormation, + methods=["GET", "POST"], +) +sco_publish( + "/module_edit", + sco_edit_module.module_edit, + Permission.ScoChangeFormation, + methods=["GET", "POST"], ) -sco_publish("/module_edit", sco_edit_module.module_edit, Permission.ScoChangeFormation) sco_publish( "/edit_module_set_code_apogee", sco_edit_module.edit_module_set_code_apogee, @@ -406,12 +444,14 @@ sco_publish( "/do_formation_create", sco_edit_formation.do_formation_create, Permission.ScoChangeFormation, + methods=["GET", "POST"], ) sco_publish( "/do_formation_delete", sco_edit_formation.do_formation_delete, Permission.ScoChangeFormation, + methods=["GET", "POST"], ) @@ -448,7 +488,7 @@ def formation_import_xml(context, file, REQUEST): return sco_formations.formation_import_xml(context, REQUEST, doc) -@bp.route("/formation_import_xml_form") +@bp.route("/formation_import_xml_form", methods=["GET", "POST"]) @permission_required(Permission.ScoChangeFormation) @scodoc7func(context) def formation_import_xml_form(context, REQUEST): @@ -499,6 +539,7 @@ sco_publish( "/do_ue_create", sco_edit_ue.do_ue_create, Permission.ScoChangeFormation, + methods=["GET", "POST"], ) sco_publish( @@ -513,6 +554,7 @@ sco_publish( "/do_matiere_create", sco_edit_matiere.do_matiere_create, Permission.ScoChangeFormation, + methods=["GET", "POST"], ) sco_publish( "/do_matiere_delete", @@ -638,7 +680,7 @@ sco_publish( ) -@bp.route("/formsemestre_custommenu_edit") +@bp.route("/formsemestre_custommenu_edit", methods=["GET", "POST"]) @permission_required(Permission.ScoView) @scodoc7func(context) def formsemestre_custommenu_edit(context, REQUEST, formsemestre_id): @@ -650,7 +692,7 @@ def formsemestre_custommenu_edit(context, REQUEST, formsemestre_id): # --- dialogue modif enseignants/moduleimpl -@bp.route("/edit_enseignants_form") +@bp.route("/edit_enseignants_form", methods=["GET", "POST"]) @permission_required(Permission.ScoView) @scodoc7func(context) def edit_enseignants_form(context, REQUEST, moduleimpl_id): @@ -759,7 +801,7 @@ def edit_enseignants_form(context, REQUEST, moduleimpl_id): return header + "\n".join(H) + tf[1] + F + footer -@bp.route("/edit_moduleimpl_resp") +@bp.route("/edit_moduleimpl_resp", methods=["GET", "POST"]) @permission_required(Permission.ScoView) @scodoc7func(context) def edit_moduleimpl_resp(context, REQUEST, moduleimpl_id): @@ -871,7 +913,7 @@ _EXPR_HELP = """

Expérimental: formule de calcul de la moyenne % """ -@bp.route("/edit_moduleimpl_expr") +@bp.route("/edit_moduleimpl_expr", methods=["GET", "POST"]) @permission_required(Permission.ScoView) @scodoc7func(context) def edit_moduleimpl_expr(context, REQUEST, moduleimpl_id): @@ -1023,7 +1065,7 @@ def view_module_abs(context, REQUEST, moduleimpl_id, format="html"): return "\n".join(H) + tab.html() + html_sco_header.sco_footer(context, REQUEST) -@bp.route("/edit_ue_expr") +@bp.route("/edit_ue_expr", methods=["GET", "POST"]) @permission_required(Permission.ScoView) @scodoc7func(context) def edit_ue_expr(context, REQUEST, formsemestre_id, ue_id): @@ -1181,7 +1223,7 @@ def formsemestre_enseignants_list(context, REQUEST, formsemestre_id, format="htm ) -@bp.route("/edit_enseignants_form_delete") +@bp.route("/edit_enseignants_form_delete", methods=["GET", "POST"]) @permission_required(Permission.ScoView) @scodoc7func(context) def edit_enseignants_form_delete(context, REQUEST, moduleimpl_id, ens_id): @@ -1399,7 +1441,7 @@ sco_publish( # --- Evaluations -@bp.route("/evaluation_delete") +@bp.route("/evaluation_delete", methods=["GET", "POST"]) @permission_required(Permission.ScoEnsView) @scodoc7func(context) def evaluation_delete(context, REQUEST, evaluation_id): @@ -1759,10 +1801,11 @@ sco_publish( "/external_ue_create_form", sco_ue_external.external_ue_create_form, Permission.ScoView, + methods=["GET", "POST"], ) -@bp.route("/appreciation_add_form") +@bp.route("/appreciation_add_form", methods=["GET", "POST"]) @permission_required(Permission.ScoEnsView) @scodoc7func(context) def appreciation_add_form( @@ -2001,10 +2044,11 @@ sco_publish( "/formsemestre_ext_create_form", sco_formsemestre_exterieurs.formsemestre_ext_create_form, Permission.ScoView, + methods=["GET", "POST"], ) -@bp.route("/formsemestre_ext_edit_ue_validations") +@bp.route("/formsemestre_ext_edit_ue_validations", methods=["GET", "POST"]) @permission_required(Permission.ScoView) @scodoc7func(context) def formsemestre_ext_edit_ue_validations( @@ -2181,7 +2225,10 @@ sco_publish( Permission.ScoView, ) sco_publish( - "/formsemestre_archive", sco_archives.formsemestre_archive, Permission.ScoView + "/formsemestre_archive", + sco_archives.formsemestre_archive, + Permission.ScoView, + methods=["GET", "POST"], ) sco_publish( "/formsemestre_delete_archive", @@ -2233,14 +2280,35 @@ sco_publish( # sco_semset sco_publish("/semset_page", sco_semset.semset_page, Permission.ScoEditApo) -sco_publish("/do_semset_create", sco_semset.do_semset_create, Permission.ScoEditApo) -sco_publish("/do_semset_delete", sco_semset.do_semset_delete, Permission.ScoEditApo) sco_publish( - "/edit_semset_set_title", sco_semset.edit_semset_set_title, Permission.ScoEditApo + "/do_semset_create", + sco_semset.do_semset_create, + Permission.ScoEditApo, + methods=["GET", "POST"], ) -sco_publish("/do_semset_add_sem", sco_semset.do_semset_add_sem, Permission.ScoEditApo) sco_publish( - "/do_semset_remove_sem", sco_semset.do_semset_remove_sem, Permission.ScoEditApo + "/do_semset_delete", + sco_semset.do_semset_delete, + Permission.ScoEditApo, + methods=["GET", "POST"], +) +sco_publish( + "/edit_semset_set_title", + sco_semset.edit_semset_set_title, + Permission.ScoEditApo, + methods=["GET", "POST"], +) +sco_publish( + "/do_semset_add_sem", + sco_semset.do_semset_add_sem, + Permission.ScoEditApo, + methods=["GET", "POST"], +) +sco_publish( + "/do_semset_remove_sem", + sco_semset.do_semset_remove_sem, + Permission.ScoEditApo, + methods=["GET", "POST"], ) # sco_export_result @@ -2251,20 +2319,30 @@ sco_publish( ) sco_publish( - "/apo_compare_csv_form", sco_apogee_compare.apo_compare_csv_form, Permission.ScoView + "/apo_compare_csv_form", + sco_apogee_compare.apo_compare_csv_form, + Permission.ScoView, + methods=["GET", "POST"], +) +sco_publish( + "/apo_compare_csv", + sco_apogee_compare.apo_compare_csv, + Permission.ScoView, + methods=["GET", "POST"], ) -sco_publish("/apo_compare_csv", sco_apogee_compare.apo_compare_csv, Permission.ScoView) # ------------- INSCRIPTIONS: PASSAGE D'UN SEMESTRE A UN AUTRE sco_publish( "/formsemestre_inscr_passage", sco_inscr_passage.formsemestre_inscr_passage, Permission.ScoEtudInscrit, + methods=["GET", "POST"], ) sco_publish( "/formsemestre_synchro_etuds", sco_synchro_etuds.formsemestre_synchro_etuds, Permission.ScoView, + methods=["GET", "POST"], ) # ------------- RAPPORTS STATISTIQUES diff --git a/app/views/scolar.py b/app/views/scolar.py index 691e86dfd..b5e36dfa4 100644 --- a/app/views/scolar.py +++ b/app/views/scolar.py @@ -122,11 +122,11 @@ from app.scodoc import sco_etud context = ScoDoc7Context("scolar") -def sco_publish(route, function, permission): +def sco_publish(route, function, permission, methods=["GET"]): """Declare a route for a python function, protected by permission and called following ScoDoc 7 Zope standards. """ - return bp.route(route)( + return bp.route(route, methods=methods)( permission_required(permission)(scodoc7func(context)(function)) ) @@ -192,7 +192,7 @@ def edit_preferences(context, REQUEST): return sco_preferences.get_base_preferences(context).edit(REQUEST=REQUEST) -@bp.route("/formsemestre_edit_preferences") +@bp.route("/formsemestre_edit_preferences", methods=["GET", "POST"]) @permission_required(Permission.ScoView) @scodoc7func(context) def formsemestre_edit_preferences(context, formsemestre_id, REQUEST): @@ -263,7 +263,14 @@ def showEtudLog(context, etudid, format="html", REQUEST=None): # ---------- PAGE ACCUEIL (listes) -------------- -bp.route("/")(sco_publish("/index_html", sco_dept.index_html, Permission.ScoView)) +@bp.route("/") +@bp.route("/index_html") +@permission_required(Permission.ScoView) +@scodoc7func(context) +def index_html(context, REQUEST=None, showcodes=0, showsemtable=0): + return sco_dept.index_html( + context, REQUEST=REQUEST, showcodes=showcodes, showsemtable=showsemtable + ) @bp.route("/rssnews") @@ -439,6 +446,7 @@ sco_publish( "/etud_upload_file_form", sco_archives_etud.etud_upload_file_form, Permission.ScoView, + methods=["GET", "POST"], ) sco_publish( @@ -455,6 +463,7 @@ sco_publish( "/etudarchive_import_files_form", sco_archives_etud.etudarchive_import_files_form, Permission.ScoView, + methods=["GET", "POST"], ) sco_publish( @@ -535,7 +544,7 @@ def doSuppressAnnotation(context, etudid, annotation_id, REQUEST): ) -@bp.route("/formChangeCoordonnees") +@bp.route("/formChangeCoordonnees", methods=["GET", "POST"]) @permission_required(Permission.ScoEtudChangeAdr) @scodoc7func(context) def formChangeCoordonnees(context, etudid, REQUEST): @@ -671,7 +680,7 @@ def etud_photo_orig_page(context, etudid=None, REQUEST=None): return "\n".join(H) -@bp.route("/formChangePhoto") +@bp.route("/formChangePhoto", methods=["GET", "POST"]) @permission_required(Permission.ScoEtudChangeAdr) @scodoc7func(context) def formChangePhoto(context, etudid=None, REQUEST=None): @@ -719,7 +728,7 @@ def formChangePhoto(context, etudid=None, REQUEST=None): elif tf[0] == -1: return REQUEST.RESPONSE.redirect(dest_url) else: - data = tf[2]["photofile"].read() + data = tf[2]["photofile"][0].read() status, diag = sco_photos.store_photo(context, etud, data, REQUEST=REQUEST) if status != 0: return REQUEST.RESPONSE.redirect(dest_url) @@ -1810,7 +1819,7 @@ def import_generate_admission_sample(context, REQUEST, formsemestre_id): # --- Données admission depuis fichier excel (version nov 2016) -@bp.route("/form_students_import_infos_admissions") +@bp.route("/form_students_import_infos_admissions", methods=["GET", "POST"]) @permission_required(Permission.ScoView) @scodoc7func(context) def form_students_import_infos_admissions(context, REQUEST, formsemestre_id=None):