TOKEN_BLOCK,
TemplateSyntaxError,
Variable,
+ loader,
)
from django.template.loader import select_template
from django.utils.text import unescape_string_literal
if queryset_var is None:
raise TemplateSyntaxError(
"Invalid syntax. Proper usage of this tag is: "
- "{%% autopaginate QUERYSET [PAGINATE_BY] [ORPHANS]"
- " [as CONTEXT_VAR_NAME] %%}")
+ "{% autopaginate QUERYSET [PAGINATE_BY] [ORPHANS]"
+ " [as CONTEXT_VAR_NAME] %}")
return AutoPaginateNode(queryset_var, multiple_paginations, paginate_by, orphans, context_var)
self.multiple_paginations = multiple_paginations
def render(self, context):
- if self.multiple_paginations or "paginator" in context:
+ if self.multiple_paginations or getattr(context, "paginator", None):
page_suffix = '_%s' % self.queryset_var
else:
page_suffix = ''
def render(self, context):
template_list = ['pagination/pagination.html']
- to_return = paginate(context)
+ new_context = paginate(context)
if self.template:
template_list.insert(0, self.template)
- t = select_template(template_list)
- if not t:
- return None
- context = Context(to_return)
- return t.render(context)
+ return loader.render_to_string(template_list, new_context,
+ context_instance = context)
+
def do_paginate(parser, token):
paginate [using "TEMPLATE"]
Where TEMPLATE is a quoted template name. If missing the default template
- is used (paginate/paginate.html).
+ is used (paginate/pagination.html).
"""
argv = token.split_contents()
argc = len(argv)
if pages[-1] != paginator.num_pages:
pages.append(None)
- to_return = {
+ new_context = {
'MEDIA_URL': settings.MEDIA_URL,
'STATIC_URL': getattr(settings, "STATIC_URL", None),
'display_disabled_next_link': DISPLAY_DISABLED_NEXT_LINK,
if 'page%s' % page_suffix in getvars:
del getvars['page%s' % page_suffix]
if len(getvars.keys()) > 0:
- to_return['getvars'] = "&%s" % getvars.urlencode()
+ new_context['getvars'] = "&%s" % getvars.urlencode()
else:
- to_return['getvars'] = ''
- return to_return
+ new_context['getvars'] = ''
except (KeyError, AttributeError):
- return {}
+ new_context = {}
+
+ context.update(new_context)
+
+ return context
register = Library()