bgneal@509: """ bgneal@509: This file contains the feed class for the forums application. bgneal@170: bgneal@509: """ bgneal@176: from django.contrib.syndication.views import Feed bgneal@170: from django.core.exceptions import ObjectDoesNotExist bgneal@176: from django.shortcuts import get_object_or_404 bgneal@170: bgneal@393: from forums.models import Forum, Topic, Post bgneal@176: from core.functions import copyright_str bgneal@509: from forums.latest import get_latest_posts bgneal@170: bgneal@170: bgneal@170: class ForumsFeed(Feed): bgneal@176: """The Feed class for a specific forum""" bgneal@170: bgneal@385: ttl = '60' bgneal@176: author_name = 'Brian Neal' bgneal@176: author_email = 'admin@surfguitar101.com' bgneal@176: bgneal@176: def get_object(self, request, forum_slug): bgneal@509: bgneal@176: if forum_slug: bgneal@509: forum = Forum.objects.get(slug=forum_slug) bgneal@509: # only return public forums bgneal@387: if forum.id not in Forum.objects.public_forum_ids(): bgneal@170: raise ObjectDoesNotExist bgneal@170: return forum bgneal@170: bgneal@176: else: bgneal@170: # return None to indicate we want a combined feed bgneal@170: return None bgneal@170: bgneal@170: def title(self, obj): bgneal@170: if obj is None: bgneal@170: forum_name = 'Combined' bgneal@170: else: bgneal@170: forum_name = obj.name bgneal@170: bgneal@170: return 'SurfGuitar101.com %s Forum Feed' % forum_name bgneal@170: bgneal@170: def link(self, obj): bgneal@170: if obj is None: bgneal@170: bits = '' bgneal@170: else: bgneal@170: bits = obj.slug + '/' bgneal@170: bgneal@170: return '/feeds/forums/' + bits bgneal@170: bgneal@170: def description(self, obj): bgneal@170: if obj is None: bgneal@170: return "User posts to SurfGuitar101.com forums." bgneal@170: return obj.description bgneal@170: bgneal@176: def feed_copyright(self): bgneal@176: return copyright_str() bgneal@170: bgneal@170: def items(self, obj): bgneal@509: forum_id = obj.id if obj else None bgneal@509: return get_latest_posts(forum_id=forum_id) bgneal@170: bgneal@176: def item_title(self, item): bgneal@509: return item['title'] bgneal@176: bgneal@176: def item_description(self, item): bgneal@509: return item['content'] bgneal@176: bgneal@176: def item_author_name(self, item): bgneal@509: return item['author'] bgneal@176: bgneal@170: def item_pubdate(self, item): bgneal@509: return item['pubdate'] bgneal@170: bgneal@170: def item_categories(self, item): bgneal@509: return [item['forum_name']] bgneal@509: bgneal@509: def item_link(self, item): bgneal@509: return item['url']