Opened 19 years ago

Closed 19 years ago

Last modified 18 years ago

#925 closed enhancement (fixed)

[patch] Refactor functionality of DjangoContext into 'processors' which can be replaced or added to

Reported by: L.Plant.98@… Owned by: Adrian Holovaty
Component: Core (Other) Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The attached patch is the result of this discussion on the dev list:
http://groups.google.co.uk/group/django-developers/browse_frm/thread/4a61014b42a72177/e65f1aee2a58cb73?tvc=1&q=request_processors+django#e65f1aee2a58cb73

Summary

The patch does the following things:

  1. Refactors the functionality of DjangoContext into a bunch of 'request processors'. These are callables that take a request object and return a dictionary to be added to the context.
  2. Allows you to override the request processors that are used by default by changing the REQUEST_PROCESSORS setting
  3. Adds a 'processors' keyword argument to generic views and DjangoContext to allow additional processors to be defined on a per view basis.

Description

Request processors are to template tags what the view function is to templates -- both views and processors process the request object and create data to be added to the context. (Views are different from processors in that they are responsible for returning the HttpResponse object as well, giving them full control and the option to not use the templating system at all etc). Processors are needed to do the processing needed by custom template tags and included sub-templates. The addition of these processors makes it possible to have things like stateful template tags, or other tags that need data from the request object, and have them work in generic views. The patch is totally backwards compatible.

Advantages

  • DjangoContext is no longer tied to built-in sub-systems.
  • With this patch Django's authentication system becomes more decoupled and replaceable. By simply adding your own version of "django.core.processors.auth" in the REQUEST_PROCESSORS setting, you can plug in your own system and have it available in the template context by default. (In fact, if you wrote an appropriate middleware could replace the built-in one altogether with this patch in place, AFAICT)
  • Part of ticket #667 would be made redundant by this patch (i.e. need for callables in extra_context)

Attachments (1)

request_processors_patch.diff (15.6 KB ) - added by L.Plant.98@… 19 years ago.
patch

Download all attachments as: .zip

Change History (7)

by L.Plant.98@…, 19 years ago

patch

comment:1 by hugo, 19 years ago

Hmm. I think I like this.

comment:2 by rjwittams, 19 years ago

Definite +1 from me.

comment:3 by cygnus@…, 19 years ago

+1; This sounds great!

comment:4 by anonymous, 19 years ago

Summary: Refactor functionality of DjangoContext into 'processors' which can be replaced or added to[patch] Refactor functionality of DjangoContext into 'processors' which can be replaced or added to

comment:5 by rezzrovv, 19 years ago

+1

comment:6 by Adrian Holovaty, 19 years ago

Resolution: fixed
Status: newclosed

(In [1773]) Fixed #925 -- Added TEMPLATE_CONTEXT_PROCESSORS, which lets you specify processesors for DjangoContext. Thanks, Luke Plant

Note: See TracTickets for help on using tickets.
Back to Top