diff options
-rw-r--r-- | src/pydrilla/config.json | 1 | ||||
-rw-r--r-- | src/pydrilla/pydrilla.py | 25 | ||||
-rw-r--r-- | src/pydrilla/templates/base.html | 32 | ||||
-rw-r--r-- | src/pydrilla/templates/index.html | 2 | ||||
-rw-r--r-- | src/test/development_config.json | 5 | ||||
-rw-r--r-- | src/test/test_pydrilla.py | 17 |
6 files changed, 66 insertions, 16 deletions
diff --git a/src/pydrilla/config.json b/src/pydrilla/config.json index a6c4bf0..6bb5440 100644 --- a/src/pydrilla/config.json +++ b/src/pydrilla/config.json @@ -9,5 +9,6 @@ { "content_dir": "/var/lib/hydrilla/content", "static_resource_uri": "http://localhost:8000/", + "hydrilla_sources_uri": "https://git.koszko.org/pydrilla/", "try_configs": ["/etc/pydrilla/config.json"] } 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) diff --git a/src/pydrilla/templates/base.html b/src/pydrilla/templates/base.html index 6e7887e..7b26b64 100644 --- a/src/pydrilla/templates/base.html +++ b/src/pydrilla/templates/base.html @@ -75,6 +75,24 @@ in a proprietary program, I am not going to enforce this in court. font-size: 1.5em; padding: 0.5em; } + + .content { + margin: auto; + margin-top: 2em; + margin-bottom: 2em; + max-width: 700px; + padding-left: 1em; + padding-right: 1em; + border-left: 1px #999 solid; + border-right: 1px #999 solid; + } + + .footer { + font-size: 0.8em; + padding: 1em; + border-top: 1px #777 solid; + text-align: center; + } {% endblock %} </style> <title>{% block title %}{{ _('hydrilla') }}{% endblock %}</title> @@ -87,8 +105,18 @@ in a proprietary program, I am not going to enforce this in court. class="home_link" {% endcall %} </div> - {% block content %} - {% endblock %} + + <div class="content"> + {% block content %} + {% endblock %} + </div> + + <div class="footer"> + Copyright © Wojtek Kosior. + <br> + This page was generated by Hydrilla which is free/libre software. + You can get a copy <a href="{{ hydrilla_sources_uri|e }}">here</a>. + </div> {% endblock %} </body> </html> diff --git a/src/pydrilla/templates/index.html b/src/pydrilla/templates/index.html index 5f5b319..2555df0 100644 --- a/src/pydrilla/templates/index.html +++ b/src/pydrilla/templates/index.html @@ -24,7 +24,7 @@ in a proprietary program, I am not going to enforce this in court. #} {% extends 'base.html' %} -{% block body %} +{% block content %} {{ super() }} <h2>{{ _('hydrilla_welcome') }}</h2> {% endblock %} diff --git a/src/test/development_config.json b/src/test/development_config.json index 5998918..30cf10d 100644 --- a/src/test/development_config.json +++ b/src/test/development_config.json @@ -16,6 +16,11 @@ // clients). "static_resource_uri": "http://localhost:8000/", + // Hydrilla will display this link to users as a place where they can + // obtain sources for its software. This config option is meant to ease + // compliance with the AGPL. + "hydrilla_sources_uri": "https://git.koszko.org/pydrilla/", + // Make Pydrilla error out on any warning "werror": true diff --git a/src/test/test_pydrilla.py b/src/test/test_pydrilla.py index 9ec6ba6..660c8f3 100644 --- a/src/test/test_pydrilla.py +++ b/src/test/test_pydrilla.py @@ -30,23 +30,31 @@ import shutil from pathlib import Path from os import mkdir, unlink, environ import json +from markupsafe import escape from pydrilla import pydrilla, create_app test_dir = Path(__file__).resolve().parent packages_dir = test_dir.parent -test_config_path = test_dir / 'development_config.json' +development_config_path = test_dir / 'development_config.json' @pytest.fixture def client(): - app = create_app(test_config_path, flask_config={'TESTING': True}) + app = create_app(development_config_path, flask_config={'TESTING': True}) with app.test_client() as client: yield client -def test_api_basic(client): +@pytest.fixture +def development_config(): + with open(development_config_path) as config_file: + yield json.loads(pydrilla.strip_json_comments(config_file.read())) + +def test_api_basic(client, development_config): response = client.get('/') assert b'html' in response.data + sources_uri = development_config['hydrilla_sources_uri'] + assert escape(sources_uri).encode() in response.data for item_type in ['mapping', 'resource']: response = client.get(f'/{item_type}s/helloapple') @@ -95,3 +103,6 @@ def test_normalize_version(): assert pydrilla.normalize_version([4, 5, 3, 0, 0]) == [4, 5, 3] assert pydrilla.normalize_version([1, 0, 5, 0]) == [1, 0, 5] assert pydrilla.normalize_version([3, 3]) == [3, 3] + +def test_strip_json_comments(development_config): + assert development_config['static_resource_uri'] == 'http://localhost:8000/' |