Opened 17 years ago

Closed 16 years ago

#5756 closed (fixed)

Any template tag that uses Variable instead of parser.compile_filter does not handle filters.

Reported by: sneeu Owned by: nobody
Component: Template system Version: dev
Severity: Keywords: tplrf-fixed
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

On a page with the URL '/account/login/', I would expect the following to work:

{% ifequal request.path|slice:"9" "/account/" %}Do something for account pages.{% endifequal %}

As I understand it the underlying code (for ifequal and other template tag) uses resolve_variable so the first argument becomes:

request.get('path|slice:":9"')

Currently a workaround using the 'with' template tag is required:

{% with request.path|slice:"9" as path_prefix %}Do something ...{% endwith %}

Attachments (3)

5756.patch (1.9 KB ) - added by Collin Grady <cgrady@…> 17 years ago.
5756.2.patch (6.2 KB ) - added by Antti Kaihola 16 years ago.
Filters as arguments for cycle, firstof, ifchanged, ifequal and include. Depends on #7295.
5756.3.patch (435 bytes ) - added by David Avsajanishvili 16 years ago.
A very little improvement of 5756.2.patch: changed line 182 in loader_tags.py (see #8088)

Download all attachments as: .zip

Change History (13)

comment:1 by Chris Beaven, 17 years ago

Triage Stage: UnreviewedAccepted

by Collin Grady <cgrady@…>, 17 years ago

Attachment: 5756.patch added

comment:2 by Collin Grady <cgrady@…>, 17 years ago

Only tag I saw that still did this was ifequal/ifnotequal - patch attached

comment:3 by Collin Grady <cgrady@…>, 17 years ago

Has patch: set

comment:4 by Chris Beaven, 17 years ago

Patch needs improvement: set
Summary: Any template tag that uses resolve_variable instead of parser.compile_filter does not handle filters.Any template tag that uses Variable instead of parser.compile_filter does not handle filters.

Checking source, we should probably fix this across the board (better to be consistent). Needs to be done for:

  • {% cycle %}
  • {% ifchanged %}
  • {% ifequal %}
  • {% firstof %}
  • {% include %} (in loader_tags)

comment:5 by Chris Beaven, 17 years ago

Keywords: easy-pickings added; ifequal variable filter template tag removed

in reply to:  4 comment:6 by Antti Kaihola, 16 years ago

Keywords: easy-pickings removed

Replying to SmileyChris:

  • {% cycle %}
  • {% ifchanged %}
  • {% ifequal %}
  • {% firstof %}
  • {% include %} (in loader_tags)

Enabling filter expressions as arguments to these tags turns out to be a bit complicated. Django's unit tests are full of single-quoted arguments to these tags, but compile_filter() (or actually FilterExpression) only supports double quotes. There are also issues with escaping quotes and translation.

These problems should be solved (#7295 has one possible patch) before going forward with this ticket.

by Antti Kaihola, 16 years ago

Attachment: 5756.2.patch added

Filters as arguments for cycle, firstof, ifchanged, ifequal and include. Depends on #7295.

comment:7 by Antti Kaihola, 16 years ago

Needs tests: set

The current patch for #7295 together with 5756.2.patch pass all current tests and make it possible to use filter expressions as arguments for the above mentioned five template tags.

Tests for the new feature should probably be added.

in reply to:  4 comment:8 by anonymous, 16 years ago

Replying to SmileyChris:

Checking source, we should probably fix this across the board (better to be consistent). Needs to be done for:

  • {% cycle %}
  • {% ifchanged %}
  • {% ifequal %}
  • {% firstof %}
  • {% include %} (in loader_tags)

It is probably too late in the game to bring this up, but should simple_tag handle this as well?

comment:9 by Johannes Dollinger, 16 years ago

Keywords: tplrf-fixed added

This would be fixed by the refactoring proposed in #7806 (which used akaihola's patch as a starting point, although not much is left).

by David Avsajanishvili, 16 years ago

Attachment: 5756.3.patch added

A very little improvement of 5756.2.patch: changed line 182 in loader_tags.py (see #8088)

comment:10 by Malcolm Tredinnick, 16 years ago

Resolution: fixed
Status: newclosed

(In [10119]) Fixed #5756, #6296 -- Most template tags can now handle filters in arguments.

Most of the hard work for this was done by akaihola.

There are still possibly some problems with the i18n template tags,
since they are written quite differently and a few other bug fixes have
to made before they can be fixed.

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