forked from 00dani/lemoncurry
Use the same paginate function on the entry-kind feeds and cat feeds, for identical pagination everywhere c:
This commit is contained in:
parent
4033837b91
commit
a0db1bfb47
2 changed files with 20 additions and 12 deletions
|
@ -20,7 +20,7 @@ def paginate(queryset, reverse, page):
|
||||||
if page == '1':
|
if page == '1':
|
||||||
return redirect(Page(1).url)
|
return redirect(Page(1).url)
|
||||||
|
|
||||||
paginator = Paginator(queryset, 10)
|
paginator = Paginator(queryset, 2)
|
||||||
entries = paginator.page(page or 1)
|
entries = paginator.page(page or 1)
|
||||||
|
|
||||||
entries.pages = tuple(Page(i) for i in paginator.page_range)
|
entries.pages = tuple(Page(i) for i in paginator.page_range)
|
||||||
|
|
|
@ -1,18 +1,20 @@
|
||||||
from annoying.decorators import render_to
|
from annoying.decorators import render_to
|
||||||
from django.core.paginator import Paginator
|
|
||||||
from django.shortcuts import get_object_or_404, redirect
|
from django.shortcuts import get_object_or_404, redirect
|
||||||
|
from django.urls import reverse
|
||||||
from .models import Entry, Cat
|
from .models import Entry, Cat
|
||||||
|
from .pagination import paginate
|
||||||
|
|
||||||
|
|
||||||
@render_to('entries/index.html')
|
@render_to('entries/index.html')
|
||||||
def index(request, kind, page):
|
def index(request, kind, page):
|
||||||
paginator = Paginator(Entry.objects.filter(kind=kind.id), 10)
|
def url(page):
|
||||||
|
kwargs = {'page': page} if page > 1 else {}
|
||||||
|
return reverse('entries:' + kind.index, kwargs=kwargs)
|
||||||
|
|
||||||
# If we explicitly got /page/1 in the URL then redirect to the version with
|
entries = Entry.objects.filter(kind=kind.id)
|
||||||
# no page suffix.
|
entries = paginate(queryset=entries, reverse=url, page=page)
|
||||||
if page == '1':
|
if hasattr(entries, 'content'):
|
||||||
return redirect('entries:' + kind.index, permanent=True)
|
return entries
|
||||||
entries = paginator.page(page or 1)
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'entries': entries,
|
'entries': entries,
|
||||||
|
@ -24,11 +26,17 @@ def index(request, kind, page):
|
||||||
|
|
||||||
@render_to('entries/index.html')
|
@render_to('entries/index.html')
|
||||||
def cat(request, slug, page):
|
def cat(request, slug, page):
|
||||||
|
def url(page):
|
||||||
|
kwargs = {'slug': slug}
|
||||||
|
if page > 1:
|
||||||
|
kwargs['page'] = page
|
||||||
|
return reverse('entries:cat', kwargs=kwargs)
|
||||||
|
|
||||||
cat = get_object_or_404(Cat, slug=slug)
|
cat = get_object_or_404(Cat, slug=slug)
|
||||||
paginator = Paginator(cat.entries.all(), 10)
|
entries = cat.entries.all()
|
||||||
if page == '1':
|
entries = paginate(queryset=entries, reverse=url, page=page)
|
||||||
return redirect('entries:cat', permanent=True, slug=slug)
|
if hasattr(entries, 'content'):
|
||||||
entries = paginator.page(page or 1)
|
return entries
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'entries': entries,
|
'entries': entries,
|
||||||
|
|
Loading…
Reference in a new issue