summaryrefslogtreecommitdiff
path: root/talersurvey
diff options
context:
space:
mode:
Diffstat (limited to 'talersurvey')
-rw-r--r--talersurvey/survey/survey.py22
-rw-r--r--talersurvey/survey/templates/index.html2
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>