From cae213ace633fdb0b23c0cc512cac23f58aedde5 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Thu, 7 Jul 2022 23:03:41 +0200 Subject: wire jinja2 filters in code Those things are not really a configuration thing that changes, rather they are part of how the code of the application works. As such, it doesn't make too much sense to require those configuration values. Instead, we now add those filters programatically. This also ensures that the filters are the same between development, production and testing environment. --- development.ini | 3 --- fietsboek/__init__.py | 8 +++++++- production.ini | 3 --- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/development.ini b/development.ini index 15250c4..47e0231 100644 --- a/development.ini +++ b/development.ini @@ -16,9 +16,6 @@ pyramid.debug_routematch = false pyramid.default_locale_name = en pyramid.includes = pyramid_debugtoolbar -jinja2.filters = - format_decimal = fietsboek.jinja2.filter_format_decimal - format_datetime = fietsboek.jinja2.filter_format_datetime sqlalchemy.url = sqlite:///%(here)s/fietsboek.sqlite diff --git a/fietsboek/__init__.py b/fietsboek/__init__.py index 98e6846..6ed9028 100644 --- a/fietsboek/__init__.py +++ b/fietsboek/__init__.py @@ -8,6 +8,7 @@ from pyramid.settings import asbool, aslist from pyramid.i18n import default_locale_negotiator from .security import SecurityPolicy +from . import jinja2 as fiets_jinja2 def locale_negotiator(request): @@ -41,7 +42,7 @@ def main(global_config, **settings): """ This function returns a Pyramid WSGI application. """ # pylint: disable=unused-argument - if 'session_key' not in settings: + if settings.get('session_key', '') == '': raise ValueError("Please set a session signing key (session_key) in your settings!") settings['enable_account_registration'] = asbool( @@ -59,4 +60,9 @@ def main(global_config, **settings): config.set_session_factory(my_session_factory) config.set_security_policy(SecurityPolicy()) config.set_locale_negotiator(locale_negotiator) + + jinja2_env = config.get_jinja2_environment() + jinja2_env.filters['format_decimal'] = fiets_jinja2.filter_format_decimal + jinja2_env.filters['format_datetime'] = fiets_jinja2.filter_format_datetime + return config.make_wsgi_app() diff --git a/production.ini b/production.ini index 9dd45c2..2a822d5 100644 --- a/production.ini +++ b/production.ini @@ -11,9 +11,6 @@ pyramid.debug_authorization = false pyramid.debug_notfound = false pyramid.debug_routematch = false pyramid.default_locale_name = en -jinja2.filters = - format_decimal = fietsboek.jinja2.filter_format_decimal - format_datetime = fietsboek.jinja2.filter_format_datetime email.from = fietsboek@kingdread.de email.smtp_url = debug://localhost:1025 -- cgit v1.2.3