summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Franke <nobody@nowhere.ws>2011-12-30 06:23:29 +0100
committerChristian Franke <nobody@nowhere.ws>2011-12-30 06:27:20 +0100
commit0dbf258759d5635a52e3e34a771510b64bb932ca (patch)
tree0f3b1cbc2a243623cc18b8102e4e66bf3baf3201
parentd14b59da51faad1257a34911c6a000b6a03d0736 (diff)
Add project newsfeed
-rw-r--r--sublab_project/projects/feeds.py34
-rw-r--r--sublab_project/projects/urls.py4
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<slug>[-\w]+)/$', DetailView.as_view(model=Project),
name='projects_detail'),
url('^(?P<slug>[-\w]+)/rss/$', ProjectNewsFeed()),