Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions home/processors.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import math
from django.conf import settings
from django.urls import reverse

Expand All @@ -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)}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
<div class="left">
<div class="col">
{% block h1 %}<h1 {% if view.header_icon %}class="icon icon-{{ view.header_icon }}"{% endif %}>{{ view.get_page_title }}<span></span></h1>{% endblock %}
{% if cache_timeout %}
<h3>Changes may take up to {{ cache_timeout }} minute(s) to reflect on your public IoGT site.</h3>
{% endif %}
</div>
{% block search %}{% search_form %}{% endblock %}
</div>
Expand Down
13 changes: 9 additions & 4 deletions iogt/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
60 changes: 30 additions & 30 deletions iogt/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
'translation_manager',
'health_check',
'health_check.db',
'health_check.cache',
'health_check.storage',
'health_check.contrib.migrations',
'rest_framework_simplejwt',
Expand All @@ -93,6 +92,7 @@
'django.contrib.sites',
]


MIDDLEWARE = [
'wagtailcache.cache.UpdateCacheMiddleware',
'django.middleware.security.SecurityMiddleware',
Expand Down Expand Up @@ -139,6 +139,7 @@
'home.processors.show_footers',
'messaging.processors.add_vapid_public_key',
'notifications.processors.push_notification',
'home.processors.cache_timeout',
],
},
},
Expand Down Expand Up @@ -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')

Expand Down