Code

Opened 4 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: copelco
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: no
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 simon29 3 years ago.
13841-docs.diff (1.1 KB) - added by simon29 3 years ago.
Updated docs.
13841_tests_docs.diff (4.7 KB) - added by copelco 3 years ago.
Combined diff with tests and docs

Download all attachments as: .zip

Change History (17)

comment:1 Changed 4 years ago by mitar

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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

comment:2 Changed 4 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 4 years ago by gregmuellegger

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 4 years ago by mitar

There was completely no response on the mailing list.

comment:5 Changed 3 years ago by russellm

  • Triage Stage changed from Unreviewed to Accepted

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

comment:6 Changed 3 years ago by simon29

  • Cc simon@… added

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

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

Changed 3 years ago by simon29

comment:7 Changed 3 years ago by simon29

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 3 years ago by simon29

Updated docs.

comment:8 Changed 3 years ago by simon29

  • Has patch set
  • milestone set to 1.4
  • Owner changed from nobody to russellm
  • Version changed from 1.2 to SVN

comment:9 Changed 3 years ago by russellm

  • Owner changed from russellm to nobody

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

comment:10 Changed 3 years ago by graham_king

  • Severity set to Normal
  • Type set to New feature

comment:11 Changed 3 years ago by julien

  • 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 3 years ago by copelco

  • Easy pickings unset
  • Owner changed from nobody to copelco
  • Status changed from new to assigned
  • UI/UX unset

Changed 3 years ago by copelco

Combined diff with tests and docs

comment:13 Changed 3 years ago by copelco

  • Cc copelco@… added
  • Needs tests unset

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

Last edited 3 years ago by copelco (previous) (diff)

comment:14 Changed 3 years ago by jacob

  • milestone 1.4 deleted

Milestone 1.4 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as assigned
The owner will be changed from copelco to anonymous. Next status will be 'assigned'
The ticket will be disowned. Next status will be 'new'
as The resolution will be set. Next status will be 'closed'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.