From e921db747b3f86d6740fdd95c215268b6658eb7d Mon Sep 17 00:00:00 2001 From: Dmitry Marakasov Date: Tue, 17 Sep 2024 02:03:34 +0300 Subject: [PATCH] Move ipv6 day logic into function for tera compatibility --- repologyapp/__init__.py | 3 ++- repologyapp/template_functions.py | 6 ++++++ repologyapp/templates/_base.html | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/repologyapp/__init__.py b/repologyapp/__init__.py index f15e548a..4e10a2af 100644 --- a/repologyapp/__init__.py +++ b/repologyapp/__init__.py @@ -25,7 +25,7 @@ from repologyapp.config import config from repologyapp.globals import repometadata from repologyapp.template_filters import css_for_versionclass, extract_netloc, maintainer_to_links, maintainers_to_group_mailto -from repologyapp.template_functions import endpoint_like, url_for, url_for_self, url_for_static +from repologyapp.template_functions import endpoint_like, needs_ipv6_notice, url_for, url_for_self, url_for_static from repologyapp.template_tests import for_page, has_flag, has_flag_at, is_fallback_maintainer from repologyapp.views import registry as view_registry @@ -63,6 +63,7 @@ app.jinja_env.globals['url_for'] = url_for app.jinja_env.globals['url_for_self'] = url_for_self app.jinja_env.globals['url_for_static'] = url_for_static +app.jinja_env.globals['needs_ipv6_notice'] = needs_ipv6_notice # templates: custom global data app.jinja_env.globals['REPOLOGY_HOME'] = config['REPOLOGY_HOME'] diff --git a/repologyapp/template_functions.py b/repologyapp/template_functions.py index 244563ad..49c3d14f 100644 --- a/repologyapp/template_functions.py +++ b/repologyapp/template_functions.py @@ -15,6 +15,7 @@ # You should have received a copy of the GNU General Public License # along with repology. If not, see . +import datetime from typing import Any import flask @@ -62,3 +63,8 @@ def endpoint_like(*variants: str) -> bool: return True return False + + +def needs_ipv6_notice(*variants: str) -> bool: + now = datetime.datetime.now() + return now.month == 6 and now.day == 6 and ':' not in flask.request.environ.REMOTE_ADDR and flask.request.endpoint != 'index' diff --git a/repologyapp/templates/_base.html b/repologyapp/templates/_base.html index 9c356250..3ff23549 100644 --- a/repologyapp/templates/_base.html +++ b/repologyapp/templates/_base.html @@ -18,7 +18,7 @@ -{% if now().month == 6 and now().day == 6 and ':' not in request.environ.REMOTE_ADDR and request.endpoint != 'index' %} +{% if needs_ipv6_notice() %}
IPv6 logo