diff options
author | Florian Dold <florian.dold@gmail.com> | 2018-01-16 13:27:14 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2018-01-16 13:27:14 +0100 |
commit | 27414f7f097d4e878bdb279ad7d41f6cdcbc2eb7 (patch) | |
tree | 9f75ea4608d74d148c5c7fa4e40934e02801a5c5 /talerblog | |
parent | bde92720a2bc83ff2f5a4322e5239dcaff52e666 (diff) | |
download | blog-27414f7f097d4e878bdb279ad7d41f6cdcbc2eb7.tar.gz blog-27414f7f097d4e878bdb279ad7d41f6cdcbc2eb7.tar.bz2 blog-27414f7f097d4e878bdb279ad7d41f6cdcbc2eb7.zip |
no need for custom URL helpers
Diffstat (limited to 'talerblog')
-rw-r--r-- | talerblog/blog/blog.py | 5 | ||||
-rw-r--r-- | talerblog/blog/templates/base.html | 12 | ||||
-rw-r--r-- | talerblog/helpers.py | 79 |
3 files changed, 7 insertions, 89 deletions
diff --git a/talerblog/blog/blog.py b/talerblog/blog/blog.py index 9894a34..9c88e81 100644 --- a/talerblog/blog/blog.py +++ b/talerblog/blog/blog.py @@ -29,7 +29,6 @@ import base64 import requests import flask from talerblog.talerconfig import TalerConfig -from ..helpers import join_urlparts from ..blog.content import ARTICLES, get_article_file, get_image_file @@ -50,11 +49,9 @@ app.config.from_object(__name__) @app.context_processor def utility_processor(): # These helpers will be available in templates - def url(my_url): - return join_urlparts(flask.request.script_root, my_url) def env(name, default=None): return os.environ.get(name, default) - return dict(url=url, env=env) + return dict(env=env) def err_abort(status_code, **params): diff --git a/talerblog/blog/templates/base.html b/talerblog/blog/templates/base.html index 755e72f..c21a082 100644 --- a/talerblog/blog/templates/base.html +++ b/talerblog/blog/templates/base.html @@ -18,11 +18,11 @@ <html data-taler-nojs="true"> <head> <title>Taler Donation Demo</title> - <link rel="stylesheet" type="text/css" href="{{ url('/static/web-common/pure.css') }}" /> - <link rel="stylesheet" type="text/css" href="{{ url('/static/web-common/demo.css') }}" /> - <link rel="stylesheet" type="text/css" href="{{ url('/static/web-common/taler-fallback.css') }}" id="taler-presence-stylesheet" /> - <script src="{{ url("/static/web-common/taler-wallet-lib.js") }}" type="application/javascript"></script> - <script src="{{ url("/static/web-common/lang.js") }}" type="application/javascript"></script> + <link rel="stylesheet" type="text/css" href="{{ url_for('static', 'web-common/pure.css') }}" /> + <link rel="stylesheet" type="text/css" href="{{ url_for('static', 'web-common/demo.css') }}" /> + <link rel="stylesheet" type="text/css" href="{{ url_for('static', 'web-common/taler-fallback.css') }}" id="taler-presence-stylesheet" /> + <script src="{{ url_for('static', 'web-common/taler-wallet-lib.js') }}" type="application/javascript"></script> + <script src="{{ url_for('static', 'web-common/lang.js') }}" type="application/javascript"></script> {% block styles %}{% endblock %} {% block scripts %}{% endblock %} </head> @@ -43,7 +43,7 @@ </div> <section id="main" class="content"> - <a href="{{ url("/") }}"> + <a href="{{ url_for('index') }}"> <div id="logo"> <svg height="100" width="100"> <circle cx="50" cy="50" r="40" stroke="darkcyan" stroke-width="6" fill="white" /> diff --git a/talerblog/helpers.py b/talerblog/helpers.py deleted file mode 100644 index 83eccd5..0000000 --- a/talerblog/helpers.py +++ /dev/null @@ -1,79 +0,0 @@ -# This file is part of TALER -# (C) 2016 INRIA -# -# TALER is free software; you can redistribute it and/or modify it under the -# terms of the GNU Affero General Public License as published by the Free Software -# Foundation; either version 3, or (at your option) any later version. -# -# TALER is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. See the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along with -# TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> -# -# @author Florian Dold -# @author Marcello Stanisci - -from urllib.parse import urljoin, urlencode -import logging -import json -import flask -from .talerconfig import TalerConfig - -LOGGER = logging.getLogger(__name__) - -TC = TalerConfig.from_env() -BACKEND_URL = TC["frontends"]["backend"].value_string(required=True) -NDIGITS = TC["frontends"]["NDIGITS"].value_int() -CURRENCY = TC["taler"]["CURRENCY"].value_string() - -FRACTION_BASE = 1e8 - -if not NDIGITS: - NDIGITS = 2 - -class MissingParameterException(Exception): - def __init__(self, param): - self.param = param - super().__init__() - -def amount_to_float(amount): - return amount['value'] + (float(amount['fraction']) / float(FRACTION_BASE)) - - -def amount_from_float(floatx): - value = int(floatx) - fraction = int((floatx - value) * FRACTION_BASE) - return dict(currency=CURRENCY, value=value, fraction=fraction) - - -def join_urlparts(*parts): - ret = "" - part = 0 - while part < len(parts): - buf = parts[part] - part += 1 - if ret.endswith("/"): - buf = buf.lstrip("/") - elif ret and not buf.startswith("/"): - buf = "/" + buf - ret += buf - return ret - - -def make_url(page, *query_params): - """ - Return a URL to a page in the current Flask application with the given - query parameters (sequence of key/value pairs). - """ - query = urlencode(query_params) - if page.startswith("/"): - root = flask.request.url_root - page = page.lstrip("/") - else: - root = flask.request.base_url - url = urljoin(root, "%s?%s" % (page, query)) - # urlencode is overly eager with quoting, the wallet right now - # needs some characters unquoted. - return url.replace("%24", "$").replace("%7B", "{").replace("%7D", "}") |