Django

Code

Ticket #6296 (closed: fixed)

Opened 2 years ago

Last modified 11 months ago

[patch]ifequal, filter and hardcoded-string doesn't work

Reported by: philipp@igowo.de Assigned to: thejaswi_puthraya
Milestone: Component: Template system
Version: SVN Keywords: ifequal filter hardcoded string tplrf-fixed
Cc: thejaswi.puthraya@gmail.com Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

Hi, I just experienced the following problem:

Let:

>>> url = "/home/test/"
>>> urlparts = url.trim("/").split("/")

['home', 'test']

In the template I have:

{% ifequal urlparts|first "home" %}test1{% endifequal %}
{% ifequal urlparts|first home %}test2{% endifequal %}

Only the "test2" gets shown.

Attachments

6296.diff (3.1 kB) - added by thejaswi_puthraya on 01/05/08 22:22:42.
patch and tests

Change History

01/05/08 08:02:14 changed by thejaswi_puthraya

  • status changed from new to assigned.
  • cc set to thejaswi.puthraya@gmail.com.
  • needs_better_patch changed.
  • needs_tests set to 1.
  • owner changed from nobody to thejaswi_puthraya.
  • needs_docs changed.
  • has_patch set to 1.
  • stage changed from Unreviewed to Accepted.

The problem with ifequal is that it accepts only variables and doesn't allow any filters. So the urlparts|first variable is not resolved. In the second case (mentioned in the ticket) when home (or any values say abc) is given, this variable too gets resolved as None (because it is neither a Float, Integer or String) in the IfEqual? Node and hence the equality case arises.

I have added patches by replacing the Variable with a FilterExpression?. Even if a plain Variable is given it gets resolved without any problems. I shall add a couple of tests very soon.

01/05/08 22:22:42 changed by thejaswi_puthraya

  • attachment 6296.diff added.

patch and tests

01/05/08 22:26:48 changed by thejaswi_puthraya

  • needs_tests deleted.
  • summary changed from ifequal, filter and hardcoded-string doesn't work to [patch]ifequal, filter and hardcoded-string doesn't work.

This ticket looks very similar to #5756. But that ticket includes nodes like Cycle Node and Ifchanged Node. Since making such a big change would require a design decision, I have patched only for the Ifequal node.

07/18/08 14:03:05 changed by emulbreh

  • keywords changed from ifequal filter hardcoded string to ifequal filter hardcoded string tplrf-fixed.

This would be fixed by the refactoring proposed in #7806.

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

  • status changed from assigned 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 #6296 ([patch]ifequal, filter and hardcoded-string doesn't work)




Change Properties
Action