Commits

Fajran Iman Rusadi committed 3c6859b

Added RSS feed.

Comments (0)

Files changed (2)

cmsplugin_news/feeds.py

+from django.contrib.syndication.feeds import Feed
+from django.core.urlresolvers import reverse
+from django.conf import settings
+
+from cmsplugin_news.models import News
+
+class NewsEntryFeed(Feed):
+    title = settings.CMSPLUGIN_NEWS_RSS_TITLE
+    description = settings.CMSPLUGIN_NEWS_RSS_DESCRIPTION
+
+    def items(self):
+        return News.published.all()[:10]
+    
+    def item_pubdate(self, item):
+        return item.pub_date
+
+    def __getattr__(self, name):
+        # The reverse() call should be made after all URLs
+        # are mapped. So we cannot use it when declaring the
+        # 'link' property.
+
+        if name == 'link':
+            return reverse('news_archive_index')
+
+        return Feed.__getattr__(self, name)
+

cmsplugin_news/urls.py

 from django.conf.urls.defaults import *
 
 from cmsplugin_news.models import News
+from cmsplugin_news.feeds import NewsEntryFeed
 
 news_info_dict = {
     'queryset': News.published.all(),
     'month_format': '%m',
 }
 
+feeds = {
+    'news': NewsEntryFeed,
+}
+
+rss_dict = {
+    'feed_dict': feeds,
+    'url': 'news',
+}
+
 urlpatterns = patterns('django.views.generic.date_based',
     (r'^$', 
         'archive_index', news_info_dict, 'news_archive_index'),
-    
+
     (r'^(?P<year>\d{4})/$', 
         'archive_year', news_info_dict, 'news_archive_year'),
     
         'object_detail', news_info_month_dict, 'news_detail'),
 )
 
+urlpatterns += patterns('',
+    (r'^rss/$',
+        'django.contrib.syndication.views.feed', rss_dict, 'news_rss'),
+)
+