From: Zygmunt Krynicki Date: Tue, 14 Jun 2011 10:50:28 +0000 (+0200) Subject: Improve do_paginate parsing X-Git-Tag: release-2.0~7 X-Git-Url: https://git.mdrn.pl/django-pagination.git/commitdiff_plain/087d48eaa49896e1297b6e26b3e89bb9164040e8?ds=inline Improve do_paginate parsing The parser can now correctly handle quoted template names. Error reporting is more consistent and easier to understand. --- diff --git a/linaro_django_pagination/templatetags/pagination_tags.py b/linaro_django_pagination/templatetags/pagination_tags.py index 815cb7f..2d15e72 100644 --- a/linaro_django_pagination/templatetags/pagination_tags.py +++ b/linaro_django_pagination/templatetags/pagination_tags.py @@ -42,6 +42,7 @@ from django.template import ( Variable, ) from django.template.loader import select_template +from django.utils.text import unescape_string_literal # TODO, import this normally later on from linaro_django_pagination.settings import * @@ -193,20 +194,26 @@ class PaginateNode(Node): def do_paginate(parser, token): """ - {% paginate [using] [template] %} + Emits the pagination control for the most recent autopaginate list - {% paginate %} - {% paginate using paginations/custom_pagination.html %} + Syntax is: + + paginate [using "TEMPLATE"] + + Where TEMPLATE is a quoted template name. If missing the default template + is used (paginate/paginate.html). """ - argv = token.contents.split() + argv = token.split_contents() argc = len(argv) - if argc > 3: - raise TemplateSyntaxError("Tag %s takes at most 2 argument." % argv[0]) if argc == 1: - return PaginateNode() - if argc == 3 and argv[1] == 'using': - return PaginateNode(template=argv[2]) - raise TemplateSyntaxError("Tag %s is invalid. Please check the syntax" % argv[0]) + 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) def paginate(context, window=DEFAULT_WINDOW, margin=DEFAULT_MARGIN):