From 1d5428f866c8af656190a4252b73618296338d17 Mon Sep 17 00:00:00 2001 From: Gerard Paligot Date: Wed, 15 Apr 2015 21:01:39 +0200 Subject: [PATCH] fix(paginator): #2556 Fixes paging page with previous item in list. --- templates/misc/paginator.html | 3 +-- templates/mp/index.html | 2 +- zds/mp/views.py | 2 +- zds/utils/paginator.py | 5 +++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/templates/misc/paginator.html b/templates/misc/paginator.html index ccb5a0d12a..e433beafe8 100644 --- a/templates/misc/paginator.html +++ b/templates/misc/paginator.html @@ -2,8 +2,7 @@ {% load append_to_get %} {% load i18n %} - -{% if page_obj|length > 1 %} +{% if paginator.num_pages > 1 %} {% captureas full_anchor %} {% if anchor %} #{{ anchor }} diff --git a/templates/mp/index.html b/templates/mp/index.html index 6fb0a627f7..8a0026fa2b 100644 --- a/templates/mp/index.html +++ b/templates/mp/index.html @@ -81,7 +81,7 @@ {% endfor %} - {% include "misc/pagination.part.html" with position='bottom' %} + {% include "misc/paginator.html" with position="bottom" %} {% endblock %} diff --git a/zds/mp/views.py b/zds/mp/views.py index 3dbcb82bb0..80ceebdc5a 100644 --- a/zds/mp/views.py +++ b/zds/mp/views.py @@ -263,7 +263,7 @@ def get_context_data(self, **kwargs): context['topic'] = self.object context['last_post_pk'] = self.object.last_message.pk context['form'] = PrivatePostForm(self.object) - context['posts'] = self.build_list() + context['posts'] = self.build_list_with_previous_item(context['object_list']) if never_privateread(self.object): mark_read(self.object) return context diff --git a/zds/utils/paginator.py b/zds/utils/paginator.py index 513e106e14..4992552937 100644 --- a/zds/utils/paginator.py +++ b/zds/utils/paginator.py @@ -40,11 +40,12 @@ def get_context_data(self, **kwargs): context.update(kwargs) return super(MultipleObjectMixin, self).get_context_data(**context) - def build_list(self): + def build_list_with_previous_item(self, queryset): """ For some list paginated, we would like to display the last item of the previous page. This function returns the list paginated with this previous item. """ + original_list = queryset.all() list = [] # If necessary, add the last item in the previous page. if self.page.number != 1: @@ -52,7 +53,7 @@ def build_list(self): last_item = (last_page)[len(last_page) - 1] list.append(last_item) # Adds all items of the list paginated. - for item in self.object_list: + for item in original_list: list.append(item) return list