9
9
from django.template.loader import get_template
10
10
from wiki.models import ChangeSet, Article
11
11
from wiki.utils import get_ct
12
from django.utils.feedgenerator import Atom1Feed, Rss201rev2Feed
12
import atomformat as atom
14
14
ALL_ARTICLES = Article.objects.all()
15
15
ALL_CHANGES = ChangeSet.objects.all()
17
17
class RssHistoryFeed(Feed):
19
feed_type = Rss201rev2Feed
20
19
title = 'History for all articles'
21
link = '/wiki/feeds/rss'
22
21
description = 'Recent changes in wiki'
24
23
def __init__(self, request,
51
50
return item.modified
53
def item_author_name(self, item):
55
Takes the object returned by get_object and returns the feeds's
56
auhor's name as a Python string
58
if item.is_anonymous_change():
60
return item.editor.username
63
class AtomHistoryFeed(RssHistoryFeed):
53
class AtomHistoryFeed(atom.Feed):
55
feed_title = 'History for all articles'
66
56
feed_subtitle = 'Recent changes in wiki'
67
link = '/wiki/feeds/atom'
58
def __init__(self, request,
59
group_slug=None, group_slug_field=None, group_qs=None,
60
article_qs=ALL_ARTICLES, changes_qs=ALL_CHANGES,
62
title_template = u'feeds/history_title.html',
63
description_template = u'feeds/history_description.html',
66
if group_slug is not None:
67
group = get_object_or_404(group_qs,
68
**{group_slug_field : group_slug})
69
self.changes_qs = changes_qs.filter(article__content_type=get_ct(group),
70
article__object_id=group.id)
72
self.changes_qs = changes_qs
74
self.title_template = get_template(title_template)
75
self.description_template = get_template(description_template)
76
super(AtomHistoryFeed, self).__init__('', request)
82
return self.changes_qs.order_by('-modified')[:30]
69
84
def item_id(self, item):
70
85
return "%s" % item.id
88
103
c = Context({'obj' : item,})
89
104
return ({'type': 'html'}, self.description_template.render(c))
91
def item_author_name(self, item):
93
Takes the object returned by get_object and returns the feeds's
94
auhor's name as a Python string
96
if item.is_anonymous_change():
98
return item.editor.username
101
107
class RssArticleHistoryFeed(Feed):
103
feed_type = Rss201rev2Feed
104
109
def __init__(self, title, request,
105
110
group_slug=None, group_slug_field=None, group_qs=None,
106
111
article_qs=ALL_ARTICLES, changes_qs=ALL_CHANGES,
145
150
return item.modified
148
class AtomArticleHistoryFeed(RssArticleHistoryFeed):
149
feed_type = Atom1Feed
153
class AtomArticleHistoryFeed(atom.Feed):
155
def __init__(self, title, request,
156
group_slug=None, group_slug_field=None, group_qs=None,
157
article_qs=ALL_ARTICLES, changes_qs=ALL_CHANGES,
159
title_template = u'feeds/history_title.html',
160
description_template = u'feeds/history_description.html',
163
if group_slug is not None:
164
group = get_object_or_404(group_qs,
165
**{group_slug_field : group_slug})
166
self.article_qs = article_qs.filter(content_type=get_ct(group),
169
self.article_qs = article_qs
171
self.title_template = get_template(title_template)
172
self.description_template = get_template(description_template)
173
super(AtomArticleHistoryFeed, self).__init__('', request)
151
175
def get_object(self, bits):
152
# We work around a bug here which is likely in atomformat.py;
153
# when the Article doesn't exist this throws an Exception. We
154
# will care for this by first checking for the Article
155
get_object_or_404(Article,title=bits[0])
157
176
return self.article_qs.get(title = bits[0])
160
178
def feed_title(self, obj):
161
179
return "History for: %s " % obj.title