From 0dbf258759d5635a52e3e34a771510b64bb932ca Mon Sep 17 00:00:00 2001 From: Christian Franke Date: Fri, 30 Dec 2011 06:23:29 +0100 Subject: Add project newsfeed --- sublab_project/projects/feeds.py | 34 +++++++++++++++++++++++++++++++++- sublab_project/projects/urls.py | 4 +++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/sublab_project/projects/feeds.py b/sublab_project/projects/feeds.py index dfc1595..33083e4 100644 --- a/sublab_project/projects/feeds.py +++ b/sublab_project/projects/feeds.py @@ -1,7 +1,10 @@ +from django.contrib.syndication.views import Feed from django.utils.feedgenerator import Atom1Feed +from django.core.urlresolvers import reverse from django.shortcuts import get_object_or_404 +from django.utils.html import strip_tags +from django.utils.text import truncate_html_words -from news.models import News from projects.models import Project from news.feeds import NewsFeed @@ -24,3 +27,32 @@ class ProjectNewsFeed(NewsFeed): class ProjectNewsFeedAtom(ProjectNewsFeed): feed_type = Atom1Feed subtitle = ProjectNewsFeed.description + +class ProjectFeed(Feed): + title = "sublab.org projects" + description = "the latest projects in your sublab" + + def link(self): + return reverse(self) + + def items(self): + return Project.objects.order_by('-date_created')[:10] + + def item_author_name(self, item): + return item.contact_user + + def item_author_email(self, item): + return item.contact_email + + def item_description(self, item): + return strip_tags(truncate_html_words(item.description_html, 100)) + + def item_title(self, item): + return item.name + + def item_pubdate(self, item): + return item.date_created + +class ProjectFeedAtom(ProjectFeed): + feed_type = Atom1Feed + subtitle = ProjectFeed.description diff --git a/sublab_project/projects/urls.py b/sublab_project/projects/urls.py index dfeb4d2..b39e730 100644 --- a/sublab_project/projects/urls.py +++ b/sublab_project/projects/urls.py @@ -2,10 +2,12 @@ from django.conf.urls.defaults import patterns, include, url from django.views.generic import DetailView, ListView from projects.models import Project -from projects.feeds import ProjectNewsFeed, ProjectNewsFeedAtom +from projects.feeds import ProjectNewsFeed, ProjectNewsFeedAtom, ProjectFeed, ProjectFeedAtom urlpatterns = patterns('', url('^$', ListView.as_view(model=Project), name='projects_list'), + url('^rss/$', ProjectFeed()), + url('^atom/$', ProjectFeedAtom()), url('^(?P[-\w]+)/$', DetailView.as_view(model=Project), name='projects_detail'), url('^(?P[-\w]+)/rss/$', ProjectNewsFeed()), -- cgit v1.2.1