Opened 9 years ago

Closed 4 years ago

Last modified 4 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: UI/UX:

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@… 9 years ago.
0001-Moves-the-argument-matching-to-a-separate-function.diff (1.1 KB) - added by marcusf 6 years ago.
0002-Adds-the-object_tag-decorator.diff (1.7 KB) - added by marcusf 6 years ago.
0003-Adds-documentation-for-object_tag.diff (2.1 KB) - added by marcusf 6 years ago.
0004-Adds-tests-for-object_tag.diff (2.1 KB) - added by marcusf 6 years ago.
object_tag-combined-patch.diff (6.8 KB) - added by marcusf 6 years ago.
Following Alex's advice by providing a single patch file
fix2016.patch (7.0 KB) - added by mk 5 years ago.

Download all attachments as: .zip

Change History (17)

Changed 9 years ago by jason@…

comment:1 Changed 9 years ago by adrian

  • Status changed from new to assigned

comment:2 Changed 9 years ago by SmileyChris

  • Needs tests set
  • Triage Stage changed from Unreviewed to Design decision needed

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

comment:3 Changed 9 years ago by SmileyChris

  • Needs documentation set
  • Needs tests unset

comment:4 Changed 8 years ago by jacob

  • Needs tests set
  • Patch needs improvement set
  • Triage Stage changed from Design decision needed to Accepted

Changed 6 years ago by marcusf

Changed 6 years ago by marcusf

Changed 6 years ago by marcusf

comment:5 Changed 6 years ago by marcusf

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

comment:6 Changed 6 years ago by Alex

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

Changed 6 years ago by marcusf

Following Alex's advice by providing a single patch file

comment:7 Changed 6 years ago by marcusf

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

comment:8 Changed 5 years ago by mk

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

Updated patch for current trunk.

Changed 5 years ago by mk

comment:9 Changed 4 years ago by mk

  • Resolution set to fixed
  • Status changed from assigned to closed

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

comment:10 Changed 4 years ago by julien

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