fix grouping

This commit is contained in:
thomas girod 2024-07-25 18:00:20 +02:00 committed by Bartuccio Antoine
parent d348e6314a
commit 3c76c5e0f1
2 changed files with 8 additions and 3 deletions

View File

@ -22,10 +22,10 @@
{% if can_edit(profile, user) %}
<button disabled id="download" onclick="download('{{ url('api:pictures') }}?users_identified={{ object.id }}')">{% trans %}Download all my pictures{% endtrans %}</button>
{% endif %}
{% for album, album_pictures in pictures|groupby("album") %}
{% for album, pictures in albums|items %}
<h4>{{ album }}</h4>
<div class="photos">
{% for picture in album_pictures %}
{% for picture in pictures %}
{% if picture.can_be_viewed_by(user) %}
<a href="{{ url("sas:picture", picture_id=picture.id) }}#pict">
<div

View File

@ -21,6 +21,7 @@
# Place - Suite 330, Boston, MA 02111-1307, USA.
#
#
import itertools
# This file contains all the views that concern the user model
from datetime import date, timedelta
@ -312,11 +313,15 @@ class UserPicturesView(UserTabsMixin, CanViewMixin, DetailView):
def get_context_data(self, **kwargs):
kwargs = super().get_context_data(**kwargs)
kwargs["pictures"] = list(
pictures = list(
Picture.objects.filter(people__user_id=self.object.id)
.order_by("-parent__date", "-date")
.annotate(album=F("parent__name"))
)
kwargs["albums"] = {
album: list(picts)
for album, picts in itertools.groupby(pictures, lambda i: i.album)
}
return kwargs