"""
Library of context processors.
"""
# Imports
from django.conf import settings
# Exports
__all__ = (
"settings_in_context",
)
# Processors
# noinspection PyUnusedLocal
[docs]def settings_in_context(request):
"""Insert certain Django settings into the context.
:param request: The request instance is not used.
:type: request: object
:rtype: dict
To identify the settings to be included in the request context, use the ``SETTINGS_IN_CONTEXT`` in your
``settings.py`` file.
.. code-block:: py
COPYRIGHT_NAME = "Pleasant Tents, LLC"
MENU_ITEMS = [
("home", "Home"),
("dashboard", "Dashboard"),
("profile", "Profile"),
]
SITE_TITLE = "Example Site"
SUPERDJANGO_SETTINGS_IN_CONTEXT = [
"COPYRIGHT_NAME",
"MENU_ITEMS",
"SITE_TITLE",
]
"""
context = dict()
if not hasattr(settings, "SUPERDJANGO_SETTINGS_IN_CONTEXT"):
return context
names = getattr(settings, "SUPERDJANGO_SETTINGS_IN_CONTEXT")
for name in names:
try:
context[name] = getattr(settings, name)
except AttributeError:
context[name] = None
return context