From 6847bb8fd52da299a45b6f3dfdfef62ee6c78795 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Mon, 12 Jul 2021 22:38:30 +0200 Subject: [PATCH] fix decorator for GET forms --- app/decorators.py | 9 ++++++++- app/main/routes.py | 8 ++++++-- app/scodoc/sco_saisie_notes.py | 5 ++++- app/scodoc/sco_utils.py | 6 +----- app/templates/essais/testcheckbox.html | 25 +++++++++++++++++++++++++ app/templates/main/index.html | 4 ++++ app/views/essais.py | 14 +++++++++++--- 7 files changed, 59 insertions(+), 12 deletions(-) create mode 100644 app/templates/essais/testcheckbox.html diff --git a/app/decorators.py b/app/decorators.py index a9c67fc5e4..cc637f81e4 100644 --- a/app/decorators.py +++ b/app/decorators.py @@ -62,7 +62,14 @@ class ZRequest(object): if k.endswith(":list"): self.form[k[:-5]] = request.form.getlist(k) elif request.method == "GET": - self.form = {k: v for (k, v) in request.args.items()} + self.form = {} + for k in request.args: + current_app.logger.debug("%s\t%s" % (k, request.args.getlist(k))) + if k.endswith(":list"): + self.form[k[:-5]] = request.args.getlist(k) + else: + self.form[k] = request.args[k] + current_app.logger.info("ZRequest.form=%s" % str(self.form)) self.RESPONSE = ZResponse() def __str__(self): diff --git a/app/main/routes.py b/app/main/routes.py index 093ad7758e..89264112cc 100644 --- a/app/main/routes.py +++ b/app/main/routes.py @@ -45,7 +45,7 @@ except ImportError: import flask from flask import request, render_template, redirect from flask_login import login_required - +import werkzeug from app.main import bp from app.decorators import scodoc7func, admin_required @@ -65,7 +65,11 @@ context = None # temporaire pour #sco8 @bp.route("/index") def index(): return render_template( - "main/index.html", title=u"Essai Flask", current_app=flask.current_app + "main/index.html", + title=u"Essai Flask", + current_app=flask.current_app, + flask=flask, + werzeug=werkzeug, ) diff --git a/app/scodoc/sco_saisie_notes.py b/app/scodoc/sco_saisie_notes.py index 08101e1228..80ee1a56f2 100644 --- a/app/scodoc/sco_saisie_notes.py +++ b/app/scodoc/sco_saisie_notes.py @@ -455,7 +455,9 @@ def _notes_add(context, uid, evaluation_id, notes, comment=None, do_it=True): Return number of changed notes """ uid = str(uid) - now = psycopg2.Timestamp(*time.localtime()[:6]) # datetime.datetime.now().isoformat() + now = psycopg2.Timestamp( + *time.localtime()[:6] + ) # datetime.datetime.now().isoformat() # Verifie inscription et valeur note _ = {}.fromkeys( sco_groups.do_evaluation_listeetuds_groups( @@ -1194,6 +1196,7 @@ def _form_saisie_notes(context, E, M, group_ids, destination="", REQUEST=None): initvalues=initvalues, submitlabel="Terminer", formid="formnotes", + method="GET", ) H.append(tf.getform()) # check and init if tf.canceled(): diff --git a/app/scodoc/sco_utils.py b/app/scodoc/sco_utils.py index cae6f53a68..c78f2084c7 100644 --- a/app/scodoc/sco_utils.py +++ b/app/scodoc/sco_utils.py @@ -537,10 +537,6 @@ def sendPDFFile(REQUEST, data, filename): class ScoDocJSONEncoder(json.JSONEncoder): def default(self, o): # pylint: disable=E0202 - # ScoDoc 7.22 n'utilise plus mx: - if str(type(o)) == "": - log("Warning: mx.DateTime object detected !") - return o.strftime("%Y-%m-%dT%H:%M:%S") if isinstance(o, (datetime.date, datetime.datetime)): return o.isoformat() elif isinstance(o, ApoEtapeVDI): @@ -550,7 +546,7 @@ class ScoDocJSONEncoder(json.JSONEncoder): def sendJSON(REQUEST, data): - js = json.dumps(data, encoding=SCO_ENCODING, indent=1, cls=ScoDocJSONEncoder) + js = json.dumps(data, indent=1, cls=ScoDocJSONEncoder) if REQUEST: REQUEST.RESPONSE.setHeader("content-type", JSON_MIMETYPE) return js diff --git a/app/templates/essais/testcheckbox.html b/app/templates/essais/testcheckbox.html new file mode 100644 index 0000000000..5bd3e339e6 --- /dev/null +++ b/app/templates/essais/testcheckbox.html @@ -0,0 +1,25 @@ +{% extends 'base.html' %} + +{% block app_content %} + +

Essai checkbox

+ +

+ request.args={{ request.args }} +

+
+
+ Choose your interests +
+ + +
+
+ + +
+
+ +
+ +{% endblock %} \ No newline at end of file diff --git a/app/templates/main/index.html b/app/templates/main/index.html index ac9bcebf98..a09a0ab0fa 100644 --- a/app/templates/main/index.html +++ b/app/templates/main/index.html @@ -12,6 +12,10 @@

Essais divers

+

+ flask v{{ flask.__version__ }}
+ werzeug v{{ werzeug.__version__ }} +

Avec login requis