digideskio / zotonic

Automatically exported from code.google.com/p/zotonic
0 stars 0 forks source link

New filter: is_not_a #160

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
is_not_a mirrors is_a. It is particularly useful when iterating over a category 
and excluding members of a sub-category (iterating over all images associated 
with a page except images in the thumbnail category).

The attached patch adds this filter. To reduce code duplication, it factorizes 
the behavior of filtering over a list (or a single item), including the 
optional argument to return the first n matching ids. is_visible and is_a are 
now based on the common module.

Original issue reported on code.google.com by pgu...@gmail.com on 12 Mar 2011 at 11:06

Attachments:

GoogleCodeExporter commented 8 years ago
How is this different from using:

{% if not(m.rsc[id]|is_a:"article") %}

basically you can put not() around any expression..

Original comment by scherpenisse on 16 Mar 2011 at 8:53

GoogleCodeExporter commented 8 years ago
I might have missed something. The form returning a boolean when passed a 
single item is only provided for completeness. I use is_not filter with a list :

{% with m.rsc[id].media|without_embedded_media:id|is_not_a:"thumbnail" as media 
%}
    {% if media %}
        {% for m in media %}
        ...
        <li {% if forloop.first %} class="show" {% endif %} >
            ...
        </li>
        {% endfor %}
        ...
    {% endif %} 
{% endwith %}

Can I do the same thing with not() ?

Original comment by pgu...@gmail.com on 16 Mar 2011 at 9:39