+class PaginateNode(Node):
+
+ def __init__(self, template=None):
+ self.template = template
+
+ def render(self, context):
+ template_list = ['pagination/pagination.html']
+ 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)
+
+
+def do_paginate(parser, token):
+ """
+ Emits the pagination control for the most recent autopaginate list
+
+ Syntax is:
+
+ paginate [using "TEMPLATE"]
+
+ Where TEMPLATE is a quoted template name. If missing the default template
+ is used (paginate/pagination.html).
+ """
+ argv = token.split_contents()
+ argc = len(argv)
+ if argc == 1:
+ template = None
+ elif argc == 3 and argv[1] == 'using':
+ template = unescape_string_literal(argv[2])
+ else:
+ raise TemplateSyntaxError(
+ "Invalid syntax. Proper usage of this tag is: "
+ "{% paginate [using \"TEMPLATE\"] %}")
+ return PaginateNode(template)
+
+