From 61d27655104657caba7db2d3f1572b8e1fa1781f Mon Sep 17 00:00:00 2001 From: Skia Date: Wed, 2 Aug 2017 20:12:36 +0200 Subject: [PATCH] core: refactor user picture page algorithm Signed-off-by: Skia --- core/templates/core/user_pictures.jinja | 11 +++++------ core/views/user.py | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/core/templates/core/user_pictures.jinja b/core/templates/core/user_pictures.jinja index 4cae6f78..23e70cea 100644 --- a/core/templates/core/user_pictures.jinja +++ b/core/templates/core/user_pictures.jinja @@ -5,15 +5,14 @@ {% endblock %} {% block content %} -{% set picture_qs = profile.pictures.exclude(picture=None).order_by('-picture__parent__id', 'id').select_related('picture__parent__parent__name') %} -{% for a in picture_qs.distinct('picture__parent') %} +{% for a in albums %}
-

{{ a.picture.parent.name }}

+

{{ a.name }}


- {% for r in picture_qs.filter(picture__parent=a.picture.parent) -%} + {% for picture in pictures[a.id] %} {% endfor %} diff --git a/core/views/user.py b/core/views/user.py index 99ecc355..5f943c51 100644 --- a/core/views/user.py +++ b/core/views/user.py @@ -258,6 +258,21 @@ class UserPicturesView(UserTabsMixin, CanViewMixin, DetailView): template_name = "core/user_pictures.jinja" current_tab = 'pictures' + def get_context_data(self, **kwargs): + kwargs = super(UserPicturesView, self).get_context_data(**kwargs) + kwargs['albums'] = [] + kwargs['pictures'] = {} + picture_qs = self.object.pictures.exclude(picture=None).order_by('-picture__parent__date', 'id').select_related('picture__parent__name') + last_album = None + for pict_relation in picture_qs: + album = pict_relation.picture.parent + if album.id != last_album: + kwargs['albums'].append(album) + kwargs['pictures'][album.id] = [] + last_album = album.id + print(album, album.date) + kwargs['pictures'][album.id].append(pict_relation.picture) + return kwargs class UserGodfathersView(UserTabsMixin, CanViewMixin, DetailView): """