Opened 10 years ago

Closed 9 years ago

#3075 closed enhancement (duplicate)

Ifequal tag extension to handle mask operators

Reported by: yopi <yannvr@…> 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: UI/UX:

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)

ifequal.diff (14.2 KB) - added by Will McCutchen <mccutchen@…> 10 years ago.
First patch, against r4991

Download all attachments as: .zip

Change History (15)

comment:1 Changed 10 years ago by Simon G. <dev@…>

Resolution: wontfix
Status: newclosed

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?

comment:2 Changed 10 years ago by Chris Beaven

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 Changed 10 years ago by anonymous

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 Changed 10 years ago by Simon G. <dev@…>

Keywords: reopen added
Triage Stage: UnreviewedDesign 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 Changed 10 years ago by Adrian Holovaty

Resolution: wontfix
Status: closedreopened

comment:6 Changed 10 years ago by Adrian Holovaty

Triage Stage: Design decision neededAccepted

This is a good idea. Could somebody implement it?

comment:7 Changed 10 years ago by Michael Radziej <mir@…>

Keywords: reopen removed

comment:8 Changed 10 years ago by GomoX <gomo@…>

Cc: gomo@… 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 Changed 10 years ago by Yopi <yannvr@…>

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!

Changed 10 years ago by Will McCutchen <mccutchen@…>

Attachment: ifequal.diff added

First patch, against r4991

comment:10 Changed 10 years ago by Will McCutchen <mccutchen@…>

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 Changed 10 years ago by Will McCutchen <mccutchen@…>

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 Changed 10 years ago by Will McCutchen <mccutchen@…>

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 Changed 10 years ago by James Bennett

Summary: [patch] Ifequal tag extension to handle mask operatorsIfequal 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.

comment:14 Changed 9 years ago by James Bennett

Resolution: duplicate
Status: reopenedclosed

Duplicate of #1209.

Note: See TracTickets for help on using tickets.
Back to Top