From e9d95eac46687dfea140e2c81bf1dc4270c9976e Mon Sep 17 00:00:00 2001 From: MS Date: Thu, 23 Jul 2020 15:39:17 +0200 Subject: lint blog --- talermerchantdemos/blog/blog.py | 56 ++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 31 deletions(-) (limited to 'talermerchantdemos/blog/blog.py') diff --git a/talermerchantdemos/blog/blog.py b/talermerchantdemos/blog/blog.py index 1bea20b..f23013a 100644 --- a/talermerchantdemos/blog/blog.py +++ b/talermerchantdemos/blog/blog.py @@ -18,7 +18,6 @@ # @brief Implementation of a Taler-compatible blog. import urllib.parse -from urllib.parse import urljoin, quote, urlencode import logging import os import traceback @@ -26,14 +25,14 @@ import uuid import qrcode import qrcode.image.svg import base64 -import requests import flask import lxml.etree import time +from urllib.parse import urljoin from cachelib import UWSGICache, SimpleCache from taler.util.talerconfig import TalerConfig from ..blog.content import ARTICLES, get_article_file, get_image_file -import .backend_get .backend_post +from .httpcommon import backend_get, backend_post BASE_DIR = os.path.dirname(os.path.abspath(__file__)) app = flask.Flask(__name__, template_folder=BASE_DIR) @@ -61,7 +60,6 @@ def utility_processor(): # These helpers will be available in templates def env(name, default=None): return os.environ.get(name, default) - return dict(env=env) @@ -106,7 +104,6 @@ def index(): # so we don't always have to ask the backend / DB, and so we don't # have to store variable-size cookies on the client. try: - import uwsgi paid_articles_cache = UWSGICache(0, "paid_articles") except ImportError: paid_articles_cache = SimpleCache() @@ -299,14 +296,14 @@ def article(article_name, data=None): pay_status = backend_get(BACKEND_URL, "private/orders/{}".format(order_id), params=dict()) if pay_status.get("paid"): # Checks to do: - # + # # - check that the paid article is actually the one # mentioned in the requested URI. # # - check if the article was refunded before, and act # accordingly. # - + # FLOW HERE == ARTICLE PAID AND CAN BE SHOWN. # Put the article in the cache. @@ -316,7 +313,7 @@ def article(article_name, data=None): # Finally return the article. return render_article(article_name, data, order_id) - elif pay_status.get("already_paid_order_id") is not None: + if pay_status.get("already_paid_order_id") is not None: return flask.redirect( flask.url_for( "article", @@ -324,27 +321,24 @@ def article(article_name, data=None): order_id=pay_status.get("already_paid_order_id") ) ) - else: - ## - # Redirect the browser to a page where the wallet can - # run the payment protocol. - taler_pay_uri = pay_status["taler_pay_uri"] - qrcode_svg = get_qrcode_svg(taler_pay_uri) - check_status_url_enc = urllib.parse.quote( - flask.url_for( - "check_status", order_id=order_id, session_id=session_id - ) - ) - content = flask.render_template( - "templates/request_payment.html", - article_name=article_name, - taler_pay_uri=taler_pay_uri, - qrcode_svg=qrcode_svg, - check_status_url_enc=check_status_url_enc - ) - headers = {"Taler": taler_pay_uri} - resp = flask.Response(content, status=402, headers=headers) - return resp - # no pay_redirect but article not paid, this should never happen! - err_abort(500, message="Internal error, invariant failed", json=pay_status) + ## + # Redirect the browser to a page where the wallet can + # run the payment protocol. + taler_pay_uri = pay_status["taler_pay_uri"] + qrcode_svg = get_qrcode_svg(taler_pay_uri) + check_status_url_enc = urllib.parse.quote( + flask.url_for( + "check_status", order_id=order_id, session_id=session_id + ) + ) + content = flask.render_template( + "templates/request_payment.html", + article_name=article_name, + taler_pay_uri=taler_pay_uri, + qrcode_svg=qrcode_svg, + check_status_url_enc=check_status_url_enc + ) + headers = {"Taler": taler_pay_uri} + resp = flask.Response(content, status=402, headers=headers) + return resp -- cgit v1.2.3