Opened 18 years ago
Closed 17 years ago
#3075 closed enhancement (duplicate)
Ifequal tag extension to handle mask operators
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Template system | Version: | |
Severity: | normal | Keywords: | |
Cc: | gomo@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I suggest extending the {% if(not)equal ... %} tags to handle operators
such 'and' and 'or' (as it is done for the the simple {% if %} tag.
Attachments (1)
Change History (15)
comment:1 by , 18 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
comment:2 by , 18 years ago
Personally, I think we could do away with ifequal and just provide more logic in if
like {% if a = b and b = c %}
but that's another issue.
comment:3 by , 18 years ago
My suggestion is meant to support the DRY principle which
is broken sometimes when you want to give rights to more than
one user in the template.
Please consider the example of tag management for an item that
both the owner and the member of his group can remove:
{% ifequal tag.user profile.user %}
<a href="/delete-tag/{{tag.id}}">-</a>
{% endifequal %}
{% ifequal tag.user_group profile.group %}
<a href="/delete-tag/{{tag.id}}">-</a>
{% endif %}
{% endifequal %}
My suggestion is:
{% ifequal tag.user profile.user or tag.group profile.user_group %}
<a href="/delete-tag/{{tag.id}}">-</a>
{% endif %}
In other words, introducing advanced logic with the ifequal tag (just
as it has been done for the if tag).
comment:4 by , 18 years ago
Keywords: | reopen added |
---|---|
Triage Stage: | Unreviewed → Design decision needed |
Ok, I'll change to Design Decision needed & let one of the core devs decide. Feel free to bring up on the django-developers mailing list for discussion too.
comment:5 by , 18 years ago
Resolution: | wontfix |
---|---|
Status: | closed → reopened |
comment:6 by , 18 years ago
Triage Stage: | Design decision needed → Accepted |
---|
This is a good idea. Could somebody implement it?
comment:7 by , 18 years ago
Keywords: | reopen removed |
---|
comment:8 by , 18 years ago
Cc: | added |
---|
I don't think the syntax is very intuitive. Although "ifequal a b or c" can be mentally parsed to "if a == b or a == c", it takes quite a bit of guesswork. I think adding "==" support to plain if would be nicer, or maybe even changing the syntax to "ifequal a b or a c", so that it is clear what you are comparing.
comment:9 by , 18 years ago
GomoX, this is really completing a missing feature of the ifequal tag. Then it would just work like the if tag. it couldn't be more intuitive for django users.
I think this feature is really needed!
comment:10 by , 18 years ago
Has patch: | set |
---|
I just added a patch to implement 'and' and 'or' clauses. I added some info to the documentation, but it probably needs improvement (not to mention the rest of the patch).
comment:11 by , 18 years ago
I should note that the patch uses IfNode.LinkTypes.and_
and IfNode.LinkTypes.or_
. That seemed like the most DRY approach, but I wasn't sure if I should maybe factor that enumeration out into its own class which IfNode
and IfEqualNode
could then use.
comment:12 by , 18 years ago
Summary: | Ifequal tag extension to handle mask operators → [patch] Ifequal tag extension to handle mask operators |
---|
Changed summary to indicate that a patch has been attached.
comment:13 by , 18 years ago
Summary: | [patch] Ifequal tag extension to handle mask operators → Ifequal tag extension to handle mask operators |
---|
The has_patch
checkbox on the ticket now allows us to indicate the presence of a patch without changing the ticket summary, so please use that in the future instead of changing summaries.
I'm marking this as wontfix as I think this becomes unnecessarily complex - what does {% ifequal foo bar and baz %} mean? or {% ifnotequal foo bar or baz %} ?
Can you give an example when this would be useful and more elegant than a combination of other tags?