Ioan Alexandru Cucu avatar Ioan Alexandru Cucu committed 8a82136 Draft

* coding style imporvements
* fixed bug (attribute error in case of paginator rasing EmptyPage or InvalidPage)

Comments (0)

Files changed (2)


 from django.core.cache import cache
 from django.core.paginator import Paginator, EmptyPage, InvalidPage
 from cms.plugin_base import CMSPluginBase
 from cms.plugin_pool import plugin_pool
 from cmsplugin_feed.forms import FeedForm
 from cmsplugin_feed.settings import CMSPLUGIN_FEED_CACHE_TIMEOUT
 def get_cached_feed(instance):
     get the feed from cache if it exists else fetch it.
-    if not cache.has_key("feed_%s"
+    if "feed_%s" % in cache:
         feed = feedparser.parse(instance.feed_url)
-        cache.set("feed_%s", feed, CMSPLUGIN_FEED_CACHE_TIMEOUT)
-    return cache.get("feed_%s"
+        cache.set("feed_%s" %, feed, CMSPLUGIN_FEED_CACHE_TIMEOUT)
+    return cache.get("feed_%s" %
 class FeedPlugin(CMSPluginBase):
             is_paginated = False
             if instance.paginate_by:
-                is_paginated =True
+                is_paginated = True
                 request = context['request']
-                feed_page_param = "feed_%s_page" %str(
+                feed_page_param = "feed_%s_page" % str(
-                feed_paginator = Paginator(feed["entries"], instance.paginate_by) 
+                feed_paginator = Paginator(
+                    feed["entries"], instance.paginate_by)
                 # Make sure page request is an int. If not, deliver first page.
                     page = int(request.GET.get(feed_page_param, '1'))
                     entries =
                 except (EmptyPage, InvalidPage):
-                    entries =
+                    entries =
-                is_paginated =False
+                is_paginated = False
                 entries = feed["entries"]
             'instance': instance,
             'feed_entries': entries,
-            'is_paginated' : is_paginated,
+            'is_paginated': is_paginated,
             'placeholder': placeholder,
         return context


 from django.utils.translation import ugettext as _
 from cms.models import CMSPlugin
 class Feed(CMSPlugin):
-    name = models.CharField(verbose_name=_('name'),max_length=255,
+    name = models.CharField(verbose_name=_('name'), max_length=255,
                             null=True, blank=True)
-    feed_url = models.URLField(verbose_name=_('feed URL'),verify_exists=True)
+    feed_url = models.URLField(verbose_name=_('feed URL'), verify_exists=True)
     paginate_by = models.IntegerField(verbose_name="paginate by",
                                       null=True, blank=True,
     def __unicode__(self):
     def save(self, *args, **kwargs):
-            cache.delete("feed_%s"
+            cache.delete("feed_%s" %
         return super(Feed, self).save(*args, **kwargs)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.