From c6e5d1ece9c9ddf738e4124135f33651c94baa7c Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Wed, 17 Nov 2021 17:31:35 +0100 Subject: add link to software sources to ease compliance with AGPL --- src/pydrilla/pydrilla.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'src/pydrilla/pydrilla.py') diff --git a/src/pydrilla/pydrilla.py b/src/pydrilla/pydrilla.py index 586be19..dc472a4 100644 --- a/src/pydrilla/pydrilla.py +++ b/src/pydrilla/pydrilla.py @@ -577,11 +577,12 @@ def create_app(config_path=(here / 'config.json'), flask_config={}): return app config = load_config(config_path) - for key in ['static_resource_uri', 'content_dir']: + for key in ['static_resource_uri', 'content_dir', 'hydrilla_sources_uri']: if key not in config: raise ValueError(_('config_key_absent_{}').format(key)) - app._pydrilla_static_resource_uri = config['static_resource_uri'] + app._pydrilla_static_resource_uri = config['static_resource_uri'] + app._pydrilla_hydrilla_sources_uri = config['hydrilla_sources_uri'] app._pydrilla_werror = config.get('werror', False) if 'hydrilla_parent' in config: raise MyNotImplError('hydrilla_parent', config_path.name) @@ -599,19 +600,14 @@ def create_app(config_path=(here / 'config.json'), flask_config={}): def _(text_key): return current_app._pydrilla_gettext(text_key) -def escaping_gettext(text_key): - from markupsafe import escape - - return str(escape(_(text_key))) - def content(): return current_app._pydrilla_content class MyEnvironment(Environment): ''' A wrapper class around jinja2.Environment that causes GNU gettext function - (as '_' and '__') and url_for function to be passed to every call of each - template's render() method. + (as '_' and '__'), url_for function and 'hydrilla_sources_uri' config option + to be passed to every call of each template's render() method. ''' def __init__(self, *args, **kwargs): @@ -622,10 +618,19 @@ class MyEnvironment(Environment): old_render = template.render def new_render(*args, **kwargs): + _ = current_app._pydrilla_gettext + sources_uri = current_app._pydrilla_hydrilla_sources_uri + + def escaping_gettext(text_key): + from markupsafe import escape + + return str(escape(_(text_key))) + final_kwargs = { '_': escaping_gettext, '__': escaping_gettext, - 'url_for': url_for + 'url_for': url_for, + 'hydrilla_sources_uri' : sources_uri } final_kwargs.update(kwargs) -- cgit v1.2.3