bgneal@170
|
1 """This file contains the feed class for the forums application."""
|
bgneal@170
|
2
|
bgneal@176
|
3 from django.contrib.syndication.views import Feed
|
bgneal@170
|
4 from django.core.exceptions import ObjectDoesNotExist
|
bgneal@176
|
5 from django.shortcuts import get_object_or_404
|
bgneal@176
|
6 from django.utils.decorators import method_decorator
|
bgneal@176
|
7 from django.views.decorators.cache import cache_page
|
bgneal@170
|
8
|
bgneal@170
|
9 from forums.models import Forum
|
bgneal@170
|
10 from forums.models import Post
|
bgneal@176
|
11 from core.functions import copyright_str
|
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@176
|
17 ttl = '720'
|
bgneal@176
|
18 author_name = 'Brian Neal'
|
bgneal@176
|
19 author_email = 'admin@surfguitar101.com'
|
bgneal@176
|
20
|
bgneal@176
|
21 @method_decorator(cache_page(15 * 60))
|
bgneal@176
|
22 def __call__(self, request, *args, **kwargs):
|
bgneal@176
|
23 return super(ForumsFeed, self).__call__(request, *args, **kwargs)
|
bgneal@176
|
24
|
bgneal@176
|
25 def get_object(self, request, forum_slug):
|
bgneal@170
|
26 # only return public forums
|
bgneal@176
|
27 if forum_slug:
|
bgneal@176
|
28 forum = get_object_or_404(Forum, slug=forum_slug)
|
bgneal@170
|
29 if forum.category.groups.count() > 0:
|
bgneal@170
|
30 raise ObjectDoesNotExist
|
bgneal@170
|
31 return forum
|
bgneal@170
|
32
|
bgneal@176
|
33 else:
|
bgneal@170
|
34 # return None to indicate we want a combined feed
|
bgneal@170
|
35 return None
|
bgneal@170
|
36
|
bgneal@170
|
37 def title(self, obj):
|
bgneal@170
|
38 if obj is None:
|
bgneal@170
|
39 forum_name = 'Combined'
|
bgneal@170
|
40 else:
|
bgneal@170
|
41 forum_name = obj.name
|
bgneal@170
|
42
|
bgneal@170
|
43 return 'SurfGuitar101.com %s Forum Feed' % forum_name
|
bgneal@170
|
44
|
bgneal@170
|
45 def link(self, obj):
|
bgneal@170
|
46 if obj is None:
|
bgneal@170
|
47 bits = ''
|
bgneal@170
|
48 else:
|
bgneal@170
|
49 bits = obj.slug + '/'
|
bgneal@170
|
50
|
bgneal@170
|
51 return '/feeds/forums/' + bits
|
bgneal@170
|
52
|
bgneal@170
|
53 def description(self, obj):
|
bgneal@170
|
54 if obj is None:
|
bgneal@170
|
55 return "User posts to SurfGuitar101.com forums."
|
bgneal@170
|
56 return obj.description
|
bgneal@170
|
57
|
bgneal@176
|
58 def feed_copyright(self):
|
bgneal@176
|
59 return copyright_str()
|
bgneal@170
|
60
|
bgneal@170
|
61 def items(self, obj):
|
bgneal@170
|
62 if obj is None:
|
bgneal@170
|
63 # return a combined feed of public forum threads
|
bgneal@170
|
64 items = Post.objects.filter(
|
bgneal@170
|
65 topic__forum__in=Forum.objects.public_forums())
|
bgneal@170
|
66 else:
|
bgneal@170
|
67 items = Post.objects.filter(topic__forum__id=obj.id)
|
bgneal@170
|
68 return items.order_by('-creation_date').select_related()[:10]
|
bgneal@170
|
69
|
bgneal@176
|
70 def item_title(self, item):
|
bgneal@176
|
71 return item.topic.name
|
bgneal@176
|
72
|
bgneal@176
|
73 def item_description(self, item):
|
bgneal@176
|
74 return item.html
|
bgneal@176
|
75
|
bgneal@176
|
76 def item_author_name(self, item):
|
bgneal@176
|
77 return item.user.username
|
bgneal@176
|
78
|
bgneal@170
|
79 def item_pubdate(self, item):
|
bgneal@170
|
80 return item.creation_date
|
bgneal@170
|
81
|
bgneal@170
|
82 def item_categories(self, item):
|
bgneal@170
|
83 return (item.topic.forum.name, )
|