diff options
author | Marcello Stanisci <stanisci.m@gmail.com> | 2017-11-21 17:49:37 +0100 |
---|---|---|
committer | Marcello Stanisci <stanisci.m@gmail.com> | 2017-11-21 17:49:37 +0100 |
commit | febb6d9dc9e1692b686e17215ebef3c5a1a79f68 (patch) | |
tree | 6060996078c734a71533323774356a824d2ce977 | |
parent | 054d9d0f6eaca6c90cc576d568066464d0040003 (diff) | |
download | survey-febb6d9dc9e1692b686e17215ebef3c5a1a79f68.tar.gz survey-febb6d9dc9e1692b686e17215ebef3c5a1a79f68.tar.bz2 survey-febb6d9dc9e1692b686e17215ebef3c5a1a79f68.zip |
add /pick endpoint
-rw-r--r-- | talersurvey/survey/survey.py | 22 | ||||
-rw-r--r-- | talersurvey/survey/templates/index.html | 2 |
2 files changed, 18 insertions, 6 deletions
diff --git a/talersurvey/survey/survey.py b/talersurvey/survey/survey.py index 8697ddf..dd68bca 100644 --- a/talersurvey/survey/survey.py +++ b/talersurvey/survey/survey.py @@ -66,12 +66,22 @@ def utility_processor(): return os.environ.get(name, default) return dict(url=url, env=env) -@app.route("/") -def index(): - return flask.render_template("templates/index.html", merchant_currency=CURRENCY) +@app.route("/pick", methods=["POST"]) +def pick(): + body = flask.request.get_json() + # Let the backend complain! + body["tip_id"] = flask.request.args.get("tip_id") + r = requests.post(urljoin(BACKEND_URL, 'tip-pickup'), + json=body) + if 200 != r.status_code: + return backend_error(r) + else: + return flask.jsonify(r.json()) -@app.route("/survey", methods=["GET", "POST"]) +@app.route("/", methods=["GET", "POST"]) def survey(): + if flask.request.method == "GET": + return flask.render_template("templates/index.html", merchant_currency=CURRENCY) success = False amount = Amount(CURRENCY, 1) if flask.request.method == "POST": @@ -85,7 +95,9 @@ def survey(): success = True response = flask.make_response(flask.render_template("templates/index.html", success=success), 402) - response.headers["X-Taler-Tipping-Url"] = "%s/%s?id=%s" % (flask.request.script_root, "pick", r.json().get("tip_id")) + response.headers["X-Taler-Tipping-Url"] = urljoin( + flask.request.base_url, + flask.url_for("pick", tip_id=r.json().get("tip_id"))) response.headers["X-Taler-Tipping-Exchange"] = r.json().get("exchange_uri") response.headers["X-Taler-Tipping-Amount"] = amount.stringify(2) response.headers["X-Taler-Tipping-Deadline"] = r.json().get("expiration") diff --git a/talersurvey/survey/templates/index.html b/talersurvey/survey/templates/index.html index ffb871e..28057c2 100644 --- a/talersurvey/survey/templates/index.html +++ b/talersurvey/survey/templates/index.html @@ -8,7 +8,7 @@ </p> </div> <div> - <form action="{{ url('/survey') }}" method="post"> + <form action="{{ url('/') }}" method="post"> {% if success %} <strong>Congratulations, your reward has been successfully submitted!</strong> <br> |