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 61dfcd14c..95d8dc75c 100644
--- a/home/templates/modeladmin/translation_manager/translationentry/index.html
+++ b/home/templates/modeladmin/translation_manager/translationentry/index.html
@@ -7,6 +7,9 @@
{% block h1 %}
{{ view.get_page_title }}
{% endblock %}
+ {% 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/patch.py b/iogt/patch.py
index b5d739734..1a3044189 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
@@ -58,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)
@@ -88,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
diff --git a/iogt/settings/base.py b/iogt/settings/base.py
index c10a7aeae..97020470d 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',
@@ -139,6 +139,7 @@
'home.processors.show_footers',
'messaging.processors.add_vapid_public_key',
'notifications.processors.push_notification',
+ 'home.processors.cache_timeout',
],
},
},
@@ -485,35 +486,34 @@
SIMPLE_JWT = {
'ACCESS_TOKEN_LIFETIME': timedelta(days=365),
}
-
-CACHE_BACKEND = os.getenv('CACHE_BACKEND')
-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')