Be smarter about missing request object.
authorZygmunt Krynicki <zygmunt.krynicki@linaro.org>
Tue, 14 Jun 2011 08:53:42 +0000 (10:53 +0200)
committerZygmunt Bazyli Krynicki <Zygmunt Krynicki zygmunt.krynicki@linaro.org>
Tue, 14 Jun 2011 08:53:42 +0000 (10:53 +0200)
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

index 05c44f3..e8331c2 100644 (file)
@@ -144,7 +144,13 @@ class AutoPaginateNode(template.Node):
             orphans = self.orphans.resolve(context)
         paginator = Paginator(value, paginate_by, orphans)
         try:
             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 ' +
         except InvalidPage:
             if INVALID_PAGE_RAISES_404:
                 raise Http404('Invalid page requested.  If DEBUG were set to ' +