Commits

B-dev committed a3977bf

tolta cache

Comments (0)

Files changed (2)

+docs/build
+.svnignore
+.DS_Store
+.svn
+files
+flussi
+
+syntax: glob
+*~
+*-
+*.pyc
+*.kpf
+*.sql
+website/dev.db
+website/settings/local.py
+.project
+.pydevproject
+.idea
+.settings/org.eclipse.core.resources.prefs
+
+syntax: regexp
+^apps/((?!loyalty).)*$

cmsplugin_feed/cms_plugins.py

-import feedparser
+import feedparser, re
 
 from django.utils.translation import ugettext as _
 from django.core.cache import cache
 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" %instance.id):
-        feed = feedparser.parse(instance.feed_url)
-        cache.set("feed_%s" %instance.id, feed, CMSPLUGIN_FEED_CACHE_TIMEOUT)
-    return cache.get("feed_%s" %instance.id)
-    
-
+#def get_cached_feed(instance):
+#    """
+#    get the feed from cache if it exists else fetch it.
+#    """
+#    if not cache.has_key("feed_%s" %instance.id):
+#        feed = feedparser.parse(instance.feed_url)
+#        cache.set("feed_%s" %instance.id, feed, CMSPLUGIN_FEED_CACHE_TIMEOUT)
+#    return cache.get("feed_%s" %instance.id)
 
 class FeedPlugin(CMSPluginBase):
     model = Feed
     render_template = 'cmsplugin_feed/feed.html'
 
     def render(self, context, instance, placeholder):
-        feed = get_cached_feed(instance)
+        #feed = get_cached_feed(instance)
+        feed = feedparser.parse(instance.feed_url)
+        is_youtube_rss = False
+        if instance.feed_url.find('youtube.com') > -1:
+            is_youtube_rss = True
+
         #import pdb; pdb.set_trace()
         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) 
+            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'))
             try:
                 entries = feed_paginator.page(page)
             except (EmptyPage, InvalidPage):
-                entries = feed_paginator.page(paginator.num_pages)
+                entries = feed_paginator.page(feed_paginator.num_pages)
         else:
             is_paginated =False
             entries = feed["entries"]
-                    
+
+        img_youtube = ''
+        if is_youtube_rss:
+            id = feed['entries'][0]['id'].split(":")[3]
+            img_youtube = '<img src="http://i.ytimg.com/vi/%s/default.jpg" alt="" width="272" />' % id
+
         context.update({
             'instance': instance,
             'feed_entries': entries,
             'is_paginated' : is_paginated,
+            'is_youtube_rss': is_youtube_rss,
+            'img_youtube': img_youtube,
             'placeholder': placeholder,
             })
         return context