Opened 13 years ago

Closed 8 years ago

Last modified 8 years ago

#2016 closed enhancement (fixed)

[patch] Decorator for template tags that load objects

Reported by: jason@… Owned by: nobody
Component: Template system Version:
Severity: normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The django.template module includes two convenient decorators for making certain common template tags, simple_tag for inserting strings and inclusion_tag for including other templates. Another common idiom is loading an object into the template. For example:

{% get_recent_articles 4 as recent_articles %}

This patch includes an object_tag decorator that makes this kind of tag easy.

I'm new to Django and don't know how this fits in with the refactoring going on now, but I found it quite useful.

Attachments (7)

object_tag.patch (1.7 KB) - added by jason@… 13 years ago.
0001-Moves-the-argument-matching-to-a-separate-function.diff (1.1 KB) - added by Marcus Fredriksson 10 years ago.
0002-Adds-the-object_tag-decorator.diff (1.7 KB) - added by Marcus Fredriksson 10 years ago.
0003-Adds-documentation-for-object_tag.diff (2.1 KB) - added by Marcus Fredriksson 10 years ago.
0004-Adds-tests-for-object_tag.diff (2.1 KB) - added by Marcus Fredriksson 10 years ago.
object_tag-combined-patch.diff (6.8 KB) - added by Marcus Fredriksson 10 years ago.
Following Alex's advice by providing a single patch file
fix2016.patch (7.0 KB) - added by Matthias Kestenholz 9 years ago.

Download all attachments as: .zip

Change History (17)

Changed 13 years ago by jason@…

Attachment: object_tag.patch added

comment:1 Changed 13 years ago by Adrian Holovaty

Status: newassigned

comment:2 Changed 13 years ago by Chris Beaven

Needs tests: set
Triage Stage: UnreviewedDesign decision needed

Did Adrian's "assigned" means that this was approved?

comment:3 Changed 13 years ago by Chris Beaven

Needs documentation: set
Needs tests: unset

comment:4 Changed 12 years ago by Jacob

Needs tests: set
Patch needs improvement: set
Triage Stage: Design decision neededAccepted

Changed 10 years ago by Marcus Fredriksson

Changed 10 years ago by Marcus Fredriksson

Changed 10 years ago by Marcus Fredriksson

Changed 10 years ago by Marcus Fredriksson

comment:5 Changed 10 years ago by Marcus Fredriksson

Added my own attempt to provide an improved patch along with documentation and tests.

comment:6 Changed 10 years ago by Alex Gaynor

Please provide a single diff from the root of the source tree, rather than several files.

Changed 10 years ago by Marcus Fredriksson

Following Alex's advice by providing a single patch file

comment:7 Changed 10 years ago by Marcus Fredriksson

Sorry for the inconvenience, I've attached the new combined patch.

comment:8 Changed 9 years ago by Matthias Kestenholz

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

Updated patch for current trunk.

Changed 9 years ago by Matthias Kestenholz

Attachment: fix2016.patch added

comment:9 Changed 8 years ago by Matthias Kestenholz

Resolution: fixed
Status: assignedclosed

Let's be bold and close this ticket. @simple_tag has a takes_context parameter now making this ticket obsolete.

comment:10 Changed 8 years ago by Julien Phalip

Just for posterity, the resolution would actually be duplicate of #14262. Although it is more recent, it also has a more up-to-date discussion about the preferred API.

Note: See TracTickets for help on using tickets.
Back to Top