Opened 6 years ago

Last modified 3 years ago

#13841 assigned New feature

Allow context processors access to current version of context

Reported by: Mitar Owned by: Colin Copeland
Component: Template system Version: master
Severity: Normal Keywords:
Cc: mmitar@…, vbmendes@…, simon@…, copelco@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

Allow context processors access to current version of context so that they can change values and not just override them. This can be easily done with another argument, context, and also backwards compatible. Functions would only get additional argument if they are defined to get two arguments and whatever they would return would override that in the context.

Attachments (3)

ticket13841.diff (875 bytes) - added by Simon Litchfield 6 years ago.
13841-docs.diff (1.1 KB) - added by Simon Litchfield 6 years ago.
Updated docs.
13841_tests_docs.diff (4.7 KB) - added by Colin Copeland 5 years ago.
Combined diff with tests and docs

Download all attachments as: .zip

Change History (18)

comment:1 Changed 6 years ago by Mitar

I could make a patch if there would be an agreement that this is useful.

comment:2 Changed 6 years ago by vbmendes

Cc: vbmendes@… added

I think this is a very useful feature. It also allows to develop context processor that add a context variable based in another context variable.

comment:3 Changed 6 years ago by Gregor Müllegger

mitar:

I could make a patch if there would be an agreement that this is useful.

It seems that you want to discuss this first before implementing. The best place for discussion is the django-developers mailinglist[1] - writing your proposal there will result in better feedback and you can get an idea if core developers also find this useful and would accept a patch.

[1] http://groups.google.com/group/django-developers

comment:4 Changed 6 years ago by Mitar

There was completely no response on the mailing list.

comment:5 Changed 6 years ago by Russell Keith-Magee

Triage Stage: UnreviewedAccepted

This seems like a reasonable feature request; however, the implementation will need to be very careful about backwards compatibility.

comment:6 Changed 6 years ago by Simon Litchfield

Cc: simon@… added

Mitar, this sounds good. Any thoughts on syntax? Maybe something like --

def mycontextprocesser(request, context=None):
    ...

Changed 6 years ago by Simon Litchfield

Attachment: ticket13841.diff added

comment:7 Changed 6 years ago by Simon Litchfield

Patch attached. Backwards compatible, shouldn't add overhead either (getargspec is only called once for each processor) --

def mycontextprocessor(request):
    ...

def mycontextprocessor(request, context):
    print context.get('request')

Changed 6 years ago by Simon Litchfield

Attachment: 13841-docs.diff added

Updated docs.

comment:8 Changed 6 years ago by Simon Litchfield

Has patch: set
milestone: 1.4
Owner: changed from nobody to Russell Keith-Magee
Version: 1.2SVN

comment:9 Changed 6 years ago by Russell Keith-Magee

Owner: changed from Russell Keith-Magee to nobody

@simon29 - Please don't assign bugs to me without speaking to me first.

comment:10 Changed 6 years ago by Graham King

Severity: Normal
Type: New feature

comment:11 Changed 6 years ago by Julien Phalip

Needs tests: set

The patch needs tests. Could you also combine everything (new feature, tests and doc) within one single diff patch?

comment:12 Changed 5 years ago by Colin Copeland

Easy pickings: unset
Owner: changed from nobody to Colin Copeland
Status: newassigned
UI/UX: unset

Changed 5 years ago by Colin Copeland

Attachment: 13841_tests_docs.diff added

Combined diff with tests and docs

comment:13 Changed 5 years ago by Colin Copeland

Cc: copelco@… added
Needs tests: unset

I wrote tests and uploaded a combined diff with simon29's changes and docs.

Last edited 5 years ago by Colin Copeland (previous) (diff)

comment:14 Changed 5 years ago by Jacob

milestone: 1.4

Milestone 1.4 deleted

comment:15 Changed 3 years ago by Tim Graham

Patch needs improvement: set
Note: See TracTickets for help on using tickets.
Back to Top