From 51f25b62eb6447a48c139e04ea73e8fe811227a4 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Thu, 22 Apr 2021 15:49:16 +0200 Subject: Use same base template as merchant demos. --- talerbank/app/static/logo-white.svg | 45 ++++++++ talerbank/app/templates/404.html | 27 +---- talerbank/app/templates/base.html | 131 ++---------------------- talerbank/app/templates/common_base.html | 94 +++++++++++++++++ talerbank/app/templates/login.html | 9 +- talerbank/app/templates/payto_wiretransfer.html | 12 +-- talerbank/app/templates/profile_page.html | 5 +- talerbank/app/templates/public_accounts.html | 7 +- talerbank/app/templates/register.html | 27 +---- talerbank/app/templates/withdraw_confirm.html | 24 +---- talerbank/app/templates/withdraw_show.html | 37 +------ talerbank/cli.py | 11 +- talerbank/jinja2.py | 61 ++++++++--- talerbank/settings.py | 61 +++++++---- 14 files changed, 272 insertions(+), 279 deletions(-) create mode 100644 talerbank/app/static/logo-white.svg create mode 100644 talerbank/app/templates/common_base.html diff --git a/talerbank/app/static/logo-white.svg b/talerbank/app/static/logo-white.svg new file mode 100644 index 0000000..cb1f023 --- /dev/null +++ b/talerbank/app/static/logo-white.svg @@ -0,0 +1,45 @@ + + + + diff --git a/talerbank/app/templates/404.html b/talerbank/app/templates/404.html index be89ff6..cdbd97f 100644 --- a/talerbank/app/templates/404.html +++ b/talerbank/app/templates/404.html @@ -1,28 +1,9 @@ - - {% extends "base.html" %} -{% block headermsg %} +{% block main %} +

{{ _("Error") }}

-{% endblock headermsg %} -{% block content %} +
@@ -30,4 +11,4 @@

{{ _("Page not found!") }}

-{% endblock content %} +{% endblock main %} diff --git a/talerbank/app/templates/base.html b/talerbank/app/templates/base.html index e265866..bb9721c 100644 --- a/talerbank/app/templates/base.html +++ b/talerbank/app/templates/base.html @@ -1,128 +1,9 @@ - - - - - - {{ _("{currency} Bank - Taler Demo").format(currency=settings_value("TALER_CURRENCY")) }} - - - - - - {% block head %} {% endblock %} - - -
-

Taler Demo

-

Bank

-

- {% autoescape off %} - {{ _("This part of the demo shows how a bank that supports Taler directly would work. In addition to using your own bank account, you can also see the transaction history of some Public Accounts.").format(public_accounts=url('public-accounts')) }} - {% endautoescape %} -

-
- -
- {% block headermsg %} {% endblock %} - {% block content %} {% endblock %} -
-
-

- {% autoescape off %} - {{ _("You can learn more about Taler on our main website.").format(taler_site="https://taler.net/") }} - {% endautoescape %} -

-
-

Copyright © 2014—2020 Taler Systems SA

-
-
- - +{% endblock %} \ No newline at end of file diff --git a/talerbank/app/templates/common_base.html b/talerbank/app/templates/common_base.html new file mode 100644 index 0000000..a90c64c --- /dev/null +++ b/talerbank/app/templates/common_base.html @@ -0,0 +1,94 @@ + + + + + + {{ page_title | default(gettext("GNU Taler Demo")) }} + + + + + {% block head %} + {% endblock %} + + + +
+

+
+

+ +
+ {% block header_content %} +

This is the header content.

+ {% endblock %} +
+
+ + + + +
+ {% block main %} + This is the main content of the page. + {% endblock %} +
+
+

+ {{ + gettext('You can learn more about GNU Taler on our main website.').format(site="https://taler.net/" + getlang() + "/") + }} +

+
+

Copyright © 2014—2021 Taler Systems SA

+
+
+ + diff --git a/talerbank/app/templates/login.html b/talerbank/app/templates/login.html index 007088e..3605555 100644 --- a/talerbank/app/templates/login.html +++ b/talerbank/app/templates/login.html @@ -18,11 +18,10 @@ @author Florian Dold #} -{% block headermsg %} -

{{ _("Welcome to the {currency} Bank!").format(currency=settings_value("TALER_CURRENCY")) }}

-{% endblock headermsg %} +{% block main %} + +

{{ _("Welcome to the {currency} Bank!").format(currency=settings_value("TALER_CURRENCY")) }}

-{% block content %}
-{% endblock content %} +{% endblock main %} diff --git a/talerbank/app/templates/payto_wiretransfer.html b/talerbank/app/templates/payto_wiretransfer.html index cdb3c0e..b3631f3 100644 --- a/talerbank/app/templates/payto_wiretransfer.html +++ b/talerbank/app/templates/payto_wiretransfer.html @@ -18,12 +18,12 @@ @author Florian Dold #} -{% block headermsg %} -
- [{{ _("Logout") }}]
-
-{% endblock headermsg %} -{% block content %} +{% block main %} + +
+ [{{ _("Logout") }}]
+
+
diff --git a/talerbank/app/templates/profile_page.html b/talerbank/app/templates/profile_page.html index 1d81b51..fe94109 100644 --- a/talerbank/app/templates/profile_page.html +++ b/talerbank/app/templates/profile_page.html @@ -18,7 +18,7 @@ @author Florian Dold #} -{% block headermsg %} +{% block main %}

{% autoescape off %} @@ -27,8 +27,7 @@

[{{ _("Logout") }}]
-{% endblock headermsg %} -{% block content %} + diff --git a/talerbank/app/templates/public_accounts.html b/talerbank/app/templates/public_accounts.html index e469896..1b69594 100644 --- a/talerbank/app/templates/public_accounts.html +++ b/talerbank/app/templates/public_accounts.html @@ -17,11 +17,10 @@ @author Marcello Stanisci #} -{% block headermsg %} +{% block main %} +

{{ _("History of public accounts") }}

-{% endblock headermsg %} -{% block content %} Back
@@ -103,4 +102,4 @@
-{% endblock content %} +{% endblock main %} diff --git a/talerbank/app/templates/register.html b/talerbank/app/templates/register.html index 4f3d8c1..9474717 100644 --- a/talerbank/app/templates/register.html +++ b/talerbank/app/templates/register.html @@ -1,28 +1,9 @@ - - {% extends "base.html" %} -{% block headermsg %} -

{{ _("Register to the {currency} bank!").format(currency=settings_value('TALER_CURRENCY')) }}

-{% endblock headermsg %} +{% block main %} + +

{{ _("Register to the {currency} bank!").format(currency=settings_value('TALER_CURRENCY')) }}

-{% block content %}
@@ -55,4 +36,4 @@
-{% endblock content %} +{% endblock main %} diff --git a/talerbank/app/templates/withdraw_confirm.html b/talerbank/app/templates/withdraw_confirm.html index 664e013..eb3398d 100644 --- a/talerbank/app/templates/withdraw_confirm.html +++ b/talerbank/app/templates/withdraw_confirm.html @@ -1,29 +1,9 @@ - - - {% extends "base.html" %} -{% block headermsg %} +{% block content %} +

{{ _("Confirm Withdrawal") }}

-{% endblock %} -{% block content %} {% if not is_success %}

{{ hint }} diff --git a/talerbank/app/templates/withdraw_show.html b/talerbank/app/templates/withdraw_show.html index cb46141..675099e 100644 --- a/talerbank/app/templates/withdraw_show.html +++ b/talerbank/app/templates/withdraw_show.html @@ -1,27 +1,5 @@ - - {% extends "base.html" %} -{% block headermsg %} -

{{ _("Withdraw to a Taler Wallet") }}

-{% endblock %} - {% block head %} - {% endblock head %} -{% block content %} -
-

- {% autoescape off %} - {{ _("Looks like your browser doesn't support GNU Taler payments. You can try installing a wallet browser extension.").format(wallet_link="https://taler.net/en/wallet.html") }} - {% endautoescape %} -

-
+{% block main %} +

{{ _("Withdraw to a Taler Wallet") }}

{{ _("You can use this QR code to withdraw to your mobile wallet:") }} @@ -78,4 +47,4 @@ {% endautoescape %}

-{% endblock content %} +{% endblock main %} diff --git a/talerbank/cli.py b/talerbank/cli.py index c62cba5..4e7f301 100644 --- a/talerbank/cli.py +++ b/talerbank/cli.py @@ -40,6 +40,11 @@ LOGGER = logging.getLogger(__name__) UWSGI_LOGFMT = "%(ltime) %(proto) %(method) %(uri) %(proto) => %(status)" os.environ.setdefault("DJANGO_SETTINGS_MODULE", "talerbank.settings") +# Argument to tell uWSGI to load the python plugin. +# This hack is required, because on systems where the plugin is statically linked, +# loading it causes an error. +arg_load_python = "--if-not-plugin python --plugins python --endif".split(" ") + @click.group(help="Manager script of Taler bank.") @click.pass_context @@ -108,6 +113,7 @@ def handle_serve_http(port): params = [ "uwsgi", "uwsgi", + *arg_load_python, "--static-map", "/static=%s/talerbank/app/static" % SITE_PACKAGES, "--die-on-term", @@ -133,6 +139,7 @@ def handle_serve_uwsgi(): params = [ "uwsgi", "uwsgi", + *arg_load_python, "--static-map", "/static=%s/talerbank/app/static" % SITE_PACKAGES, "--die-on-term", @@ -166,6 +173,8 @@ def config(): TC = TalerConfig.from_file(os.environ.get("TALER_CONFIG_FILE")) TC.dump() - def run(): cli() + +if __name__ == "__main__": + cli() diff --git a/talerbank/jinja2.py b/talerbank/jinja2.py index b26b984..a91cf3b 100644 --- a/talerbank/jinja2.py +++ b/talerbank/jinja2.py @@ -27,6 +27,8 @@ from django.urls import reverse, get_script_prefix from django.conf import settings from jinja2 import Environment from django.utils.translation import gettext +import markupsafe + ## # Check if a URL is absolute or not. @@ -128,6 +130,7 @@ def tojson(x): def amount_stringify(amount): return amount.stringify(settings.TALER_DIGITS, pretty=True) + def get_locale(url): parts = url.split('/', 2) if (2 >= len(parts)): @@ -136,20 +139,52 @@ def get_locale(url): lang = parts[1] return lang + +all_languages = { + "en": "English [en]", + "ar": "Arabic [ar]", + "zh_Hant": "Chinese [zh]", + "fr": "French [fr]", + "de": "German [de]", + "hi": "Hindi [hi]", + "it": "Italian [it]", + "ja": "Japanese [ja]", + "ko": "Korean [ko]", + "pt": "Portuguese [pt]", + "pt_BR": "Portuguese (Brazil) [pt_BR]", + "ru": "Russian [ru]", + "es": "Spanish [es]", + "sv": "Swedish [sv]", + "tr": "Turkish [tr]", +} + + +def context_processor(request): + def getlang(): + return get_locale(request.path) + + return dict(getlang=getlang) + + def environment(**options): env = Environment(**options) - env.globals.update( - { - "static": static, - "url": url, - "settings_value": settings_value, - "env": env_get, - "is_valid_amount": is_valid_amount, - "amount_stringify": amount_stringify, - "tojson": tojson, - "_": gettext, - "get_locale": get_locale - - } + + gettext_markup = lambda *args, **kwargs: markupsafe.Markup( + gettext(*args, **kwargs) ) + + env.globals.update({ + "static": static, + "url": url, + "settings_value": settings_value, + "env": env_get, + "is_valid_amount": is_valid_amount, + "amount_stringify": amount_stringify, + "tojson": tojson, + "_": gettext_markup, + "gettext": gettext_markup, + "get_locale": get_locale, + "getactive": lambda: "bank", + "all_languages": all_languages, + }) return env diff --git a/talerbank/settings.py b/talerbank/settings.py index 8331761..e9c852a 100644 --- a/talerbank/settings.py +++ b/talerbank/settings.py @@ -18,7 +18,9 @@ from taler.util.talerconfig import TalerConfig, ConfigurationError LOGGER = logging.getLogger(__name__) -LOGGER.info("DJANGO_SETTINGS_MODULE: %s" % os.environ.get("DJANGO_SETTINGS_MODULE")) +LOGGER.info( + "DJANGO_SETTINGS_MODULE: %s" % os.environ.get("DJANGO_SETTINGS_MODULE") +) TC = TalerConfig.from_file(os.environ.get("TALER_CONFIG_FILE")) @@ -79,16 +81,18 @@ MIDDLEWARE = [ "talerbank.app.middleware.DecompressionMiddleware", ] -TEMPLATES = [ - { - "BACKEND": "django.template.backends.jinja2.Jinja2", - "DIRS": [ - os.path.join(BASE_DIR, "talerbank/app/static/web-common/"), - os.path.join(BASE_DIR, "talerbank/app/templates"), - ], - "OPTIONS": {"environment": "talerbank.jinja2.environment"}, - } -] +TEMPLATES = [{ + "BACKEND": + "django.template.backends.jinja2.Jinja2", + "DIRS": [ + os.path.join(BASE_DIR, "talerbank/app/static/web-common/"), + os.path.join(BASE_DIR, "talerbank/app/templates"), + ], + "OPTIONS": { + "environment": "talerbank.jinja2.environment", + "context_processors": ["talerbank.jinja2.context_processor"], + }, +}] # Disable those, since they don't work with # jinja2 anyways. @@ -109,10 +113,13 @@ if not DBNAME: LOGGER.info("dbname: %s" % DBNAME) -CHECK_DBSTRING_FORMAT = re.search(r"[a-z]+:///[a-z]+([\?][a-z]+=[a-z/]+)?", DBNAME) +CHECK_DBSTRING_FORMAT = re.search( + r"[a-z]+:///[a-z]+([\?][a-z]+=[a-z/]+)?", DBNAME +) if not CHECK_DBSTRING_FORMAT: LOGGER.error( - "Bad db string given '%s', respect the format" "'dbtype:///dbname'" % DBNAME + "Bad db string given '%s', respect the format" + "'dbtype:///dbname'" % DBNAME ) sys.exit(2) @@ -146,12 +153,23 @@ DATABASES["default"] = DBCONFIG AUTH_PASSWORD_VALIDATORS = [ { - "NAME": "django.contrib.auth.password_validation" + "NAME": + "django.contrib.auth.password_validation" ".UserAttributeSimilarityValidator" }, - {"NAME": "django.contrib.auth.password_validation" ".MinimumLengthValidator"}, - {"NAME": "django.contrib.auth.password_validation" ".CommonPasswordValidator"}, - {"NAME": "django.contrib.auth.password_validation" ".NumericPasswordValidator"}, + { + "NAME": "django.contrib.auth.password_validation" + ".MinimumLengthValidator" + }, + { + "NAME": "django.contrib.auth.password_validation" + ".CommonPasswordValidator" + }, + { + "NAME": + "django.contrib.auth.password_validation" + ".NumericPasswordValidator" + }, ] # Internationalization @@ -184,7 +202,9 @@ except ConfigurationError as exc: LOGGER.error(exc) sys.exit(3) -TALER_MAX_DEBT = TC.value_string("bank", "MAX_DEBT", default="%s:50.0" % TALER_CURRENCY) +TALER_MAX_DEBT = TC.value_string( + "bank", "MAX_DEBT", default="%s:50.0" % TALER_CURRENCY +) TALER_MAX_DEBT_BANK = TC.value_string( "bank", "MAX_DEBT_BANK", default="%s:0.0" % TALER_CURRENCY ) @@ -203,7 +223,9 @@ TALER_PREDEFINED_ACCOUNTS = [ ] TALER_EXPECTS_DONATIONS = ["Tor", "GNUnet", "Taler", "FSF"] TALER_SUGGESTED_EXCHANGE = TC.value_string("bank", "suggested_exchange") -TALER_SUGGESTED_EXCHANGE_PAYTO = TC.value_string("bank", "suggested_exchange_payto") +TALER_SUGGESTED_EXCHANGE_PAYTO = TC.value_string( + "bank", "suggested_exchange_payto" +) _allow_reg = TC.value_string("bank", "ALLOW_REGISTRATIONS", default="no") @@ -212,7 +234,6 @@ if _allow_reg.lower() == "yes": else: ALLOW_REGISTRATIONS = False - _show_freeform_withdrawal = TC.value_string( "bank", "SHOW_FREEFORM_WITHDRAWAL", default="no" ) -- cgit v1.2.3