1
Fork 0

Allow access to settings in templates

This commit is contained in:
Jake Howard 2018-07-24 21:16:55 +01:00
parent 510daf113d
commit 53cbee964f
Signed by: jake
GPG key ID: 57AFB45680EDD477
4 changed files with 49 additions and 22 deletions

18
project/common/context.py Normal file
View file

@ -0,0 +1,18 @@
from django.conf import settings
SETTINGS_KEYS = [
'BASE_URL',
'STATIC_URL',
'MEDIA_URL',
'LANGUAGE_CODE',
'TIME_ZONE',
'ALLOWED_HOSTS',
'WAGTAIL_SITE_NAME'
]
def settings_injector(request):
return {'settings': {
setting: getattr(settings, setting) for setting in SETTINGS_KEYS
}}

View file

@ -27,7 +27,7 @@ class Entity(MetadataPageMixin, Page):
return self.search_image
def get_meta_description(self):
return self.search_description or self.short_body
return self.search_description
class Meta:
abstract = True

View file

@ -17,6 +17,22 @@ import django_cache_url
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
WAGTAIL_SITE_NAME = "project"
# Base URL to use when referring to full URLs within the Wagtail admin backend -
# e.g. in notification emails. Don't include '/admin' or a trailing slash
BASE_URL = 'http://example.com'
DEBUG = True
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '@%p6v$-d_+)v!=5ow9-*!lw@2n+&9!f83^+p)#jegc%7h122xe'
# SECURITY WARNING: define the correct hosts in production!
ALLOWED_HOSTS = ['*']
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/
@ -77,23 +93,30 @@ TEMPLATES = [
'DIRS': [
os.path.join(BASE_DIR, 'templates'),
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
'loaders': [
('django.template.loaders.cached.Loader', [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
]),
'project.common.context.settings_injector'
],
},
},
]
if not DEBUG:
TEMPLATES[0]['OPTIONS']['loaders'] = [
('django.template.loaders.cached.Loader', [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
]),
]
del TEMPLATES[0]['APP_DIRS']
WSGI_APPLICATION = 'project.wsgi.application'
@ -158,21 +181,6 @@ MEDIA_URL = '/media/'
# Wagtail settings
WAGTAIL_SITE_NAME = "project"
# Base URL to use when referring to full URLs within the Wagtail admin backend -
# e.g. in notification emails. Don't include '/admin' or a trailing slash
BASE_URL = 'http://example.com'
DEBUG = True
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '@%p6v$-d_+)v!=5ow9-*!lw@2n+&9!f83^+p)#jegc%7h122xe'
# SECURITY WARNING: define the correct hosts in production!
ALLOWED_HOSTS = ['*']
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
if 'CACHE_URL' in os.environ:
CACHES = {'default': django_cache_url.config()}

View file

@ -2,4 +2,5 @@
{% block content %}
{{ self.body }}
{{ settings.WAGTAIL_SITE_NAME }}
{% endblock %}