diff options
author | Wojtek Kosior <koszko@koszko.org> | 2022-10-29 13:54:06 +0200 |
---|---|---|
committer | Wojtek Kosior <koszko@koszko.org> | 2022-10-29 13:54:06 +0200 |
commit | d7db0d187ccb4404fdf6f19fba15e0a39391640a (patch) | |
tree | 4c41764c51818587d797efe17abab2e94306ec48 /src/hydrilla_website | |
download | hydrilla-website-d7db0d187ccb4404fdf6f19fba15e0a39391640a.tar.gz hydrilla-website-d7db0d187ccb4404fdf6f19fba15e0a39391640a.zip |
initial commit
Diffstat (limited to 'src/hydrilla_website')
-rw-r--r-- | src/hydrilla_website/__init__.py | 7 | ||||
-rw-r--r-- | src/hydrilla_website/__main__.py | 9 | ||||
-rw-r--r-- | src/hydrilla_website/app.py | 93 | ||||
m--------- | src/hydrilla_website/common_jinja_templates | 0 | ||||
-rw-r--r-- | src/hydrilla_website/locales/en_US/LC_MESSAGES/messages.po | 32 | ||||
-rw-r--r-- | src/hydrilla_website/py.typed | 5 | ||||
-rw-r--r-- | src/hydrilla_website/templates/index.html.jinja | 29 | ||||
-rw-r--r-- | src/hydrilla_website/templates/website_base.html.jinja | 26 |
8 files changed, 201 insertions, 0 deletions
diff --git a/src/hydrilla_website/__init__.py b/src/hydrilla_website/__init__.py new file mode 100644 index 0000000..3ac4327 --- /dev/null +++ b/src/hydrilla_website/__init__.py @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: CC0-1.0 + +# Copyright (C) 2022 Wojtek Kosior <koszko@koszko.org> +# +# Available under the terms of Creative Commons Zero v1.0 Universal. + +from .app import website_app diff --git a/src/hydrilla_website/__main__.py b/src/hydrilla_website/__main__.py new file mode 100644 index 0000000..ad71c06 --- /dev/null +++ b/src/hydrilla_website/__main__.py @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: CC0-1.0 + +# Copyright (C) 2022 Wojtek Kosior <koszko@koszko.org> +# +# Available under the terms of Creative Commons Zero v1.0 Universal. + +from .app import website_app + +website_app.run() diff --git a/src/hydrilla_website/app.py b/src/hydrilla_website/app.py new file mode 100644 index 0000000..84303c3 --- /dev/null +++ b/src/hydrilla_website/app.py @@ -0,0 +1,93 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later + +# Hydrilla&Haketilo website logic. +# +# Copyright (C) 2021, 2022 Wojtek Kosior +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. +# +# +# I, Wojtek Kosior, thereby promise not to sue for violation of this +# file's license. Although I request that you do not make use of this +# code in a proprietary program, I am not going to enforce this in +# court. + +import gettext +import dataclasses as dc +import typing as t + +from pathlib import Path + +import flask +import jinja2 + +from . import common_jinja_templates + + +here = Path(__file__).resolve().parent + + +supported_languages = {'en_US'} +default_locale = 'en_US' + + +def choose_locale() -> None: + app = t.cast(HydrillaWebsite, flask.current_app) + best_locale_match = flask.request.accept_languages.best_match( + supported_languages, + default = default_locale + ) + if best_locale_match is None: + app._hydrilla_request_locale = default_locale + else: + app._hydrilla_request_locale = best_locale_match + + translations = gettext.translation( + 'messages', + localedir = here / 'locales', + languages = [app._hydrilla_request_locale] + ) + + app.jinja_env.install_gettext_translations(translations) + + +@dc.dataclass(init=False) +class HydrillaWebsite(flask.Flask): + _hydrilla_request_locale: str + + def __init__(self) -> None: + super().__init__(__name__) + + loaders = [jinja2.PackageLoader(__package__)] + combined_loader = common_jinja_templates.combine_with_loaders(loaders) + + self.jinja_options = { + **self.jinja_options, + 'loader': combined_loader, + 'autoescape': jinja2.select_autoescape(['.jinja']), + 'lstrip_blocks': True, + 'extensions': [ + *self.jinja_options.get('extensions', []), + 'jinja2.ext.i18n', + 'jinja2.ext.do' + ] + } + + self.before_request(choose_locale) + +website_app = HydrillaWebsite() + +@website_app.route('/', methods=['GET']) +def main() -> str: + return flask.render_template('index.html.jinja') diff --git a/src/hydrilla_website/common_jinja_templates b/src/hydrilla_website/common_jinja_templates new file mode 160000 +Subproject 0e8ab5c2735b94166552ce80c18e523357a048a diff --git a/src/hydrilla_website/locales/en_US/LC_MESSAGES/messages.po b/src/hydrilla_website/locales/en_US/LC_MESSAGES/messages.po new file mode 100644 index 0000000..eb9d5e4 --- /dev/null +++ b/src/hydrilla_website/locales/en_US/LC_MESSAGES/messages.po @@ -0,0 +1,32 @@ +# SPDX-License-Identifier: CC0-1.0 +# English translations for Hydrilla&Haketilo website. +# +# Copyright (C) 2021-2022 Wojtek Kosior <koszko@koszko.org> +# Available under the terms of Creative Commons Zero v1.0 Universal. +msgid "" +msgstr "" +"Project-Id-Version: hydrilla_website 0.1.dev0+d20221029\n" +"Report-Msgid-Bugs-To: koszko@koszko.org\n" +"POT-Creation-Date: 2022-10-29 13:24+0200\n" +"PO-Revision-Date: 2022-10-29 13:18+0200\n" +"Last-Translator: Wojtek Kosior <koszko@koszko.org>\n" +"Language: en_US\n" +"Language-Team: en_US <koszko@koszko.org>\n" +"Plural-Forms: nplurals=2; plural=(n != 1)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Generated-By: Babel 2.9.0\n" + +#: src/hydrilla_website/templates/index.html.jinja:23 +msgid "index.title" +msgstr "Main page" + +#: src/hydrilla_website/templates/index.html.jinja:27 +msgid "index.h_big.welcome_to_haketilo" +msgstr "Welcome to Haketilo" + +#: src/hydrilla_website/templates/website_base.html.jinja:20 +msgid "base.title.haketilo" +msgstr "Haketilo&Hydrilla" + diff --git a/src/hydrilla_website/py.typed b/src/hydrilla_website/py.typed new file mode 100644 index 0000000..f41d511 --- /dev/null +++ b/src/hydrilla_website/py.typed @@ -0,0 +1,5 @@ +SPDX-License-Identifier: CC0-1.0 + +Copyright (C) 2022 Wojtek Kosior <koszko@koszko.org> + +Available under the terms of Creative Commons Zero v1.0 Universal. diff --git a/src/hydrilla_website/templates/index.html.jinja b/src/hydrilla_website/templates/index.html.jinja new file mode 100644 index 0000000..65ae42a --- /dev/null +++ b/src/hydrilla_website/templates/index.html.jinja @@ -0,0 +1,29 @@ +{# +SPDX-License-Identifier: GPL-3.0-or-later OR CC-BY-SA-4.0 + +Website main page. + +This file is part of Hydrilla&Haketilo website. + +Copyright (C) 2022 Wojtek Kosior + +Dual licensed under +* GNU General Public License v3.0 or later and +* Creative Commons Attribution Share Alike 4.0 International. + +You can choose to use either of these licenses or both. + + +I, Wojtek Kosior, thereby promise not to sue for violation of this +file's licenses. Although I request that you do not make use of this +code in a proprietary work, I am not going to enforce this in court. +#} +{% extends "website_base.html.jinja" %} + +{% block title %} {{ _('index.title') }} {% endblock %} + +{% block main %} + <h3> + {{ _('index.h_big.welcome_to_haketilo') }} + </h3> +{% endblock %} diff --git a/src/hydrilla_website/templates/website_base.html.jinja b/src/hydrilla_website/templates/website_base.html.jinja new file mode 100644 index 0000000..f706faa --- /dev/null +++ b/src/hydrilla_website/templates/website_base.html.jinja @@ -0,0 +1,26 @@ +{# +SPDX-License-Identifier: CC0-1.0 + +Proxy web UI base page template. + +This file is part of Hydrilla&Haketilo. + +Copyright (C) 2022 Wojtek Kosior <koszko@koszko.org> + +Available under the terms of Creative Commons Zero v1.0 Universal. +#} +{% extends "base.html.jinja" %} + +{% block head %} + {{ super() }} + + <title> + {% block title required %}{% endblock %} + - + {{ _('base.title.haketilo') }} + </title> +{% endblock head %} + +{% block style %} + {{ super() }} +{% endblock style %} |