Use ResponseException for various places rather than needing to check the return value for responseness
This commit is contained in:
parent
7d17a92793
commit
065619772e
8 changed files with 17 additions and 26 deletions
|
@ -1,6 +1,8 @@
|
|||
from django.core.paginator import Paginator
|
||||
from django.shortcuts import redirect
|
||||
|
||||
from lemoncurry.middleware import ResponseException
|
||||
|
||||
|
||||
def paginate(queryset, reverse, page):
|
||||
class Page:
|
||||
|
@ -18,7 +20,7 @@ def paginate(queryset, reverse, page):
|
|||
# If the first page was requested, redirect to the clean version of the URL
|
||||
# with no page suffix.
|
||||
if page == 1:
|
||||
return redirect(Page(1).url)
|
||||
raise ResponseException(redirect(Page(1).url))
|
||||
|
||||
paginator = Paginator(queryset, 10)
|
||||
entries = paginator.page(page or 1)
|
||||
|
|
|
@ -9,8 +9,6 @@ from ..pagination import paginate
|
|||
def by_kind(request, kind, page=None):
|
||||
entries = Entry.objects.filter(kind=kind.id)
|
||||
entries = paginate(queryset=entries, reverse=kind.index_page, page=page)
|
||||
if hasattr(entries, 'content'):
|
||||
return entries
|
||||
|
||||
return {
|
||||
'entries': entries,
|
||||
|
@ -31,8 +29,6 @@ def by_cat(request, slug, page=None):
|
|||
cat = get_object_or_404(Cat, slug=slug)
|
||||
entries = cat.entries.all()
|
||||
entries = paginate(queryset=entries, reverse=url, page=page)
|
||||
if hasattr(entries, 'content'):
|
||||
return entries
|
||||
|
||||
return {
|
||||
'entries': entries,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue