Skip to content
This repository was archived by the owner on Jun 5, 2018. It is now read-only.

RFD: Reuse existing paginator? #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 6 additions & 2 deletions linaro_django_pagination/templatetags/pagination_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ def __init__(self, queryset_var, multiple_paginations, paginate_by=None,
self.multiple_paginations = multiple_paginations

def render(self, context):
if self.multiple_paginations or getattr(context, "paginator", None):
paginator = context.get('paginator', None)
if self.multiple_paginations or paginator:
page_suffix = '_%s' % self.queryset_var
else:
page_suffix = ''
Expand All @@ -150,7 +151,10 @@ def render(self, context):
orphans = self.orphans
else:
orphans = self.orphans.resolve(context)
paginator = Paginator(value, paginate_by, orphans)
# Use existing paginator if possible, to avoid bad
# values for eg. num_pages
if paginator is None:
paginator = Paginator(value, paginate_by, orphans)
try:
request = context['request']
except KeyError:
Expand Down