From 79b65b1914b1db437200f57df24f76653d0451cc Mon Sep 17 00:00:00 2001 From: Zygmunt Krynicki Date: Tue, 14 Jun 2011 10:53:42 +0200 Subject: [PATCH] Be smarter about missing request object. The application requires uses to use request context processor. If it is not enabled let's warn the user and explain the situation using ImproperlyConfigured exception rather than cryptic bactrace. --- linaro_django_pagination/templatetags/pagination_tags.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/linaro_django_pagination/templatetags/pagination_tags.py b/linaro_django_pagination/templatetags/pagination_tags.py index 05c44f3..e8331c2 100644 --- a/linaro_django_pagination/templatetags/pagination_tags.py +++ b/linaro_django_pagination/templatetags/pagination_tags.py @@ -144,7 +144,13 @@ class AutoPaginateNode(template.Node): orphans = self.orphans.resolve(context) paginator = Paginator(value, paginate_by, orphans) try: - page_obj = paginator.page(context['request'].page(page_suffix)) + request = context['request'] + except KeyError: + raise ImproperlyConfigured( + "You need to enable 'django.core.context_processors.request'." + " See linaro-django-pagination/README file for TEMPLATE_CONTEXT_PROCESSORS details") + try: + page_obj = paginator.page(request.page(page_suffix)) except InvalidPage: if INVALID_PAGE_RAISES_404: raise Http404('Invalid page requested. If DEBUG were set to ' + -- 2.20.1