gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [taler-survey] branch master updated: add /pick endpoint


From: gnunet
Subject: [GNUnet-SVN] [taler-survey] branch master updated: add /pick endpoint
Date: Tue, 21 Nov 2017 17:49:52 +0100

This is an automated email from the git hooks/post-receive script.

marcello pushed a commit to branch master
in repository survey.

The following commit(s) were added to refs/heads/master by this push:
     new febb6d9  add /pick endpoint
febb6d9 is described below

commit febb6d9dc9e1692b686e17215ebef3c5a1a79f68
Author: Marcello Stanisci <address@hidden>
AuthorDate: Tue Nov 21 17:49:37 2017 +0100

    add /pick endpoint
---
 talersurvey/survey/survey.py            | 22 +++++++++++++++++-----
 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)
 
address@hidden("/")
-def index():
-    return flask.render_template("templates/index.html", 
merchant_currency=CURRENCY)
address@hidden("/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())
 
address@hidden("/survey", methods=["GET", "POST"])
address@hidden("/", 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>

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]