Opened 17 years ago

Closed 17 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: 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)

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

Download all attachments as: .zip

Change History (15)

comment:1 by Simon G. <dev@…>, 17 years ago

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 by Chris Beaven, 17 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 anonymous, 17 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 Simon G. <dev@…>, 17 years ago

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 by Adrian Holovaty, 17 years ago

Resolution: wontfix
Status: closedreopened

comment:6 by Adrian Holovaty, 17 years ago

Triage Stage: Design decision neededAccepted

This is a good idea. Could somebody implement it?

comment:7 by Michael Radziej <mir@…>, 17 years ago

Keywords: reopen removed

comment:8 by GomoX <gomo@…>, 17 years ago

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 by Yopi <yannvr@…>, 17 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!

by Will McCutchen <mccutchen@…>, 17 years ago

Attachment: ifequal.diff added

First patch, against r4991

comment:10 by Will McCutchen <mccutchen@…>, 17 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 Will McCutchen <mccutchen@…>, 17 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 Will McCutchen <mccutchen@…>, 17 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 James Bennett, 17 years ago

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 by James Bennett, 17 years ago

Resolution: duplicate
Status: reopenedclosed

Duplicate of #1209.

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