Commits

Viorel Stirbu  committed 757577d

gracefully handle bad feed url

  • Participants
  • Parent commits ad64418

Comments (0)

Files changed (1)

File cmsplugin_feed/cms_plugins.py

 
     def render(self, context, instance, placeholder):
         feed = get_cached_feed(instance)
-        #import pdb; pdb.set_trace()
-        if instance.paginate_by:
-            is_paginated =True
-            request = context['request']
-            feed_page_param = "feed_%s_page" %str(instance.id)
+        if not feed:
+            entries = []
+            is_paginated = False
+        else:
+            if instance.paginate_by:
+                is_paginated =True
+                request = context['request']
+                feed_page_param = "feed_%s_page" %str(instance.id)
 
-            feed_paginator = Paginator(feed["entries"], instance.paginate_by) 
-            # Make sure page request is an int. If not, deliver first page.
-            try:
-                page = int(request.GET.get(feed_page_param, '1'))
-            except ValueError:
-                page = 1
-            # If page request (9999) is out of range, deliver last page of results.
-            try:
-                entries = feed_paginator.page(page)
-            except (EmptyPage, InvalidPage):
-                entries = feed_paginator.page(paginator.num_pages)
-        else:
-            is_paginated =False
-            entries = feed["entries"]
+                feed_paginator = Paginator(feed["entries"], instance.paginate_by) 
+                # Make sure page request is an int. If not, deliver first page.
+                try:
+                    page = int(request.GET.get(feed_page_param, '1'))
+                except ValueError:
+                    page = 1
+                # If page request (9999) is out of range, deliver last page of results.
+                try:
+                    entries = feed_paginator.page(page)
+                except (EmptyPage, InvalidPage):
+                    entries = feed_paginator.page(paginator.num_pages)
+            else:
+                is_paginated =False
+                entries = feed["entries"]
                     
         context.update({
             'instance': instance,