From 18ae5c327d1a1e069e4350c27b3f09b82c130a57 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Thu, 1 Feb 2018 07:34:20 +0100 Subject: add survey stats --- talersurvey/survey/survey.py | 21 +++++++++++++++++++++ talersurvey/survey/templates/base.html | 9 +-------- talersurvey/survey/templates/index.html | 2 +- talersurvey/survey/templates/survey_stats.html | 15 +++++++++++++++ 4 files changed, 38 insertions(+), 9 deletions(-) create mode 100644 talersurvey/survey/templates/survey_stats.html (limited to 'talersurvey/survey') diff --git a/talersurvey/survey/survey.py b/talersurvey/survey/survey.py index c5b796c..c5b72b5 100644 --- a/talersurvey/survey/survey.py +++ b/talersurvey/survey/survey.py @@ -76,12 +76,33 @@ def backend_post(endpoint, json): return response_json +def backend_get(endpoint, params): + headers = {"Authorization": "ApiKey " + APIKEY} + try: + resp = requests.get(urljoin(BACKEND_URL, endpoint), params=params, headers=headers) + except requests.ConnectionError: + err_abort(500, message="Could not establish connection to backend") + try: + response_json = resp.json() + except ValueError: + err_abort(500, message="Could not parse response from backend") + if resp.status_code != 200: + err_abort(500, message="Backend returned error status", + json=response_json, status_code=resp.status_code) + return response_json + + @app.errorhandler(Exception) def internal_error(e): return flask.render_template("templates/error.html", message="Internal error", stack=traceback.format_exc()) +@app.route("/survey-stats", methods=["GET"]) +def survey_stats(e): + stats = backend_get("tip-query", instance="default") + return flask.render_template("survey_stats.html", stats=stats) + @app.route("/submit-survey", methods=["POST"]) def submit_survey(): diff --git a/talersurvey/survey/templates/base.html b/talersurvey/survey/templates/base.html index 849c53d..bc36c08 100644 --- a/talersurvey/survey/templates/base.html +++ b/talersurvey/survey/templates/base.html @@ -40,14 +40,7 @@
- - - +

Taler Surve Demo

{% block main %} This is the main content of the page. {% endblock %} diff --git a/talersurvey/survey/templates/index.html b/talersurvey/survey/templates/index.html index f40c235..e1ca8ce 100644 --- a/talersurvey/survey/templates/index.html +++ b/talersurvey/survey/templates/index.html @@ -4,7 +4,7 @@

In this page, you can participate in our survey about payment systems - and get a nice tip - via your Taler wallet - from this shop! + and get a nice tip - via your Taler wallet - from this shop! (surve stats)

diff --git a/talersurvey/survey/templates/survey_stats.html b/talersurvey/survey/templates/survey_stats.html new file mode 100644 index 0000000..62c77dd --- /dev/null +++ b/talersurvey/survey/templates/survey_stats.html @@ -0,0 +1,15 @@ +{% extends "templates/base.html" %} + +{% block main %} +
+

This page shows information about the tipping configuration of the + merchant. Usually this should not be visible to users.

+
    +
  • Reserve pub: {{ stats['reserve_pub'] }}
  • +
  • Reserve expiration: {{ stats['reserve_expiration'] }}
  • +
  • Amount available {{ stats['amount_available'] }}
  • +
  • Amount picked up {{ stats['amount_picked_up'] }}
  • +
  • Amount authorized {{ stats['amount_authorized'] }}
  • +
      +
+{% endblock %} -- cgit v1.2.3