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