What if this filter is being used inside a loop and node is changing all the time, which happens to be the case? Another loop just to find out if a node is inside a list of nodes is not only slower and verbose but also a dumb method, since we can't even break as soon as we have a positive response.
Compare: {% for _node in open_nodes %} {% ifequal node.id _node.id %} {{ node.name }} {% endif %} {% endfor %} with: {% if node.id|in:open_nodes %} {{ node.name }} {% endif %} I'm aware that this could have been done at the logic level by iterating through all the nodes and adding a new bool key stating if they were opened, but IMHO using the in keyword inside the templates doesn't break the layer separation that django is trying to enforce. My 2 cents :) João Russell Keith-Magee wrote: > On 10/23/06, João Cruz Morais <[EMAIL PROTECTED]> wrote: > >>Hi there, >> >>Some time ago I've submitted this filter - >>http://code.djangoproject.com/ticket/2741 - because i thought it was too >>simple and obvious to be left outside the builtin pack. >>Adrian rejected the purposal, and never said why, so I'm wondering, do >>you know any other way to achieve this filter objective without, of >>course, resorting to new filters/tags/etc? > > > I haven't spoken to Adrian about his reasons, but I suspect I know why > he rejected this proposal, and I would have rejected it for the same > reason. > > Django is very explicit about templates not containing view logic. If > you are checking set/list membership in a template, it indicates that > there is some aspect of the view that you are not adequately capturing > in your context. > > The right way to do this would be to put the 'IN' condition as a > context variable (e.g., is_open: node.id in open_nodes), and then use > a standard 'if' template tag (e.g., {%if is_open %}). > > This maintains the separation of template from view; you can modify > the conditions under which the is_open block is displayed without > having to modify the template. > > Yours, > Russ Magee %-) > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~----------~----~----~----~------~----~------~--~---