From 370e3de5df0e40c000ed9c5e69c727455ea6ffdc Mon Sep 17 00:00:00 2001 From: nitely Date: Thu, 30 Jul 2015 23:22:58 -0300 Subject: [PATCH] core.utils infinite paginator refactor This module should be moved to the infinite-paginator app --- .../utils/paginator/infinite_paginator.py | 19 ++++++++----------- spirit/middleware.py | 2 +- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/spirit/core/utils/paginator/infinite_paginator.py b/spirit/core/utils/paginator/infinite_paginator.py index a277d99c..907c722f 100644 --- a/spirit/core/utils/paginator/infinite_paginator.py +++ b/spirit/core/utils/paginator/infinite_paginator.py @@ -3,26 +3,23 @@ from __future__ import unicode_literals from django.http import Http404 +from django.shortcuts import get_object_or_404 from infinite_scroll_pagination.paginator import SeekPaginator, EmptyPage def paginate(request, query_set, lookup_field, per_page=15, page_var='value'): # TODO: remove + value = None page_pk = request.GET.get(page_var, None) + + # It's not the first page + if page_pk is not None: + obj = get_object_or_404(query_set.model, pk=page_pk) + value = getattr(obj, lookup_field) + paginator = SeekPaginator(query_set, per_page=per_page, lookup_field=lookup_field) - # First page - if page_pk is None: - return paginator.page() - - try: - obj = query_set.model.objects.get(pk=page_pk) - except query_set.model.DoesNotExist: - raise Http404() - - value = getattr(obj, lookup_field) - try: page = paginator.page(value=value, pk=page_pk) except EmptyPage: diff --git a/spirit/middleware.py b/spirit/middleware.py index f493f04d..9d760fce 100644 --- a/spirit/middleware.py +++ b/spirit/middleware.py @@ -4,7 +4,7 @@ from spirit.core.middleware import XForwardedForMiddleware, PrivateForumMiddlewa from spirit.user.middleware import TimezoneMiddleware, LastIPMiddleware,\ LastSeenMiddleware, ActiveUserMiddleware -# TODO: remove in Spirit 0.4 +# TODO: remove in Spirit 0.5 __all__ = [