Opened 8 years ago

Last modified 8 years ago

#27126 closed Cleanup/optimization

Use `namedtuple` in result of `{% regroup %}` — at Initial Version

Reported by: Baptiste Mispelon Owned by: nobody
Component: Template system Version: 1.10
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Currently, {% regroup %} returns a list of dictionaries with two key (grouper and list).

I propose chaning that to return a namedtuple with the same fields.

This should be backwards-compatible because attribute access and key access inside template uses the same syntax.

The added benefit would be that you could now write:

{% regroup places by country as country_list %}

<ul>
{% for country, cities in country_list %}
    <li>{{ country }}
    <ul>
        {% for city in cities %}
          <li>{{ city.name }}: {{ city.population }}</li>
        {% endfor %}
    </ul>
    </li>
{% endfor %}
</ul>

Change History (0)

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