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 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 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