X-Git-Url: https://git.mdrn.pl/django-pagination.git/blobdiff_plain/a0cd75db95e10f1e2ff6979ee78fa7d36edb23c3..b5f7065624d3f212ef9e22911478011789cc32b0:/linaro_django_pagination/templatetags/pagination_tags.py diff --git a/linaro_django_pagination/templatetags/pagination_tags.py b/linaro_django_pagination/templatetags/pagination_tags.py index bb2dd9a..15363d8 100644 --- a/linaro_django_pagination/templatetags/pagination_tags.py +++ b/linaro_django_pagination/templatetags/pagination_tags.py @@ -40,6 +40,7 @@ from django.template import ( TOKEN_BLOCK, TemplateSyntaxError, Variable, + loader, ) from django.template.loader import select_template from django.utils.text import unescape_string_literal @@ -134,7 +135,7 @@ class AutoPaginateNode(Node): 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 = '' @@ -185,11 +186,9 @@ class PaginateNode(Node): to_return = 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, to_return, + context_instance = context) + def do_paginate(parser, token): @@ -201,7 +200,7 @@ 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) @@ -329,7 +328,11 @@ def paginate(context, window=DEFAULT_WINDOW, margin=DEFAULT_MARGIN): to_return['getvars'] = '' return to_return except (KeyError, AttributeError): - return {} + to_return = {} + + context.update(to_return) + + return context register = Library()