Code

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#1903 closed enhancement (invalid)

[patch] to add filter "get" to add getting data from dicts and lists

Reported by: erickt@… Owned by: adrian
Component: Template system 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

Any chance this could be added? I want to display a list of items with user customizable columns. I couldn't see any other way to do this other than implementing a filter. It seems like it would be a fairly fundamental filter, but it's absent from the library ("slice" isn't appropriate as dicts don't play nice with them). An alternative, of course, would be to have "getitem" and "getattr" filter, but that's slightly more verbose and technical. Any chance this could be added? Thanks.

-e

Attachments (2)

get-patch (1.4 KB) - added by erickt@… 8 years ago.
patch to add feature
get-patch.diff (1.4 KB) - added by erickt@… 8 years ago.
adding the .diff extension to get highlighting working

Download all attachments as: .zip

Change History (4)

Changed 8 years ago by erickt@…

patch to add feature

comment:1 Changed 8 years ago by erickt@…

  • Summary changed from patch to add filter "get" to add getting data from dicts and lists to [patch] to add filter "get" to add getting data from dicts and lists

fixing the summary

Changed 8 years ago by erickt@…

adding the .diff extension to get highlighting working

comment:2 Changed 8 years ago by mtredinnick

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

Your patch seems to do exactly the same as {{ data.a }} does in a template (if data is a dictionary, this will retrieve data['a']). If this is not what you want to happen, then please reopen with a more concrete example (showing how this would act in a template; the test cases you include are not completely clear, except to make me think it acts like something we already have).

If you want something that can dereference the value of template variable "a" to get the real value to look up in the dictionary (i.e. if {{a}} is "b", it looks up data['b']), we have traditionally avoided adding features like this to Django's templating language in order to keep it as simple as possible. The justification is that you should extract the data you really need in the view function and pass it in, rather than doing the programming in the template.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


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

 
Note: See TracTickets for help on using tickets.