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

fix(paginator): #2556 Fixes paging page with previous item in list. #2558

Merged
merged 1 commit into from
Apr 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions templates/misc/paginator.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion templates/mp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
{% endfor %}
</div>

{% include "misc/pagination.part.html" with position='bottom' %}
{% include "misc/paginator.html" with position="bottom" %}
{% endblock %}


Expand Down
2 changes: 1 addition & 1 deletion zds/mp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions zds/utils/paginator.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,20 @@ 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):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Y'a pas de risques d'effets de bord hors des MP avec ceci ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ZdSPagingListView est utilisé uniquement dans les vues CVB (donc dans les vues refactorées) et la liste des messages d'un MP est la première à devoir récupérer le dernier message de la page précédente. La méthode (définie dans ZdSPagingListView) est donc utilisée nulle part ailleurs.

"""
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:
last_page = self.paginator.page(self.page.number - 1).object_list
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

Expand Down