Be smarter about missing request object.
[django-pagination.git] / linaro_django_pagination / templatetags / pagination_tags.py
index 78d8866..e8331c2 100644 (file)
@@ -127,7 +127,7 @@ class AutoPaginateNode(template.Node):
         self.multiple_paginations = multiple_paginations
 
     def render(self, context):
-        if self.multiple_paginations or context.has_key('paginator'):
+        if self.multiple_paginations or "paginator" in context:
             page_suffix = '_%s' % self.queryset_var
         else:
             page_suffix = ''
@@ -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 ' +