1
from django.contrib.syndication.feeds import Feed, FeedDoesNotExist
2
from django.utils.feedgenerator import Atom1Feed
3
from django.contrib.contenttypes.models import ContentType
4
from django.core.exceptions import ObjectDoesNotExist
5
from django.core.urlresolvers import reverse
6
from django.utils.translation import ugettext_lazy as _
7
from django.shortcuts import get_object_or_404, render_to_response
8
from django.template import Context, Template
9
from django.template.loader import get_template
10
from wiki.models import ChangeSet, Article
11
from wiki.utils import get_ct
12
import atomformat as atom
14
ALL_ARTICLES = Article.objects.all()
15
ALL_CHANGES = ChangeSet.objects.all()
17
class RssHistoryFeed(Feed):
19
title = 'History for all articles'
21
description = 'Recent changes in wiki'
23
def __init__(self, request,
24
group_slug=None, group_slug_field=None, group_qs=None,
25
article_qs=ALL_ARTICLES, changes_qs=ALL_CHANGES,
27
title_template = u'feeds/history_title.html',
28
description_template = u'feeds/history_description.html',
31
if group_slug is not None:
32
group = get_object_or_404(group_qs,
33
**{group_slug_field : group_slug})
34
self.changes_qs = changes_qs.filter(article__content_type=get_ct(group),
35
article__object_id=group.id)
37
self.changes_qs = changes_qs
39
self.title_template = title_template
40
self.description_template = description_template
41
super(RssHistoryFeed, self).__init__('', request)
44
return self.changes_qs.order_by('-modified')[:30]
46
def item_pubdate(self, item):
48
Return the item's pubdate. It's this modified date
53
class AtomHistoryFeed(atom.Feed):
55
feed_title = 'History for all articles'
56
feed_subtitle = 'Recent changes in wiki'
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]
84
def item_id(self, item):
87
def item_title(self, item):
88
c = Context({'obj' : item})
89
return self.title_template.render(c)
91
def item_updated(self, item):
94
def item_authors(self, item):
95
if item.is_anonymous_change():
96
return [{'name' : _('Anonimous')},]
97
return [{'name' : item.editor.username},]
99
def item_links(self, item):
100
return [{'href': item.get_absolute_url()}, ]
102
def item_content(self, item):
103
c = Context({'obj' : item,})
104
return ({'type': 'html'}, self.description_template.render(c))
107
class RssArticleHistoryFeed(Feed):
109
def __init__(self, title, request,
110
group_slug=None, group_slug_field=None, group_qs=None,
111
article_qs=ALL_ARTICLES, changes_qs=ALL_CHANGES,
113
title_template = u'feeds/history_title.html',
114
description_template = u'feeds/history_description.html',
117
if group_slug is not None:
118
group = get_object_or_404(group_qs,
119
**{group_slug_field : group_slug})
120
self.article_qs = article_qs.filter(content_type=get_ct(group),
123
self.article_qs = article_qs
125
self.title_template = title_template
126
self.description_template = description_template
127
super(RssArticleHistoryFeed, self).__init__(title, request)
129
def get_object(self, bits):
130
return self.article_qs.get(title = bits[0])
132
def title(self, obj):
133
return "History for: %s " % obj.title
137
raise FeedDoesNotExist
138
return obj.get_absolute_url()
140
def description(self, obj):
141
return "Recent changes in %s" % obj.title
143
def items(self, obj):
144
return ChangeSet.objects.filter(article__id__exact=obj.id).order_by('-modified')[:30]
146
def item_pubdate(self, item):
148
Returns the modified date
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)
175
def get_object(self, bits):
176
return self.article_qs.get(title = bits[0])
178
def feed_title(self, obj):
179
return "History for: %s " % obj.title
181
def feed_subtitle(self, obj):
182
return "Recent changes in %s" % obj.title
187
def items(self, obj):
188
return ChangeSet.objects.filter(article__id__exact=obj.id).order_by('-modified')[:30]
190
def item_id(self, item):
191
return "%s" % item.id
193
def item_title(self, item):
194
c = Context({'obj' : item})
195
return self.title_template.render(c)
197
def item_updated(self, item):
200
def item_authors(self, item):
201
if item.is_anonymous_change():
202
return [{'name' : _('Anonimous')},]
203
return [{'name' : item.editor.username},]
205
def item_links(self, item):
206
return [{'href': item.get_absolute_url()},]
208
def item_content(self, item):
209
c = Context({'obj' : item, })
210
return ({'type': 'html'}, self.description_template.render(c))