From 3c2f27489638d10c5a765f9a2081d010c9f42ea6 Mon Sep 17 00:00:00 2001 From: Ali Hassan Date: Wed, 22 Feb 2023 18:06:52 +0500 Subject: [PATCH 1/7] Notifies users if change will take some time --- .../modeladmin/translation_manager/translationentry/index.html | 1 + 1 file changed, 1 insertion(+) diff --git a/home/templates/modeladmin/translation_manager/translationentry/index.html b/home/templates/modeladmin/translation_manager/translationentry/index.html index 61dfcd14c..91e9b117b 100644 --- a/home/templates/modeladmin/translation_manager/translationentry/index.html +++ b/home/templates/modeladmin/translation_manager/translationentry/index.html @@ -7,6 +7,7 @@
{% block h1 %}

{{ view.get_page_title }}

{% endblock %} +

Changes may take up to 5 minutes to reflect on your public IoGT site.

{% block search %}{% search_form %}{% endblock %}
From a946d7fc5a40944a7a8c0f37c2844f1acf3a473d Mon Sep 17 00:00:00 2001 From: Ali Hassan Date: Thu, 23 Feb 2023 11:08:57 +0500 Subject: [PATCH 2/7] Update wagtail menus package --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 3109799af..1196ae1e1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,7 +19,7 @@ Markdown==3.3.7 wagtail==2.15.* wagtail-cache~=1.2.1 wagtailmedia==0.10.* -wagtailmenus~=3.0 +wagtailmenus==3.1.3 wagtailsvg==0.0.14 whitenoise==5.2.* django-health-check==3.16.5 From 290819bf8d6cb2883209edcb245d9ca97278217b Mon Sep 17 00:00:00 2001 From: Sher Ali Date: Mon, 27 Feb 2023 18:08:04 +0500 Subject: [PATCH 3/7] changes default to dummy cache --- iogt/patch.py | 8 +++++--- iogt/settings/base.py | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/iogt/patch.py b/iogt/patch.py index b5d739734..f2ee18fc6 100644 --- a/iogt/patch.py +++ b/iogt/patch.py @@ -20,15 +20,17 @@ def _translate_node_render(self, context): from django.utils.safestring import SafeData from django.utils.safestring import mark_safe from django.core.cache import cache + from translation_manager.models import TranslationEntry - lookup = (self.filter_expression.var.literal or - self.filter_expression.var._resolve_lookup(context)) + lookup = self.filter_expression.var.literal or self.filter_expression.var._resolve_lookup(context) try: translation_entry = cache.get(f'{globals_.locale.language_code}_translation_map')[ (lookup, globals_.locale.language_code)] except (KeyError, TypeError): - translation_entry = None + translation_entry = TranslationEntry.objects.filter( + language=globals_.locale.language_code, original=lookup + ).first() if translation_entry and translation_entry.translation: return translation_entry.translation diff --git a/iogt/settings/base.py b/iogt/settings/base.py index 4305a8017..630a98735 100644 --- a/iogt/settings/base.py +++ b/iogt/settings/base.py @@ -486,7 +486,7 @@ 'ACCESS_TOKEN_LIFETIME': timedelta(days=365), } -CACHE_BACKEND = os.getenv('CACHE_BACKEND') +CACHE_BACKEND = os.getenv('CACHE_BACKEND', 'django.core.cache.backends.dummy.DummyCache') if CACHE_BACKEND: DJANGO_REDIS_IGNORE_EXCEPTIONS = True SESSION_ENGINE = 'django.contrib.sessions.backends.cached_db' From 10ca35b28688bb55df1a77da4d99ea38ffe0bbd6 Mon Sep 17 00:00:00 2001 From: Sher Ali Date: Tue, 28 Feb 2023 10:39:53 +0500 Subject: [PATCH 4/7] refactor dummy cache usage --- iogt/settings/base.py | 59 +++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 30 deletions(-) diff --git a/iogt/settings/base.py b/iogt/settings/base.py index 630a98735..1d3ebda74 100644 --- a/iogt/settings/base.py +++ b/iogt/settings/base.py @@ -75,7 +75,6 @@ 'translation_manager', 'health_check', 'health_check.db', - 'health_check.cache', 'health_check.storage', 'health_check.contrib.migrations', 'rest_framework_simplejwt', @@ -93,6 +92,7 @@ 'django.contrib.sites', ] + MIDDLEWARE = [ 'wagtailcache.cache.UpdateCacheMiddleware', 'django.middleware.security.SecurityMiddleware', @@ -485,35 +485,34 @@ SIMPLE_JWT = { 'ACCESS_TOKEN_LIFETIME': timedelta(days=365), } - -CACHE_BACKEND = os.getenv('CACHE_BACKEND', 'django.core.cache.backends.dummy.DummyCache') -if CACHE_BACKEND: - DJANGO_REDIS_IGNORE_EXCEPTIONS = True - SESSION_ENGINE = 'django.contrib.sessions.backends.cached_db' - WAGTAIL_CACHE_BACKEND = 'pagecache' - CACHE_LOCATION = os.getenv('CACHE_LOCATION', '') - CACHE_TIMEOUT = int(os.getenv('CACHE_TIMEOUT', '0')) - CACHES = { - 'default': { - 'BACKEND': CACHE_BACKEND, - 'LOCATION': CACHE_LOCATION, - 'TIMEOUT': CACHE_TIMEOUT, - }, - 'renditions': { - 'BACKEND': CACHE_BACKEND, - 'LOCATION': CACHE_LOCATION, - 'TIMEOUT': CACHE_TIMEOUT, - }, - 'pagecache': { - 'BACKEND': CACHE_BACKEND, - 'LOCATION': CACHE_LOCATION, - 'TIMEOUT': CACHE_TIMEOUT, - 'KEY_PREFIX': 'pagecache', - }, - } -else: - WAGTAIL_CACHE = False - SESSION_ENGINE='django.contrib.sessions.backends.db' +DUMMY_CACHE_BACKEND = 'django.core.cache.backends.dummy.DummyCache' +CACHE_BACKEND = os.getenv('CACHE_BACKEND', '') or DUMMY_CACHE_BACKEND +if CACHE_BACKEND != DUMMY_CACHE_BACKEND: + INSTALLED_APPS += [ + 'health_check.cache', + ] +DJANGO_REDIS_IGNORE_EXCEPTIONS = True +SESSION_ENGINE = 'django.contrib.sessions.backends.cached_db' +CACHE_LOCATION = os.getenv('CACHE_LOCATION', '') +CACHE_TIMEOUT = int(os.getenv('CACHE_TIMEOUT', '0')) +CACHES = { + 'default': { + 'BACKEND': CACHE_BACKEND, + 'LOCATION': CACHE_LOCATION, + 'TIMEOUT': CACHE_TIMEOUT, + }, + 'renditions': { + 'BACKEND': CACHE_BACKEND, + 'LOCATION': CACHE_LOCATION, + 'TIMEOUT': CACHE_TIMEOUT, + }, + 'pagecache': { + 'BACKEND': CACHE_BACKEND, + 'LOCATION': CACHE_LOCATION, + 'TIMEOUT': CACHE_TIMEOUT, + 'KEY_PREFIX': 'pagecache', + }, +} SITE_VERSION = os.getenv('SITE_VERSION', 'unknown') From 603b1e3e5798a77efeb730b93ef71367ccc2d579 Mon Sep 17 00:00:00 2001 From: Sher Ali Date: Tue, 28 Feb 2023 11:01:30 +0500 Subject: [PATCH 5/7] use compatible version of wagtailmenu --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 3109799af..1196ae1e1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,7 +19,7 @@ Markdown==3.3.7 wagtail==2.15.* wagtail-cache~=1.2.1 wagtailmedia==0.10.* -wagtailmenus~=3.0 +wagtailmenus==3.1.3 wagtailsvg==0.0.14 whitenoise==5.2.* django-health-check==3.16.5 From 4189381e673f3eb865600835a30210ce325a9f9c Mon Sep 17 00:00:00 2001 From: Sher Ali Date: Tue, 28 Feb 2023 11:11:36 +0500 Subject: [PATCH 6/7] fixes translation block patch for translation entry --- iogt/patch.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/iogt/patch.py b/iogt/patch.py index f2ee18fc6..1a3044189 100644 --- a/iogt/patch.py +++ b/iogt/patch.py @@ -60,6 +60,7 @@ def _translate_block_node_render(self, context, nested=False): from django.template import TemplateSyntaxError from django.template.base import render_value_in_context from django.utils import translation + from translation_manager.models import TranslationEntry if self.message_context: message_context = self.message_context.resolve(context) @@ -90,7 +91,9 @@ def _translate_block_node_render(self, context, nested=False): translation_entry = cache.get(f'{globals_.locale.language_code}_translation_map')[ (singular, globals_.locale.language_code)] except (KeyError, TypeError): - translation_entry = None + translation_entry = TranslationEntry.objects.filter( + language=globals_.locale.language_code, original=singular + ).first() if translation_entry and translation_entry.translation: result = translation_entry.translation From cce35837ffa169813b5fd7b98430df1f3cf4a5b3 Mon Sep 17 00:00:00 2001 From: Sher Ali Date: Wed, 8 Mar 2023 12:57:02 +0500 Subject: [PATCH 7/7] make minutes configurable --- home/processors.py | 5 +++++ .../translation_manager/translationentry/index.html | 4 +++- iogt/settings/base.py | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/home/processors.py b/home/processors.py index 283d4a458..2e360c350 100644 --- a/home/processors.py +++ b/home/processors.py @@ -1,3 +1,4 @@ +import math from django.conf import settings from django.urls import reverse @@ -13,3 +14,7 @@ def show_footers(request): if start_link: show_footers_ = False return {'show_footers': show_footers_} + + +def cache_timeout(request): + return {'cache_timeout': math.ceil(settings.CACHE_TIMEOUT / 60)} diff --git a/home/templates/modeladmin/translation_manager/translationentry/index.html b/home/templates/modeladmin/translation_manager/translationentry/index.html index 91e9b117b..95d8dc75c 100644 --- a/home/templates/modeladmin/translation_manager/translationentry/index.html +++ b/home/templates/modeladmin/translation_manager/translationentry/index.html @@ -7,7 +7,9 @@
{% block h1 %}

{{ view.get_page_title }}

{% endblock %} -

Changes may take up to 5 minutes to reflect on your public IoGT site.

+ {% if cache_timeout %} +

Changes may take up to {{ cache_timeout }} minute(s) to reflect on your public IoGT site.

+ {% endif %}
{% block search %}{% search_form %}{% endblock %}
diff --git a/iogt/settings/base.py b/iogt/settings/base.py index abd57a8ff..97020470d 100644 --- a/iogt/settings/base.py +++ b/iogt/settings/base.py @@ -139,6 +139,7 @@ 'home.processors.show_footers', 'messaging.processors.add_vapid_public_key', 'notifications.processors.push_notification', + 'home.processors.cache_timeout', ], }, },