From 7516ffd1a1598701ec6ba1a2edf9d50836ba51a1 Mon Sep 17 00:00:00 2001 From: Christian Franke Date: Fri, 30 Dec 2011 03:56:53 +0100 Subject: Add newsfeed --- sublab_project/news/feeds.py | 32 ++++++++++++++++++++++++++++++++ sublab_project/news/urls.py | 3 +++ sublab_project/templates/base.html | 5 +++++ 3 files changed, 40 insertions(+) create mode 100644 sublab_project/news/feeds.py (limited to 'sublab_project') diff --git a/sublab_project/news/feeds.py b/sublab_project/news/feeds.py new file mode 100644 index 0000000..011cee5 --- /dev/null +++ b/sublab_project/news/feeds.py @@ -0,0 +1,32 @@ +from django.contrib.syndication.views import Feed +from django.utils.feedgenerator import Atom1Feed +from django.core.urlresolvers import reverse +from django.utils.html import strip_tags + +from news.models import News + +class NewsFeed(Feed): + title = "sublab.org news" + description = "the latest news from your sublab" + + def link(self): + return reverse(self) + + def items(self): + return News.objects.order_by('-date_updated')[:10] + + def item_author_name(self, item): + return item.author + + def item_description(self, item): + return strip_tags(item.content_html) + + def item_title(self, item): + return item.title + + def item_pubdate(self, item): + return item.date_created + +class NewsFeedAtom(NewsFeed): + feed_type = Atom1Feed + subtitle = NewsFeed.description diff --git a/sublab_project/news/urls.py b/sublab_project/news/urls.py index fe682ad..7f2029c 100644 --- a/sublab_project/news/urls.py +++ b/sublab_project/news/urls.py @@ -2,9 +2,12 @@ from django.conf.urls.defaults import patterns, include, url from django.views.generic import DetailView from news.models import News +from news.feeds import NewsFeed, NewsFeedAtom from news.views import NewsListView urlpatterns = patterns('', url(r'^$', NewsListView.as_view(), name='news_list'), url(r'^news/(?P[-\w]+)/$', DetailView.as_view(model=News), name='news_detail'), + url(r'^newsfeed/rss/$', NewsFeed(), name='news_feed'), + url(r'^newsfeed/atom/$', NewsFeedAtom(), name='news_feed_atom'), ) diff --git a/sublab_project/templates/base.html b/sublab_project/templates/base.html index 7499645..074dec9 100644 --- a/sublab_project/templates/base.html +++ b/sublab_project/templates/base.html @@ -17,6 +17,11 @@ + + {% block feeds %} + + + {% endblock feeds %} -- cgit v1.2.1