summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Franke <nobody@nowhere.ws>2011-12-30 05:34:31 +0100
committerChristian Franke <nobody@nowhere.ws>2011-12-30 06:27:20 +0100
commitaf5790587db626385aeaa7878dc4c4b12b5fd3a0 (patch)
treeea5c7a19721c6d9c3333b6b51aa08134eef5920b
parent2c4427a55ab2d42619eb6305f4b1bbc84695cadf (diff)
add project specific news feeds
-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()),
)