ELIF using not in, within a FOR

0

I would like to know if there is any way to refine the ELIF within a FOR, so that it does not enter in the FOR whenever the date does not exist, but rather if that date does not exist.

Here's the problem:

For each meeting date

{%for u in i.chamada_set.get.datas_encontros.filter|dictsort:"data_ano"%}

Sign in for each completed date

{% for a in i.chamada_set.get.finalizada_set.filter %}

And check if:

{%if a.data_finalizada|date:"d, m, Y" == u.data_ano|date:"d, m, Y"%}

The date ended is equal to the date of the meeting, but if I have 3 dates completed, only 1 would fall in that if and the other 2 in the

Then I thought about ELIF

{%elif u.data_ano|date:"d, m, Y" not in a.data_finalizada|date:"d, m, Y" %}

But continued entering because the other dates ended, are not equal to the date encounter.

Image:

Ingreenarethefinisheddates,inPersonOne,havethefollowingdateorderended[06/11/2018,08/11/2018,11/13/2018]

Themainideawouldbetoshowthatyoudidnotfindthedate,anditworkswhenyouhaveonlyonedate(PersonTwoandPersonThree).

TRcode:

{%foryini.chamada_set.get.alunos.filter%}<tr><td>{{y.nome_aluno}}{{y.sobrenome_aluno}}</td><td>{{y.cgu_aluno}}</td>{%foruini.chamada_set.get.datas_encontros.filter|dictsort:"data_ano"%}
        {% for a in i.chamada_set.get.finalizada_set.filter %}
            {%if a.data_finalizada|date:"d, m, Y" == u.data_ano|date:"d, m, Y" and y.id == a.aluno_finalizado.id %}
                <td style="color:green">
                    <i class="">encontrou </i>
                    <i class="">{{u.data_ano|date:"d, m, Y"}}</i>
                </td>
            {%elif u.data_ano|date:"d, m, Y" not in a.data_finalizada|date:"d, m, Y" and y.id == a.aluno_finalizado.id  %}
                <td  style="color:tomato">
                    <i class="">não é a data: </i>
                    <i class="">{{u.data_ano|date:"d, m, Y"}}</i>
                </td>
            {%endif%}
        {%endfor%}
    {%endfor%}
    </tr>
{%endfor%}
    
asked by anonymous 08.11.2018 / 00:37

2 answers

1

I removed this part of the Jinja2 documentation: Template Designer Documentation

  

Unlike in Python, it's not possible to break or continue in a loop.   You can, however, filter the sequence during iteration, which allows   you to skip items. The following example skips all the users which are   hidden:

{% for user in users if not user.hidden %}
    <li>{{ user.username|e }}</li>
{% endfor %}

One tip that can help is to use the index of for as a counter to help you escape in if.

    
13.11.2018 / 11:39
0

I found this other information that can help a lot. For there is no break but if so. take a look if it helps you

Docucmentation link

  

Loop Controls

     

If the application enables the Loop Controls, it's   possible to use break and continue in loops. When break is reached,   the loop is terminated; if continue, the processing is   stopped and continues with the next iteration.

     

Here's a loop that skips every second item:

{% for user in users %}
    {%- if loop.index is even %}{% continue %}{% endif %}
    ... {% endfor %} 
     

Likewise, a loop that stops processing after the 10th iteration:

{% for user in users %}
    {%- if loop.index >= 10 %}{% break %}{% endif %} 
{%- endfor %}
     

Note that loop.index starts with 1, and loop.index0 starts with 0

    
19.11.2018 / 12:34