1
0
forked from ScoDoc/ScoDoc

fix decorator for GET forms

This commit is contained in:
Emmanuel Viennet 2021-07-12 22:38:30 +02:00
parent 0ec41c48f3
commit 6847bb8fd5
7 changed files with 59 additions and 12 deletions

View File

@ -62,7 +62,14 @@ class ZRequest(object):
if k.endswith(":list"): if k.endswith(":list"):
self.form[k[:-5]] = request.form.getlist(k) self.form[k[:-5]] = request.form.getlist(k)
elif request.method == "GET": 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() self.RESPONSE = ZResponse()
def __str__(self): def __str__(self):

View File

@ -45,7 +45,7 @@ except ImportError:
import flask import flask
from flask import request, render_template, redirect from flask import request, render_template, redirect
from flask_login import login_required from flask_login import login_required
import werkzeug
from app.main import bp from app.main import bp
from app.decorators import scodoc7func, admin_required from app.decorators import scodoc7func, admin_required
@ -65,7 +65,11 @@ context = None # temporaire pour #sco8
@bp.route("/index") @bp.route("/index")
def index(): def index():
return render_template( 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,
) )

View File

@ -455,7 +455,9 @@ def _notes_add(context, uid, evaluation_id, notes, comment=None, do_it=True):
Return number of changed notes Return number of changed notes
""" """
uid = str(uid) 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 # Verifie inscription et valeur note
_ = {}.fromkeys( _ = {}.fromkeys(
sco_groups.do_evaluation_listeetuds_groups( sco_groups.do_evaluation_listeetuds_groups(
@ -1194,6 +1196,7 @@ def _form_saisie_notes(context, E, M, group_ids, destination="", REQUEST=None):
initvalues=initvalues, initvalues=initvalues,
submitlabel="Terminer", submitlabel="Terminer",
formid="formnotes", formid="formnotes",
method="GET",
) )
H.append(tf.getform()) # check and init H.append(tf.getform()) # check and init
if tf.canceled(): if tf.canceled():

View File

@ -537,10 +537,6 @@ def sendPDFFile(REQUEST, data, filename):
class ScoDocJSONEncoder(json.JSONEncoder): class ScoDocJSONEncoder(json.JSONEncoder):
def default(self, o): # pylint: disable=E0202 def default(self, o): # pylint: disable=E0202
# ScoDoc 7.22 n'utilise plus mx:
if str(type(o)) == "<type 'mx.DateTime.DateTime'>":
log("Warning: mx.DateTime object detected !")
return o.strftime("%Y-%m-%dT%H:%M:%S")
if isinstance(o, (datetime.date, datetime.datetime)): if isinstance(o, (datetime.date, datetime.datetime)):
return o.isoformat() return o.isoformat()
elif isinstance(o, ApoEtapeVDI): elif isinstance(o, ApoEtapeVDI):
@ -550,7 +546,7 @@ class ScoDocJSONEncoder(json.JSONEncoder):
def sendJSON(REQUEST, data): 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: if REQUEST:
REQUEST.RESPONSE.setHeader("content-type", JSON_MIMETYPE) REQUEST.RESPONSE.setHeader("content-type", JSON_MIMETYPE)
return js return js

View File

@ -0,0 +1,25 @@
{% extends 'base.html' %}
{% block app_content %}
<h1>Essai checkbox</h1>
<p>
<tt>request.args={{ request.args }}</tt>
</p>
<form method="get">
<fieldset>
<legend>Choose your interests</legend>
<div>
<input type="checkbox" id="coding" name="interest" value="coding">
<label for="coding">Coding</label>
</div>
<div>
<input type="checkbox" id="music" name="interest" value="music">
<label for="music">Music</label>
</div>
</fieldset>
<input type="submit" name="OK" />
</form>
{% endblock %}

View File

@ -12,6 +12,10 @@
<h2>Essais divers</h2> <h2>Essais divers</h2>
<p>
<tt>flask v{{ flask.__version__ }}</tt><br />
<tt>werzeug v{{ werzeug.__version__ }}</tt>
</p>
<h3>Avec login requis</h3> <h3>Avec login requis</h3>
<ul> <ul>
<li><a href="{{ url_for('main.test_vue') }}"><tt>test_vue</tt>, login requis</a></li> <li><a href="{{ url_for('main.test_vue') }}"><tt>test_vue</tt>, login requis</a></li>

View File

@ -5,8 +5,12 @@ Module Essais: divers essais pour la migration vers Flask
Emmanuel Viennet, 2021 Emmanuel Viennet, 2021
""" """
import flask
from flask import g from flask import g
from flask import current_app from flask import current_app
from flask import render_template
from flask import request
from app.decorators import ( from app.decorators import (
scodoc7func, scodoc7func,
@ -79,9 +83,13 @@ def sco_test_view(REQUEST=None):
return """Vous avez vu sco_test_view !""" return """Vous avez vu sco_test_view !"""
import flask
@bp.route("/essrep") @bp.route("/essrep")
def essrep(): def essrep():
return flask.Response(status=200, response="Bonjour pépé %s" + u"papa") return flask.Response(status=200, response="Bonjour pépé %s" + u"papa")
# Tests formulaires avec checkbox et GET
@bp.route("/testcheckbox", methods=["GET"])
def testcheckbox():
# args = request.args
return render_template("essais/testcheckbox.html")