annotate gpp/forums/feeds.py @ 174:e9c718065a25

Ticket #58; use Django 1.2's cached template loader.
author Brian Neal <bgneal@gmail.com>
date Wed, 03 Mar 2010 04:04:11 +0000
parents 6f14970b103a
children b7ac381996e8
rev   line source
bgneal@170 1 """This file contains the feed class for the forums application."""
bgneal@170 2 import datetime
bgneal@170 3
bgneal@170 4 from django.contrib.syndication.feeds import Feed
bgneal@170 5 from django.core.exceptions import ObjectDoesNotExist
bgneal@170 6
bgneal@170 7 from forums.models import Forum
bgneal@170 8 from forums.models import Post
bgneal@170 9
bgneal@170 10 BASE_YEAR = 2010
bgneal@170 11
bgneal@170 12 class ForumsFeed(Feed):
bgneal@170 13 """The Feed class for the forums application"""
bgneal@170 14
bgneal@170 15 def get_object(self, bits):
bgneal@170 16 # only return public forums
bgneal@170 17 if len(bits) == 1:
bgneal@170 18 forum = Forum.objects.get(slug=bits[0])
bgneal@170 19 if forum.category.groups.count() > 0:
bgneal@170 20 raise ObjectDoesNotExist
bgneal@170 21 return forum
bgneal@170 22
bgneal@170 23 elif len(bits) == 0:
bgneal@170 24 # return None to indicate we want a combined feed
bgneal@170 25 return None
bgneal@170 26
bgneal@170 27 def title(self, obj):
bgneal@170 28 if obj is None:
bgneal@170 29 forum_name = 'Combined'
bgneal@170 30 else:
bgneal@170 31 forum_name = obj.name
bgneal@170 32
bgneal@170 33 return 'SurfGuitar101.com %s Forum Feed' % forum_name
bgneal@170 34
bgneal@170 35 def link(self, obj):
bgneal@170 36 if obj is None:
bgneal@170 37 bits = ''
bgneal@170 38 else:
bgneal@170 39 bits = obj.slug + '/'
bgneal@170 40
bgneal@170 41 return '/feeds/forums/' + bits
bgneal@170 42
bgneal@170 43 def description(self, obj):
bgneal@170 44 if obj is None:
bgneal@170 45 return "User posts to SurfGuitar101.com forums."
bgneal@170 46 return obj.description
bgneal@170 47
bgneal@170 48 def copyright(self):
bgneal@170 49 curr_year = datetime.datetime.now().year
bgneal@170 50 if curr_year == BASE_YEAR:
bgneal@170 51 year_range = str(BASE_YEAR)
bgneal@170 52 else:
bgneal@170 53 year_range = "%d - %d" % (BASE_YEAR, curr_year)
bgneal@170 54
bgneal@170 55 return 'Copyright (C) %s, SurfGuitar101.com' % year_range
bgneal@170 56
bgneal@170 57 ttl = '720'
bgneal@170 58
bgneal@170 59 title_template = 'forums/feed_title.html'
bgneal@170 60 description_template = 'forums/feed_description.html'
bgneal@170 61
bgneal@170 62 def items(self, obj):
bgneal@170 63 if obj is None:
bgneal@170 64 # return a combined feed of public forum threads
bgneal@170 65 items = Post.objects.filter(
bgneal@170 66 topic__forum__in=Forum.objects.public_forums())
bgneal@170 67 else:
bgneal@170 68 items = Post.objects.filter(topic__forum__id=obj.id)
bgneal@170 69 return items.order_by('-creation_date').select_related()[:10]
bgneal@170 70
bgneal@170 71 def item_pubdate(self, item):
bgneal@170 72 return item.creation_date
bgneal@170 73
bgneal@170 74 def item_categories(self, item):
bgneal@170 75 return (item.topic.forum.name, )