[patch] Refactor functionality of DjangoContext into 'processors' which can be replaced or added to
|Reported by:||L.Plant.98@…||Owned by:||adrian|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
The attached patch is the result of this discussion on the dev list:
The patch does the following things:
- 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.
- Allows you to override the request processors that are used by default by changing the REQUEST_PROCESSORS setting
- Adds a 'processors' keyword argument to generic views and DjangoContext to allow additional processors to be defined on a per view basis.
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.
- 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)
Change History (7)
Changed 11 years ago by L.Plant.98@…
comment:4 Changed 10 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