Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regions selection in nav bar mixes up entries #570

Closed
pitpalme opened this issue Apr 4, 2022 · 1 comment · Fixed by #578
Closed

Regions selection in nav bar mixes up entries #570

pitpalme opened this issue Apr 4, 2022 · 1 comment · Fixed by #578
Labels

Comments

@pitpalme
Copy link
Contributor

pitpalme commented Apr 4, 2022

Describe the bug
Countries and regions are not display correctly grouped, but somehow mixed up.
We have 2 Germany, 3 Berlin/Brandenburg and all contain different locations/places.
It's confusing.

To Reproduce
See screenshots.

Expected behavior
Places shown grouped correctly, by areas and regions and countries.

Screenshots
image
image
image

@pitpalme
Copy link
Contributor Author

pitpalme commented Apr 7, 2022

Seems, we ran into a 16 year old, known, behavior:

REGROUP tag makes two groups with the same value

I think it works just as intended. From Django documentation:
Note that {% regroup %} does not work when the list to be grouped is not sorted by the key you are grouping by! This means that if your list of people was not sorted by gender, you'd need to make sure it is sorted before using it, i.e.:
{% regroup people|dictsort:"gender" by gender as grouped %}

Built-in template tags and filters: regroup

Note that {% regroup %} does not order its input! Our example relies on the fact that the cities list was ordered by country in the first place. If the cities list did not order its members by country, the regrouping would naively display more than one group for a single country. For example, say the cities list was set to this (note that the countries are not grouped together):

pitpalme added a commit to pitpalme/volunteer_planner that referenced this issue Apr 7, 2022
Django templatetag regroup requires properly sorted data structure,
otherwise intermediate items might be duplicated.
This change fixes the bug by using proper order_by clause on queryset.
@pitpalme pitpalme linked a pull request Apr 7, 2022 that will close this issue
pitpalme added a commit that referenced this issue Apr 8, 2022
Fixes #570: regions nav bar items not sorted well
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant