Hi everyone,
I am having problems with a string comparison in a django template and
I'd very much appreciate some help here! This template is rendered
from a view and gets to variables:
- HTproblemImpact, a dictionary with strings as keys (the "problems")
and Impact objects as values. The Impact class has two attributes:
description (string) and value (integer). This dictionary contains the
default impact for each problem type, which the user could change in
the html form that I explain below.
- IMPACT_CHOICES, a tuple with the possible impacts, as strings. For
instance:
IMPACT_CHOICES = ( ("HI", "high"), ("LO", "low"), ... ,)
So this is part of my template:
<form action="/profiles/setProblems/" method="POST">
{% for problemType, problemImpact in
HTproblemImpact.items %}
<p>{{ problemType }}:
{{ problemImpact.description }}
{% for impact in IMPACT_CHOICES %}
<input type="radio" name="{{ problemType }}"
value="{{ impact.0 }}"
{% ifequal str(problemImpact.description)
(impact.0) %}
checked="true">
{% else %}
checked="false">
{% endifequal %}
{{ impact.1 }}
{% endfor %}
</p>
{% endfor %}
<input type="submit" value="Submit" />
</form>
The problem here is that the ifequal tag *always* returns true. I
could understand that it always returned false if it was a problem
with different string codings, but I don't know how it can be always
true. This is the HTML output for this part of the template:
<form action="/profiles/setProblems/" method="POST">
<p>ProblemX: ME
<input type="radio" name="ProblemX"
value="HI"
checked="true">
high
<input type="radio" name="ProblemX"
value="ME"
checked="true">
medium
<input type="radio" name="ProblemX"
value="LO"
checked="true">
low
<input type="radio" name="ProblemX"
value="NO"
checked="true">
none
</p>
<p>ProblemY: ME
<input type="radio" name="ProblemY"
value="HI"
checked="true">
high
<input type="radio" name="ProblemY"
value="ME"
checked="true">
medium
<input type="radio" name="ProblemY"
value="LO"
checked="true">
low
<input type="radio" name="ProblemY"
value="NO"
checked="true">
none
</p>
<input type="submit" value="Submit" />
</form>
Any idea of how to fix it? Thanks a lot!!
Pablo
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---