Ticket #6793: exported_settings_processor.diff

File exported_settings_processor.diff, 2.4 KB (added by Alberto García Hierro <fiam@…>, 17 years ago)
  • django/conf/global_settings.py

     
    156156    'django.core.context_processors.debug',
    157157    'django.core.context_processors.i18n',
    158158    'django.core.context_processors.media',
     159    'django.core.context_processors.exported_settings',
    159160#    'django.core.context_processors.request',
    160161)
    161162
  • django/core/context_processors.py

     
    6060def request(request):
    6161    return {'request': request}
    6262
     63def exported_settings(request):
     64    context_extras = {}
     65    e = getattr(settings, 'EXPORTED', None)
     66    if not e:
     67        return context_extras
     68
     69    for field in e.fields:
     70        context_extras[field[0]] = field[1]
     71    return context_extras
     72
    6373# PermWrapper and PermLookupDict proxy the permissions system into objects that
    6474# the template system can understand.
    6575
  • docs/settings.txt

     
    138138
    139139The only place you should assign to settings is in a settings file.
    140140
     141Using settings in templates
     142===========================
     143
     144Define a class called EXPORTED with the fields attribute set
     145to an iterable of pairs. The first component is the template
     146variable name, and the second is the value. For example:
     147
     148    class EXPORTED:
     149        fields = ( ('foo', 'bar'), ('images_url', MEDIA_URL + '/images/'))
     150
     151Note that this feature depends on RequestContext.
     152See the `RequestContext docs`_ for more information.
     153
     154.. _RequestContext docs: ../templates_python/#subclassing-context-requestcontext
     155
    141156Security
    142157========
    143158
     
    907922    ("django.core.context_processors.auth",
    908923    "django.core.context_processors.debug",
    909924    "django.core.context_processors.i18n",
    910     "django.core.context_processors.media")
     925    "django.core.context_processors.media",
     926    "django.core.context_processors.exported_settings")
    911927
    912928A tuple of callables that are used to populate the context in ``RequestContext``.
    913929These callables take a request object as their argument and return a dictionary
Back to Top