Commits

Horst Gutmann committed 14a45ca

Adds CMSApp integration and feed

  • Participants
  • Parent commits 5bf6e5e

Comments (0)

Files changed (6)

File cmsplugin_news/cms_app.py

+from django.utils.translation import ugettext_lazy as _
+
+from cms.app_base import CMSApp
+from cms.apphook_pool import apphook_pool
+
+
+class NewsAppHook(CMSApp):
+    name = _('News App')
+    urls = ['cmsplugin_news.urls']
+
+
+apphook_pool.register(NewsAppHook)
+

File cmsplugin_news/feeds.py

+from django.contrib.syndication.views import Feed
+from django.core.urlresolvers import reverse
+
+from . import models
+from . import settings
+
+
+class NewsFeed(Feed):
+    title = settings.FEED_TITLE
+    description = settings.FEED_DESCRIPTION
+
+    title_template = 'cmsplugin_news/feeds/item_title.html' 
+    description_template = 'cmsplugin_news/feeds/item_description.html' 
+
+    @property
+    def link(self):
+        return reverse('news_archive_index')
+
+    def items(self):
+        return models.News.published.all()[:settings.FEED_SIZE]
+
+    def item_url(self, item):
+        return item.get_absolute_url()
+

File cmsplugin_news/settings.py

 from django.conf import settings as django_settings
+from django.utils.translation import ugettext_lazy as _
 
 
+def get_setting(name, default):
+    """
+    A little helper for fetching global settings with a common prefix.
+    """
+    parent_name = "CMSPLUGIN_NEWS_{}".format(name)
+    return getattr(django_settings, parent_name, default)
+
 """
     Disables the latest news plugin
     Defaults to false
 """
-DISABLE_LATEST_NEWS_PLUGIN = getattr(django_settings, 'CMSPLUGIN_NEWS_DISABLE_LATEST_NEWS_PLUGIN', False)
+DISABLE_LATEST_NEWS_PLUGIN = get_setting('DISABLE_LATEST_NEWS_PLUGIN', False)
+FEED_SIZE = get_setting('FEED_SIZE', 10)
+FEED_TITLE = get_setting('FEED_TITLE', _('News feed'))
+FEED_DESCRIPTION = get_setting('FEED_DESCRIPTION', _('A feed full of news'))
+

File cmsplugin_news/templates/cmsplugin_news/feeds/item_description.html

+{{ obj.content|safe }}

File cmsplugin_news/templates/cmsplugin_news/feeds/item_title.html

+{{ obj.title|safe }}

File cmsplugin_news/urls.py

 
 from cmsplugin_news.models import News
 
+from . import feeds
+
+
 news_info_dict = {
     'queryset': News.published.all(),
     'date_field': 'pub_date',
     
     (r'^(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/(?P<slug>[-\w]+)/$', 
         'object_detail', news_info_month_dict, 'news_detail'),
+
+    url(r'^feed/$', feeds.NewsFeed())
 )