def check_context_processor_installed(app_configs=None, **kwargs):
"Warn if our context processor is not installed."
from django.conf import settings
errors = []
if hasattr(settings, 'TEMPLATES'):
for i, engine in enumerate(settings.TEMPLATES):
# We only check for the context processor if using the default django backend.
if engine['BACKEND'] != 'django.template.backends.django.DjangoTemplates':
continue
if CONTEXT not in engine.get('OPTIONS', {}).get('context_processors', []):
errors.append(Warning(
'Missing boardinghouse context processor',
hint="Add '{1}' to settings.TEMPLATES[{0}]"
"['OPTIONS']['context_processors']".format(i, CONTEXT),
id='boardinghouse.W001'
))
elif hasattr(settings, 'TEMPLATE_CONTEXT_PROCESSORS'):
if CONTEXT not in settings.TEMPLATE_CONTEXT_PROCESSORS:
errors.append(Warning(
'Missing boardinghouse context processor',
hint="Add '{0}' to settings.TEMPLATE_CONTEXT_PROCESSORS".format(CONTEXT),
id='boardinghouse.W001'
))
else:
errors.append(Warning(
'Missing boardinghouse context processor (no TEMPLATES defined)',
hint="Configure settings.TEMPLATES and add '{0}'".format(CONTEXT),
id='boardinghouse.W001',
))
return errors
评论列表
文章目录