Hi again,
Unfortunately I haven't explained my point well from the beginning but
you've managed to understand where I was going with your last example.
I think you are right. I can always anotate the object with that key
and use it afterwards in the template.
Thanks for your time Russell,
João
On 10/24/06, Russell Keith-Magee <[EMAIL PROTECTED]> wrote:
>
> On 10/24/06, João Cruz Morais <[EMAIL PROTECTED]> wrote:
> >
> > 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.
>
> You shouldn't need to 'break'. Django's templates are _not_, nor will
> they ever be, a Turing complete programming language; the core
> developers will reject any suggestion to make it one.
>
> > 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 %}
>
> Well - as written, this should be constructed as
> {% if is_open %}
> {{ node.name }}
> {% endif %}
>
> with a context containing:
> is_open: node in open_nodes
>
> However, I presume that the actual problem you are driving at is:
>
> {% for node in nodes %}
> {% if node.id|in:open_nodes %}
> {{ node.name }}
> {% endif %}
> {% endfor %}
>
> In this specific case, the solution is:
>
> {% for node in open_nodes %}
> {{ node.name }}
> {% endfor %}
>
> but if you want to do more than just print a list of open nodes, or
> you want more complex processing dependent on the 'open' state, then
> one approach is to annotate the object list with the desired property:
> template
>
> {% for node in node_list %}
> {% if node.is_open %}
> {{ node.data.name }}
> {% endif %}
> {% endfor %}
>
> using a context containing:
> node_list: [{'data':node, 'is_open':node in open_nodes} for node in nodes]
>
> There are probably a dozen other ways to solve this problem that don't
> require adding complex operations to the template language, and don't
> require moving business logic into 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 [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-users
-~----------~----~----~----~------~----~------~--~---