My favorites | Sign in
Project Home Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions

Issue 14 attachment: django-forum-rss.r16.path (3.7 KB)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
Index: templates/feeds/forum_title.html
===================================================================
--- templates/feeds/forum_title.html (revision 0)
+++ templates/feeds/forum_title.html (revision 0)
@@ -0,0 +1 @@
+{{ obj.thread }}
Index: templates/feeds/forum_description.html
===================================================================
--- templates/feeds/forum_description.html (revision 0)
+++ templates/feeds/forum_description.html (revision 0)
@@ -0,0 +1 @@
+{{ obj.body }}
Index: templates/forum/forum_list.html
===================================================================
--- templates/forum/forum_list.html (revision 16)
+++ templates/forum/forum_list.html (working copy)
@@ -1,5 +1,6 @@
{% extends "forum_base.html" %}
{% block title %}Forums{% endblock %}
+
{% block content %}
<table id='djangoForumList'>
<tr>
Index: feeds.py
===================================================================
--- feeds.py (revision 0)
+++ feeds.py (revision 0)
@@ -0,0 +1,68 @@
+# -*- coding: utf-8 -*-
+
+from django.conf import settings
+from django.contrib.syndication.feeds import Feed
+from django.contrib.syndication.feeds import FeedDoesNotExist
+from django.utils.feedgenerator import Atom1Feed
+from django.contrib.sites.models import Site
+from django.core.exceptions import ObjectDoesNotExist
+from django.core.urlresolvers import reverse
+from django.utils.translation import ugettext as _
+
+from forum.models import Forum, Thread, Post
+
+class RssForumFeed(Feed):
+ title_template = 'feeds/forum_title.html'
+ description_template = 'feeds/forum_description.html'
+
+ def get_object(self, bits):
+ if len(bits) == 0:
+ return None
+ else:
+ slug = "/".join(bits)
+ return Forum.objects.get(slug__exact=slug)
+
+ def title(self, obj):
+ if not hasattr(self, '_site'):
+ self._site = Site.objects.get_current()
+
+ if obj:
+ return _("%(title)s's Forum: %(forum)s") % {
+ 'title': self._site.name,
+ 'forum': obj.title }
+ else:
+ return _("%(title)s's Forum") % {'title': self._site.name}
+
+ def description(self, obj):
+ if obj:
+ return obj.description
+ else:
+ return _('Latest posts on site')
+
+ def link(self, obj):
+ if obj:
+ return obj.get_absolute_url()
+ else:
+ return "/forums/"
+
+ def get_query_set(self, obj):
+ if obj:
+ return Post.objects.filter(thread__forum__pk=obj.id)\
+ .order_by('-time')
+ else:
+ return Post.objects.order_by('-time')
+
+
+ def items(self, obj):
+ return self.get_query_set(obj)[:15]
+
+ def item_pubdate(self, item):
+ return item.time
+
+class AtomForumFeed(RssForumFeed):
+ feed_type = Atom1Feed
+
+ def subtitle(self, obj):
+ return RssForumFeed.description(self, obj)
+
+
Index: urls.py
===================================================================
--- urls.py (revision 16)
+++ urls.py (working copy)
@@ -11,13 +11,20 @@

from django.conf.urls.defaults import *
from forum.models import Forum
+from forum.feeds import RssForumFeed, AtomForumFeed

forum_dict = {
'queryset' : Forum.objects.filter(parent__isnull=True),
}

+feed_dict = {
+ 'rss' : RssForumFeed,
+ 'atom': AtomForumFeed
+}
urlpatterns = patterns('',
(r'^$', 'django.views.generic.list_detail.object_list', forum_dict),
+ (r'^(?P<url>(rss|atom).*)/$', 'django.contrib.syndication.views.feed'
+ ,{ 'feed_dict': feed_dict}),

(r'^thread/(?P<thread>[0-9]+)/$', 'forum.views.thread'),
(r'^thread/(?P<thread>[0-9]+)/reply/$', 'forum.views.reply'),
Powered by Google Project Hosting