summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sublab_project/projects/feeds.py26
-rw-r--r--sublab_project/projects/urls.py4
2 files changed, 29 insertions, 1 deletions
diff --git a/sublab_project/projects/feeds.py b/sublab_project/projects/feeds.py
new file mode 100644
index 0000000..dfc1595
--- /dev/null
+++ b/sublab_project/projects/feeds.py
@@ -0,0 +1,26 @@
+from django.utils.feedgenerator import Atom1Feed
+from django.shortcuts import get_object_or_404
+
+from news.models import News
+from projects.models import Project
+from news.feeds import NewsFeed
+
+class ProjectNewsFeed(NewsFeed):
+ def get_object(self, *args, **kwargs):
+ return get_object_or_404(Project, **kwargs)
+
+ def title(self, obj):
+ return 'sublab.org - %s' % obj.name
+
+ def description(self, obj):
+ return obj.description
+
+ def link(self, obj):
+ return obj.get_absolute_url()
+
+ def items(self, obj):
+ return obj.news.all()[:10]
+
+class ProjectNewsFeedAtom(ProjectNewsFeed):
+ feed_type = Atom1Feed
+ subtitle = ProjectNewsFeed.description
diff --git a/sublab_project/projects/urls.py b/sublab_project/projects/urls.py
index 788e18a..dfeb4d2 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
urlpatterns = patterns('',
url('^$', ListView.as_view(model=Project), name='projects_list'),
url('^(?P<slug>[-\w]+)/$', DetailView.as_view(model=Project),
name='projects_detail'),
+ url('^(?P<slug>[-\w]+)/rss/$', ProjectNewsFeed()),
+ url('^(?P<slug>[-\w]+)/atom/$', ProjectNewsFeedAtom()),
)