annotate gpp/forums/feeds.py @ 557:7247a406f92b

Merging change to requirements.txt made on production server.
author Brian Neal <bgneal@gmail.com>
date Sun, 29 Jan 2012 14:45:09 -0600
parents 248dd8dd67f8
children
rev   line source
bgneal@509 1 """
bgneal@509 2 This file contains the feed class for the forums application.
bgneal@170 3
bgneal@509 4 """
bgneal@176 5 from django.contrib.syndication.views import Feed
bgneal@170 6 from django.core.exceptions import ObjectDoesNotExist
bgneal@176 7 from django.shortcuts import get_object_or_404
bgneal@170 8
bgneal@393 9 from forums.models import Forum, Topic, Post
bgneal@176 10 from core.functions import copyright_str
bgneal@509 11 from forums.latest import get_latest_posts
bgneal@170 12
bgneal@170 13
bgneal@170 14 class ForumsFeed(Feed):
bgneal@176 15 """The Feed class for a specific forum"""
bgneal@170 16
bgneal@385 17 ttl = '60'
bgneal@176 18 author_name = 'Brian Neal'
bgneal@176 19 author_email = 'admin@surfguitar101.com'
bgneal@176 20
bgneal@176 21 def get_object(self, request, forum_slug):
bgneal@509 22
bgneal@176 23 if forum_slug:
bgneal@509 24 forum = Forum.objects.get(slug=forum_slug)
bgneal@509 25 # only return public forums
bgneal@387 26 if forum.id not in Forum.objects.public_forum_ids():
bgneal@170 27 raise ObjectDoesNotExist
bgneal@170 28 return forum
bgneal@170 29
bgneal@176 30 else:
bgneal@170 31 # return None to indicate we want a combined feed
bgneal@170 32 return None
bgneal@170 33
bgneal@170 34 def title(self, obj):
bgneal@170 35 if obj is None:
bgneal@170 36 forum_name = 'Combined'
bgneal@170 37 else:
bgneal@170 38 forum_name = obj.name
bgneal@170 39
bgneal@170 40 return 'SurfGuitar101.com %s Forum Feed' % forum_name
bgneal@170 41
bgneal@170 42 def link(self, obj):
bgneal@170 43 if obj is None:
bgneal@170 44 bits = ''
bgneal@170 45 else:
bgneal@170 46 bits = obj.slug + '/'
bgneal@170 47
bgneal@170 48 return '/feeds/forums/' + bits
bgneal@170 49
bgneal@170 50 def description(self, obj):
bgneal@170 51 if obj is None:
bgneal@170 52 return "User posts to SurfGuitar101.com forums."
bgneal@170 53 return obj.description
bgneal@170 54
bgneal@176 55 def feed_copyright(self):
bgneal@176 56 return copyright_str()
bgneal@170 57
bgneal@170 58 def items(self, obj):
bgneal@509 59 forum_id = obj.id if obj else None
bgneal@509 60 return get_latest_posts(forum_id=forum_id)
bgneal@170 61
bgneal@176 62 def item_title(self, item):
bgneal@509 63 return item['title']
bgneal@176 64
bgneal@176 65 def item_description(self, item):
bgneal@509 66 return item['content']
bgneal@176 67
bgneal@176 68 def item_author_name(self, item):
bgneal@509 69 return item['author']
bgneal@176 70
bgneal@170 71 def item_pubdate(self, item):
bgneal@509 72 return item['pubdate']
bgneal@170 73
bgneal@170 74 def item_categories(self, item):
bgneal@509 75 return [item['forum_name']]
bgneal@509 76
bgneal@509 77 def item_link(self, item):
bgneal@509 78 return item['url']