Django

Code

Ticket #5756 (closed: fixed)

Opened 2 years ago

Last modified 3 months ago

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

Reported by: sneeu Assigned to: nobody
Milestone: Component: Template system
Version: SVN Keywords: tplrf-fixed
Cc: Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 1 Patch needs improvement: 1

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

5756.patch (1.9 kB) - added by Collin Grady <cgrady@the-magi.us> on 02/01/08 19:25:48.
5756.2.patch (6.2 kB) - added by akaihola on 05/23/08 10:42:05.
Filters as arguments for cycle, firstof, ifchanged, ifequal and include. Depends on #7295.
5756.3.patch (435 bytes) - added by avsd on 08/02/08 15:10:51.
A very little improvement of 5756.2.patch: changed line 182 in loader_tags.py (see #8088)

Change History

01/03/08 03:35:29 changed by SmileyChris

  • needs_better_patch changed.
  • stage changed from Unreviewed to Accepted.
  • needs_tests changed.
  • needs_docs changed.

02/01/08 19:25:48 changed by Collin Grady <cgrady@the-magi.us>

  • attachment 5756.patch added.

02/01/08 19:27:07 changed by Collin Grady <cgrady@the-magi.us>

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

02/01/08 20:41:59 changed by Collin Grady <cgrady@the-magi.us>

  • has_patch set to 1.

(follow-ups: ↓ 6 ↓ 8 ) 02/21/08 14:23:19 changed by SmileyChris

  • needs_better_patch set to 1.
  • summary changed from Any template tag that uses resolve_variable instead of parser.compile_filter does not handle filters. to 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)

02/21/08 14:59:28 changed by SmileyChris

  • keywords changed from ifequal variable filter template tag to easy-pickings.

(in reply to: ↑ 4 ) 05/23/08 06:36:18 changed by akaihola

  • keywords deleted.

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.

05/23/08 10:42:05 changed by akaihola

  • attachment 5756.2.patch added.

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

05/23/08 10:45:29 changed by akaihola

  • needs_tests set to 1.

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 ) 07/09/08 20:10:15 changed by anonymous

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?

07/18/08 14:00:17 changed by emulbreh

  • keywords set to tplrf-fixed.

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

08/02/08 15:10:51 changed by avsd

  • attachment 5756.3.patch added.

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

03/23/09 04:42:51 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

(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.


Add/Change #5756 (Any template tag that uses Variable instead of parser.compile_filter does not handle filters.)




Change Properties
Action