core.utils infinite paginator refactor

This module should be moved to the infinite-paginator app
This commit is contained in:
nitely 2015-07-30 23:22:58 -03:00
parent 7ad6a0dd71
commit 370e3de5df
2 changed files with 9 additions and 12 deletions

View File

@ -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)
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()
# 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)
try:
page = paginator.page(value=value, pk=page_pk)
except EmptyPage:

View File

@ -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__ = [