#17229: Invalid '==' expression silently ignored leading to invalid result
-------------------------------------+-------------------------------------
Reporter: anatoly techtonik | Owner: nobody
<techtonik@…> | Status: reopened
Type: Bug | Version: 1.2
Component: Template system | Resolution:
Severity: Normal | Triage Stage:
Keywords: | Unreviewed
Has patch: 0 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
-------------------------------------+-------------------------------------
Changes (by anatoly techtonik <techtonik@…>):
* status: closed => reopened
* needs_docs: 0 => 1
* resolution: invalid =>
Comment:
Replying to [comment:1 lukeplant]:
> Your example is invalid, because 'True' is not a literal that is
understood by the template language.
This explains the behavior, but doesn't solve the issue.
> Rather, the string 'True' in your template is interpreted as a variable
name. Since a variable called "True" does not exist in the context, the
behaviour you see above follows (though the full sequence of steps is a
little involved).
Don't you think that Pythonic template engine should allow standard Python
True/False keywords in comparison expressions? There is a clear need to
use them for NullBooleanField comparisons, which is impossible otherwise
(which is my case, btw, that your example below doesn't solve). The only
reason not to teach Django understand True/False literals is to allow
people set these variables in templates themselves, but I really don't
think you'd like to encourage such practice.
> The expression you want is simply:
> {{{
> {% if closed %}
> }}}
>
> If you want the negation:
>
> {{{
> {% if not closed %}
> }}}
>
>
> (This, by the way, is normally considered good style in Python as well.
Adding the no-op comparison `== True` is pointless - and so neither the
majority of Python developers nor template writers would intuitively write
this).
That's not what I want. In my case `closed` is NullBooleanField used as a
filter for issue list. `None` means that both open and closed issues
should be returned. I need to distinguish between `None` and `False`.
--
Ticket URL: <https://code.djangoproject.com/ticket/17229#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" 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-updates?hl=en.