From 8fedde52e70360bf406915b32760675a036e4fed Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Thu, 29 Jul 2021 17:31:15 +0300 Subject: [PATCH] refactoring: removing useless args for Flask --- app/scodoc/gen_tables.py | 2 - app/scodoc/html_sco_header.py | 29 +- app/scodoc/html_sidebar.py | 61 ++-- app/scodoc/pe_view.py | 4 +- app/scodoc/sco_abs_views.py | 22 +- app/scodoc/sco_apogee_compare.py | 8 +- app/scodoc/sco_archives.py | 10 +- app/scodoc/sco_archives_etud.py | 4 +- app/scodoc/sco_bulletins.py | 30 +- app/scodoc/sco_cost_formation.py | 2 +- app/scodoc/sco_debouche.py | 28 +- app/scodoc/sco_dept.py | 12 +- app/scodoc/sco_dump_db.py | 4 +- app/scodoc/sco_edit_formation.py | 12 +- app/scodoc/sco_edit_matiere.py | 12 +- app/scodoc/sco_edit_module.py | 12 +- app/scodoc/sco_edit_ue.py | 6 +- app/scodoc/sco_edt_cal.py | 2 - app/scodoc/sco_etape_apogee.py | 2 +- app/scodoc/sco_etape_apogee_view.py | 8 +- app/scodoc/sco_evaluations.py | 13 +- app/scodoc/sco_export_results.py | 2 - app/scodoc/sco_find_etud.py | 4 +- app/scodoc/sco_formsemestre.py | 12 +- app/scodoc/sco_formsemestre_edit.py | 15 +- app/scodoc/sco_formsemestre_exterieurs.py | 8 +- app/scodoc/sco_formsemestre_inscriptions.py | 8 +- app/scodoc/sco_formsemestre_status.py | 130 ++++----- app/scodoc/sco_formsemestre_validation.py | 6 +- app/scodoc/sco_groups.py | 83 +++--- app/scodoc/sco_groups_edit.py | 6 +- app/scodoc/sco_groups_view.py | 16 +- app/scodoc/sco_import_etuds.py | 12 +- app/scodoc/sco_inscr_passage.py | 4 +- app/scodoc/sco_liste_notes.py | 2 +- app/scodoc/sco_lycee.py | 4 - app/scodoc/sco_moduleimpl_inscriptions.py | 2 - app/scodoc/sco_moduleimpl_status.py | 8 +- app/scodoc/sco_page_etud.py | 13 +- app/scodoc/sco_permissions_check.py | 56 ++-- app/scodoc/sco_placement.py | 2 +- app/scodoc/sco_poursuite_dut.py | 2 +- app/scodoc/sco_preferences.py | 2 +- app/scodoc/sco_pvjury.py | 6 +- app/scodoc/sco_recapcomplet.py | 4 +- app/scodoc/sco_report.py | 8 +- app/scodoc/sco_saisie_notes.py | 18 +- app/scodoc/sco_semset.py | 6 +- app/scodoc/sco_synchro_etuds.py | 8 +- app/scodoc/sco_trombino.py | 10 +- app/scodoc/sco_users.py | 2 - app/scodoc/sco_utils.py | 4 +- app/views/absences.py | 12 +- app/views/entreprises.py | 5 +- app/views/notes.py | 40 +-- app/views/scolar.py | 31 +- app/views/users.py | 8 +- scotests/sco_fake_gen.py | 2 +- scotests/test_absence.py | 4 +- scotests/test_absence2.py | 4 +- scotests/test_api7doc.py | 214 +++++++++----- scotests/test_groupes.py | 303 ++++++++++++-------- tests/unit/test_caches.py | 7 +- 63 files changed, 633 insertions(+), 743 deletions(-) diff --git a/app/scodoc/gen_tables.py b/app/scodoc/gen_tables.py index 078017e8c..3791c8142 100644 --- a/app/scodoc/gen_tables.py +++ b/app/scodoc/gen_tables.py @@ -628,8 +628,6 @@ class GenTable(object): H.append( self.html_header or html_sco_header.sco_header( - context, - REQUEST, page_title=page_title, javascripts=javascripts, init_qtip=init_qtip, diff --git a/app/scodoc/html_sco_header.py b/app/scodoc/html_sco_header.py index 2401ee7cb..7381cc734 100644 --- a/app/scodoc/html_sco_header.py +++ b/app/scodoc/html_sco_header.py @@ -30,6 +30,8 @@ import html +from flask import g +from flask import request from flask_login import current_user import app.scodoc.sco_utils as scu @@ -136,10 +138,7 @@ def scodoc_top_html_header(page_title="ScoDoc: bienvenue"): # Header: def sco_header( - context, - REQUEST=None, # optional args - container=None, # objet qui a lancé la demande page_title="", # page title no_side_bar=False, # hide sidebar cssstyles=[], # additionals CSS sheets @@ -159,15 +158,13 @@ def sco_header( from app.scodoc.sco_formsemestre_status import formsemestre_page_title context = None # XXX TODO à enlever #context - # context est une instance de ZScolar. container est une instance qui "acquiert" ZScolar - # Add a HTTP header (can be used by Apache to log requests) - if REQUEST.AUTHENTICATED_USER: - REQUEST.RESPONSE.setHeader("X-ScoDoc-User", str(REQUEST.AUTHENTICATED_USER)) - - # Get more parameters from REQUEST - if not head_message and "head_message" in REQUEST.form: - head_message = REQUEST.form["head_message"] + # Get head message from http request: + if not head_message: + if request.method == "POST": + head_message = request.form.get("head_message", "") + elif request.method == "GET": + head_message = request.args.get("head_message", "") params = { "page_title": page_title or VERSION.SCONAME, @@ -175,7 +172,7 @@ def sco_header( "ScoURL": scu.ScoURL(), "encoding": scu.SCO_ENCODING, "titrebandeau_mkup": "" + titrebandeau + "", - "authuser": str(REQUEST.AUTHENTICATED_USER), + "authuser": current_user.user_name, } if bodyOnLoad: params["bodyOnLoad_mkup"] = """onload="%s" """ % bodyOnLoad @@ -307,11 +304,11 @@ def sco_header( H.append(scu.CUSTOM_HTML_HEADER) # if not no_side_bar: - H.append(html_sidebar.sidebar(REQUEST)) + H.append(html_sidebar.sidebar()) H.append("""
""") # # Barre menu semestre: - H.append(formsemestre_page_title(context, REQUEST)) + H.append(formsemestre_page_title(context)) # Avertissement si mot de passe à changer if user_check: @@ -354,9 +351,7 @@ def html_sem_header( "Titre d'une page semestre avec lien vers tableau de bord" # sem now unused and thus optional... if with_page_header: - h = sco_header( - context, REQUEST, page_title="%s" % (page_title or title), **args - ) + h = sco_header(page_title="%s" % (page_title or title), **args) else: h = "" if with_h2: diff --git a/app/scodoc/html_sidebar.py b/app/scodoc/html_sidebar.py index a172df4f0..8bcdb487f 100644 --- a/app/scodoc/html_sidebar.py +++ b/app/scodoc/html_sidebar.py @@ -28,30 +28,32 @@ """ Génération de la "sidebar" (marge gauche des pages HTML) """ -from flask import url_for, g +from flask import url_for +from flask import g +from flask import request +from flask_login import current_user import app.scodoc.sco_utils as scu from app.scodoc import sco_preferences from app.scodoc.sco_permissions import Permission -def sidebar_common(REQUEST=None): +def sidebar_common(): "partie commune à toutes les sidebar" - authuser = REQUEST.AUTHENTICATED_USER params = { "ScoURL": scu.ScoURL(), "UsersURL": scu.UsersURL(), "NotesURL": scu.NotesURL(), "AbsencesURL": scu.AbsencesURL(), "LogoutURL": url_for("auth.logout"), - "authuser": str(authuser), + "authuser": current_user.user_name, } H = [ 'ScoDoc 8', '' % params, - sidebar_dept(REQUEST), - """

Scolarité

+ sidebar_dept(), + """

Scolarité

Semestres
Programmes
Absences
@@ -59,14 +61,14 @@ def sidebar_common(REQUEST=None): % params, ] - if authuser.has_permission(Permission.ScoUsersAdmin) or authuser.has_permission( - Permission.ScoUsersView - ): + if current_user.has_permission( + Permission.ScoUsersAdmin + ) or current_user.has_permission(Permission.ScoUsersView): H.append( """Utilisateurs
""" % params ) - if authuser.has_permission(Permission.ScoChangePreferences): + if current_user.has_permission(Permission.ScoChangePreferences): H.append( """Paramétrage
""" % params @@ -75,7 +77,7 @@ def sidebar_common(REQUEST=None): return "".join(H) -def sidebar(REQUEST=None): +def sidebar(): "Main HTML page sidebar" # rewritten from legacy DTML code from app.scodoc import sco_abs @@ -86,7 +88,7 @@ def sidebar(REQUEST=None): "SCO_USER_MANUAL": scu.SCO_USER_MANUAL, } - H = ['