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
1
from django.contrib.syndication.views import Feed, FeedDoesNotExist
10
2
from wiki.models import ChangeSet, Article
11
from wiki.utils import get_ct
12
3
from django.utils.feedgenerator import Atom1Feed, Rss201rev2Feed
14
ALL_ARTICLES = Article.objects.all()
15
ALL_CHANGES = ChangeSet.objects.all()
5
# Validated through http://validator.w3.org/feed/
17
8
class RssHistoryFeed(Feed):
19
10
feed_type = Rss201rev2Feed
20
11
title = 'History for all articles'
21
link = '/wiki/feeds/rss'
22
12
description = 'Recent changes in wiki'
24
def __init__(self, request,
25
group_slug=None, group_slug_field=None, group_qs=None,
26
article_qs=ALL_ARTICLES, changes_qs=ALL_CHANGES,
28
title_template = u'feeds/history_title.html',
29
description_template = u'feeds/history_description.html',
32
if group_slug is not None:
33
group = get_object_or_404(group_qs,
34
**{group_slug_field : group_slug})
35
self.changes_qs = changes_qs.filter(article__content_type=get_ct(group),
36
article__object_id=group.id)
38
self.changes_qs = changes_qs
40
self.title_template = title_template
41
self.description_template = description_template
42
super(RssHistoryFeed, self).__init__('', request)
13
link = '/wiki/feeds/rss/'
14
title_template = 'wiki/feeds/history_title.html'
15
description_template = 'wiki/feeds/history_description.html'
45
return self.changes_qs.order_by('-modified')[:30]
18
return ChangeSet.objects.order_by('-modified')[:30]
47
20
def item_pubdate(self, item):
49
Return the item's pubdate. It's this modified date
21
"""Return the item's pubdate.
23
It's this modified date
51
26
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
28
# Validated through http://validator.w3.org/feed/
63
31
class AtomHistoryFeed(RssHistoryFeed):
65
33
feed_type = Atom1Feed
66
feed_subtitle = 'Recent changes in wiki'
67
link = '/wiki/feeds/atom'
69
def item_id(self, item):
72
def item_title(self, item):
73
c = Context({'obj' : item})
74
return self.title_template.render(c)
76
def item_updated(self, item):
34
subtitle = 'Recent changes in wiki'
35
link = '/wiki/feeds/atom/'
37
def item_updateddate(self, item):
77
38
return item.modified
79
def item_authors(self, item):
80
if item.is_anonymous_change():
81
return [{'name' : _('Anonimous')},]
82
return [{'name' : item.editor.username},]
84
def item_links(self, item):
85
return [{'href': item.get_absolute_url()}, ]
87
def item_content(self, item):
88
c = Context({'obj' : item,})
89
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
40
# Validated through http://validator.w3.org/feed/
101
43
class RssArticleHistoryFeed(Feed):
103
44
feed_type = Rss201rev2Feed
104
def __init__(self, title, request,
105
group_slug=None, group_slug_field=None, group_qs=None,
106
article_qs=ALL_ARTICLES, changes_qs=ALL_CHANGES,
108
title_template = u'feeds/history_title.html',
109
description_template = u'feeds/history_description.html',
112
if group_slug is not None:
113
group = get_object_or_404(group_qs,
114
**{group_slug_field : group_slug})
115
self.article_qs = article_qs.filter(content_type=get_ct(group),
118
self.article_qs = article_qs
120
self.title_template = title_template
121
self.description_template = description_template
122
super(RssArticleHistoryFeed, self).__init__(title, request)
124
def get_object(self, bits):
125
return self.article_qs.get(title = bits[0])
127
def title(self, obj):
128
return "History for: %s " % obj.title
45
title_template = 'wiki/feeds/history_title.html'
46
description_template = 'wiki/feeds/history_description.html'
48
def get_object(self, request, *args, **kwargs):
49
return Article.objects.get(title=kwargs['title'])
51
def title(self, item):
52
return 'History for: %s ' % item.title
132
56
raise FeedDoesNotExist
133
return obj.get_absolute_url()
135
def description(self, obj):
136
return "Recent changes in %s" % obj.title
138
def items(self, obj):
139
return ChangeSet.objects.filter(article__id__exact=obj.id).order_by('-modified')[:30]
57
return item.get_absolute_url()
59
def description(self, item):
60
return 'Recent changes in %s' % item.title
62
def items(self, item):
63
return ChangeSet.objects.filter(article__id__exact=item.id).order_by('-modified')[:30]
141
65
def item_pubdate(self, item):
143
Returns the modified date
66
"""Returns the modified date."""
145
67
return item.modified
69
# Validated through http://validator.w3.org/feed/
148
72
class AtomArticleHistoryFeed(RssArticleHistoryFeed):
149
73
feed_type = Atom1Feed
151
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
return self.article_qs.get(title = bits[0])
160
def feed_title(self, obj):
161
return "History for: %s " % obj.title
163
def feed_subtitle(self, obj):
164
return "Recent changes in %s" % obj.title
169
def item_id(self, item):
170
return "%s" % item.id
172
def item_title(self, item):
173
c = Context({'obj' : item})
174
return self.title_template.render(c)
176
def item_updated(self, item):
75
def subtitle(self, item):
76
return 'Recent changes in %s' % item.title
78
def item_updateddate(self, item):
177
79
return item.modified
179
def item_authors(self, item):
180
if item.is_anonymous_change():
181
return [{'name' : _('Anonimous')},]
182
return [{'name' : item.editor.username},]
184
def item_links(self, item):
185
return [{'href': item.get_absolute_url()},]
187
def item_content(self, item):
188
c = Context({'obj' : item, })
189
return ({'type': 'html'}, self.description_template.render(c))