summaryrefslogtreecommitdiff
path: root/talermerchantdemos/httpcommon/__init__.py
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-10-11 13:29:45 +0200
committerChristian Grothoff <christian@grothoff.org>2020-10-11 13:29:45 +0200
commit1ae0306a3cf2ea27f60b2d205789994d260c2cce (patch)
tree53117a55c27601e92172ea82f1d8cd11d355c06c /talermerchantdemos/httpcommon/__init__.py
parent2e665813a44988bfd906c0fab773f82652047841 (diff)
downloadtaler-merchant-demos-1ae0306a3cf2ea27f60b2d205789994d260c2cce.tar.gz
taler-merchant-demos-1ae0306a3cf2ea27f60b2d205789994d260c2cce.tar.bz2
taler-merchant-demos-1ae0306a3cf2ea27f60b2d205789994d260c2cce.zip
add i18n FSFS
Diffstat (limited to 'talermerchantdemos/httpcommon/__init__.py')
-rw-r--r--talermerchantdemos/httpcommon/__init__.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/talermerchantdemos/httpcommon/__init__.py b/talermerchantdemos/httpcommon/__init__.py
index 1036f33..d07fe69 100644
--- a/talermerchantdemos/httpcommon/__init__.py
+++ b/talermerchantdemos/httpcommon/__init__.py
@@ -1,6 +1,10 @@
import flask
import requests
from urllib.parse import urljoin
+from flask import request
+from datetime import datetime
+import time
+
##
# Return a error response to the client.
@@ -79,5 +83,50 @@ def backend_get(backend_url, endpoint, params):
print("Backend responds to {}: {}".format(final_url, str(response_json)))
return response_json
+##
+# Helper function used inside Jinja2 logic to create a links
+# to the current page but in a different language. Used to
+# implement the "Language" menu.
+#
+def self_localized(lang):
+ """
+ Return URL for the current page in another locale.
+ """
+ path = request.path
+ # path must have the form "/$LANG/$STUFF"
+ parts = path.split('/', 2)
+ if (2 >= len(parts)):
+ # Totally unexpected path format, do not localize
+ return path
+ return "/" + lang + "/" + parts[2]
+
+
+##
+# Return a error response to the client.
+#
+# @param abort_status_code status code to return along the response.
+# @param params _kw_ arguments to passed verbatim to the templating engine.
+def err_abort(abort_status_code, **params):
+ t = flask.render_template("templates/error.html.j2", **params)
+ flask.abort(flask.make_response(t, abort_status_code))
+
+
+
def fallback_404(error):
return "Page not found"
+
+
+
+class Deadline:
+ def __init__(self, value):
+ self.value = value
+ def isExpired(self):
+ if self.value == "never":
+ return False
+ now = int(round(time.time()) * 1000)
+ now_dt = datetime.fromtimestamp(now / 1000)
+ deadline_dt = datetime.fromtimestamp(self.value / 1000)
+ print("debug: checking refund expiration, now: {}, deadline: {}".format(
+ now_dt.strftime("%c"), deadline_dt.strftime("%c")
+ ))
+ return now > self.value