Opened 9 years ago

Closed 9 years ago

Last modified 8 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
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: UI/UX:

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@… 9 years ago.
patch

Download all attachments as: .zip

Change History (7)

Changed 9 years ago by L.Plant.98@…

patch

comment:1 Changed 9 years ago by hugo

Hmm. I think I like this.

comment:2 Changed 9 years ago by rjwittams

Definite +1 from me.

comment:3 Changed 9 years ago by cygnus@…

+1; This sounds great!

comment:4 Changed 9 years ago by anonymous

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

comment:5 Changed 9 years ago by rezzrovv

+1

comment:6 Changed 9 years ago by adrian

  • Resolution set to fixed
  • Status changed from new to closed

(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