Ticket #1278: template_context_constants.patch

File template_context_constants.patch, 3.2 KB (added by Chris Beaven, 17 years ago)

patch with tests

  • django/conf/global_settings.py

     
    136136# only parameter and returns a dictionary to add to the context.
    137137TEMPLATE_CONTEXT_PROCESSORS = (
    138138    'django.core.context_processors.auth',
     139    'django.core.context_processors.constants',
    139140    'django.core.context_processors.debug',
    140141    'django.core.context_processors.i18n',
    141 #    'django.core.context_processors.request',
     142#    'django.core.context_processrs.request',
    142143)
    143144
     145# Constants to add to all template contexts.
     146TEMPLATE_CONTEXT_CONSTANTS = {}
     147
    144148# Output to use in template system for invalid (e.g. misspelled) variables.
    145149TEMPLATE_STRING_IF_INVALID = ''
    146150
  • django/conf/project_template/settings.py

     
    5656#     'django.template.loaders.eggs.load_template_source',
    5757)
    5858
     59# Constants to add to all template contexts (dependant on the context
     60# processor 'django.core.context_processors.constants').
     61TEMPLATE_CONTEXT_CONSTANTS = {'media_url': MEDIA_URL}
     62
    5963MIDDLEWARE_CLASSES = (
    6064    'django.middleware.common.CommonMiddleware',
    6165    'django.contrib.sessions.middleware.SessionMiddleware',
  • django/core/context_processors.py

     
    2020        'perms': PermWrapper(request.user),
    2121    }
    2222
     23def constants(request):
     24    return settings.TEMPLATE_CONTEXT_CONSTANTS
     25
    2326def debug(request):
    2427    "Returns context variables helpful for debugging."
    2528    context_extras = {}
  • docs/settings.txt

     
    717717Default::
    718718
    719719    ("django.core.context_processors.auth",
     720    "django.core.context_processors.constants",
    720721    "django.core.context_processors.debug",
    721722    "django.core.context_processors.i18n")
    722723
  • docs/templates_python.txt

     
    290290``TEMPLATE_CONTEXT_PROCESSORS`` is set to::
    291291
    292292    ("django.core.context_processors.auth",
     293    "django.core.context_processors.constants",
    293294    "django.core.context_processors.debug",
    294295    "django.core.context_processors.i18n")
    295296
     
    371372      representing every SQL query that has happened so far during the request
    372373      and how long it took. The list is in order by query.
    373374
     375django.core.context_processors.constants
     376~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     377
     378If ``TEMPLATE_CONTEXT_PROCESSORS`` contains this processor, every
     379``Context`` will contain variables defined in the ``TEMPLATE_CONTEXT_CONSTANTS``
     380setting.
     381
    374382django.core.context_processors.i18n
    375383~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    376384
Back to Top