#27126: Use `namedtuple` in result of `{% regroup %}`
--------------------------------------+------------------------------------
     Reporter:  bmispelon             |                    Owner:  nobody
         Type:  Cleanup/optimization  |                   Status:  new
    Component:  Template system       |                  Version:  1.10
     Severity:  Normal                |               Resolution:
     Keywords:                        |             Triage Stage:  Accepted
    Has patch:  1                     |      Needs documentation:  0
  Needs tests:  0                     |  Patch needs improvement:  0
Easy pickings:  0                     |                    UI/UX:  0
--------------------------------------+------------------------------------
Changes (by timgraham):

 * stage:  Unreviewed => Accepted


Old 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:
> {{{#!django
> {% 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>
>
> }}}

New description:

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

 I propose changing 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:
 {{{#!django
 {% 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>

 }}}

--

--
Ticket URL: <https://code.djangoproject.com/ticket/27126#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.dd5318d45b8fa3302248130d2c55f5e3%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to