Opened 18 years ago

Closed 14 years ago

Last modified 14 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@… 18 years ago.
0001-Moves-the-argument-matching-to-a-separate-function.diff (1.1 KB ) - added by Marcus Fredriksson 15 years ago.
0002-Adds-the-object_tag-decorator.diff (1.7 KB ) - added by Marcus Fredriksson 15 years ago.
0003-Adds-documentation-for-object_tag.diff (2.1 KB ) - added by Marcus Fredriksson 15 years ago.
0004-Adds-tests-for-object_tag.diff (2.1 KB ) - added by Marcus Fredriksson 15 years ago.
object_tag-combined-patch.diff (6.8 KB ) - added by Marcus Fredriksson 15 years ago.
Following Alex's advice by providing a single patch file
fix2016.patch (7.0 KB ) - added by Matthias Kestenholz 14 years ago.

Download all attachments as: .zip

Change History (17)

by jason@…, 18 years ago

Attachment: object_tag.patch added

comment:1 by Adrian Holovaty, 18 years ago

Status: newassigned

comment:2 by Chris Beaven, 18 years ago

Needs tests: set
Triage Stage: UnreviewedDesign decision needed

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

comment:3 by Chris Beaven, 18 years ago

Needs documentation: set
Needs tests: unset

comment:4 by Jacob, 17 years ago

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

by Marcus Fredriksson, 15 years ago

by Marcus Fredriksson, 15 years ago

by Marcus Fredriksson, 15 years ago

comment:5 by Marcus Fredriksson, 15 years ago

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

comment:6 by Alex Gaynor, 15 years ago

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

by Marcus Fredriksson, 15 years ago

Following Alex's advice by providing a single patch file

comment:7 by Marcus Fredriksson, 15 years ago

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

comment:8 by Matthias Kestenholz, 14 years ago

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

Updated patch for current trunk.

by Matthias Kestenholz, 14 years ago

Attachment: fix2016.patch added

comment:9 by Matthias Kestenholz, 14 years ago

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 by Julien Phalip, 14 years ago

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