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)
Change History (13)
comment:1 by , 17 years ago
Triage Stage: | Unreviewed → Accepted |
---|
by , 17 years ago
Attachment: | 5756.patch added |
---|
comment:2 by , 17 years ago
comment:3 by , 17 years ago
Has patch: | set |
---|
follow-ups: 6 8 comment:4 by , 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 %}
(inloader_tags
)
comment:5 by , 17 years ago
Keywords: | easy-pickings added; ifequal variable filter template tag removed |
---|
comment:6 by , 16 years ago
Keywords: | easy-pickings removed |
---|
Replying to SmileyChris:
{% cycle %}
{% ifchanged %}
{% ifequal %}
{% firstof %}
{% include %}
(inloader_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 , 16 years ago
Attachment: | 5756.2.patch added |
---|
Filters as arguments for cycle, firstof, ifchanged, ifequal and include. Depends on #7295.
comment:7 by , 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.
comment:8 by , 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 %}
(inloader_tags
)
It is probably too late in the game to bring this up, but should simple_tag handle this as well?
comment:9 by , 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 , 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 , 16 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
(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.
Only tag I saw that still did this was ifequal/ifnotequal - patch attached