From 483df704655fee666fa1b07b1590a9130305b308 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Sun, 15 Aug 2021 22:08:38 +0200 Subject: [PATCH] Fix: url_for --- app/scodoc/pe_tools.py | 2 +- app/scodoc/sco_evaluations.py | 12 +++++++++--- app/scodoc/sco_formsemestre_custommenu.py | 9 +++++---- app/scodoc/sco_formsemestre_status.py | 12 ++++++++++-- app/scodoc/sco_groups.py | 8 +++++++- app/views/notes.py | 20 ++++++++++---------- misc/example-api-1.py | 7 ++++++- 7 files changed, 48 insertions(+), 22 deletions(-) diff --git a/app/scodoc/pe_tools.py b/app/scodoc/pe_tools.py index f119d26c3..278d8e2be 100644 --- a/app/scodoc/pe_tools.py +++ b/app/scodoc/pe_tools.py @@ -87,7 +87,7 @@ def print_semestres_description(sems, avec_affichage_debug=False): + sem["anneescolaire"] ) desc += " (" + sem["annee_debut"] + "/" + sem["annee_fin"] + ") " - desc += str(sem["formation_id"]) + " / " + sem["formsemestre_id"] + desc += str(sem["formation_id"]) + " / " + str(sem["formsemestre_id"]) desc += " - " + sem["titre_num"] return desc diff --git a/app/scodoc/sco_evaluations.py b/app/scodoc/sco_evaluations.py index b12b5dba2..7228a4f9e 100644 --- a/app/scodoc/sco_evaluations.py +++ b/app/scodoc/sco_evaluations.py @@ -883,15 +883,21 @@ def formsemestre_evaluations_delai_correction( e["delai_correction"] = None e["module_code"] = Mod["code"] - e["_module_code_target"] = ( - "moduleimpl_status?moduleimpl_id=" + M["moduleimpl_id"] + e["_module_code_target"] = url_for( + "notes.moduleimpl_status", + scodoc_dept=g.scodoc_dept, + moduleimpl_id=M["moduleimpl_id"], ) e["module_titre"] = Mod["titre"] e["responsable_id"] = M["responsable_id"] e["responsable_nomplogin"] = sco_users.user_info(M["responsable_id"])[ "nomplogin" ] - e["_jour_target"] = "evaluation_listenotes?evaluation_id=" + e["evaluation_id"] + e["_jour_target"] = url_for( + "notes.evaluation_listenotes", + scodoc_dept=g.scodoc_dept, + evaluation_id=e["evaluation_id"], + ) T.append(e) columns_ids = ( diff --git a/app/scodoc/sco_formsemestre_custommenu.py b/app/scodoc/sco_formsemestre_custommenu.py index 4bd042e7d..dc039057f 100644 --- a/app/scodoc/sco_formsemestre_custommenu.py +++ b/app/scodoc/sco_formsemestre_custommenu.py @@ -28,6 +28,7 @@ """Menu "custom" (défini par l'utilisateur) dans les semestres """ import flask +from flask import g, url_for import app.scodoc.sco_utils as scu import app.scodoc.notesdb as ndb @@ -105,18 +106,18 @@ def formsemestre_custommenu_edit(context, formsemestre_id, REQUEST=None): for item in menu: descr.append( ( - "title_" + item["custommenu_id"], + "title_" + str(item["custommenu_id"]), {"size": 40, "template": '%(elem)s'}, ) ) descr.append( ( - "url_" + item["custommenu_id"], + "url_" + str(item["custommenu_id"]), {"size": 80, "template": '%(elem)s'}, ) ) - initvalues["title_" + item["custommenu_id"]] = item["title"] - initvalues["url_" + item["custommenu_id"]] = item["url"] + initvalues["title_" + str(item["custommenu_id"])] = item["title"] + initvalues["url_" + str(item["custommenu_id"])] = item["url"] tf = TrivialFormulator( REQUEST.URL0, REQUEST.form, diff --git a/app/scodoc/sco_formsemestre_status.py b/app/scodoc/sco_formsemestre_status.py index 0780102a7..a60a66cf0 100644 --- a/app/scodoc/sco_formsemestre_status.py +++ b/app/scodoc/sco_formsemestre_status.py @@ -651,8 +651,16 @@ def formsemestre_description_table( "Coef.": M["module"]["coefficient"], # 'ECTS' : M['module']['ects'], # Lien sur titre -> module - "_Module_target": "moduleimpl_status?moduleimpl_id=" + M["moduleimpl_id"], - "_Code_target": "moduleimpl_status?moduleimpl_id=" + M["moduleimpl_id"], + "_Module_target": url_for( + "notes.moduleimpl_status", + scodoc_dept=g.scodoc_dept, + moduleimpl_id=M["moduleimpl_id"], + ), + "_Code_target": url_for( + "notes.moduleimpl_status", + scodoc_dept=g.scodoc_dept, + moduleimpl_id=M["moduleimpl_id"], + ), } R.append(l) if M["module"]["coefficient"]: diff --git a/app/scodoc/sco_groups.py b/app/scodoc/sco_groups.py index 0cd8ce48f..838ba0107 100644 --- a/app/scodoc/sco_groups.py +++ b/app/scodoc/sco_groups.py @@ -1222,7 +1222,13 @@ def group_rename(context, group_id, REQUEST=None): + html_sco_header.sco_footer() ) elif tf[0] == -1: - return flask.redirect("affectGroups?partition_id=" + group["partition_id"]) + return flask.redirect( + url_for( + "scolar.affectGroups", + scodoc_dept=g.scodoc_dept, + partition_id=group["partition_id"], + ) + ) else: # form submission return group_set_name( diff --git a/app/views/notes.py b/app/views/notes.py index 198c5c2e4..606fa5233 100644 --- a/app/views/notes.py +++ b/app/views/notes.py @@ -1494,21 +1494,21 @@ def evaluation_delete(context, REQUEST, evaluation_id): return "\n".join(H) + tf[1] + html_sco_header.sco_footer() elif tf[0] == -1: return flask.redirect( - scu.ScoURL() - + "/Notes/moduleimpl_status?moduleimpl_id=" - + E["moduleimpl_id"] + url_for( + "notes.moduleimpl_status", + scodoc_dept=g.scodoc_dept, + moduleimpl_id=E["moduleimpl_id"], + ) ) else: sco_evaluations.do_evaluation_delete(E["evaluation_id"]) return ( "\n".join(H) - + """

OK, évaluation supprimée.

-

Continuer

""" - % ( - scu.ScoURL() - + "/Notes/moduleimpl_status?moduleimpl_id=" - + E["moduleimpl_id"] - ) + + f"""

OK, évaluation supprimée.

+

Continuer

""" + html_sco_header.sco_footer() ) diff --git a/misc/example-api-1.py b/misc/example-api-1.py index 18b2b523e..d823aac7c 100644 --- a/misc/example-api-1.py +++ b/misc/example-api-1.py @@ -17,6 +17,7 @@ import requests import urllib3 import pdb from pprint import pprint as pp +from flask import g, url_for # A modifier pour votre serveur: CHECK_CERTIFICATE = False # set to True in production @@ -108,7 +109,11 @@ print( ) print( "Pour vérifier, aller sur: ", - BASEURL + "/Notes/moduleimpl_status?moduleimpl_id=" + mod["moduleimpl_id"], + url_for( + "notes.moduleimpl_status", + scodoc_dept="DEPT", + moduleimpl_id=mod["moduleimpl_id"], + ), ) # ---- Saisie d'une note