~widelands-dev/widelands-website/django_staticfiles

« back to all changes in this revision

Viewing changes to wiki/feeds.py

  • Committer: Holger Rapp
  • Date: 2009-02-20 12:25:18 UTC
  • Revision ID: holgerrapp@gmx.net-20090220122518-feaq34ta973snnct
Imported wikiapp into our repository, because we did some local changes (users must be logged in to edit wiki pages)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
13
 
 
14
ALL_ARTICLES = Article.objects.all()
 
15
ALL_CHANGES = ChangeSet.objects.all()
 
16
 
 
17
class RssHistoryFeed(Feed):
 
18
 
 
19
    title = 'History for all articles'
 
20
    link = '/wiki/'
 
21
    description = 'Recent changes in wiki'
 
22
 
 
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, 
 
26
                 extra_context=None, 
 
27
                 title_template = u'feeds/history_title.html', 
 
28
                 description_template = u'feeds/history_description.html', 
 
29
                 *args, **kw):
 
30
 
 
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)
 
36
        else:
 
37
            self.changes_qs = changes_qs
 
38
 
 
39
        self.title_template = title_template
 
40
        self.description_template = description_template
 
41
        super(RssHistoryFeed, self).__init__('', request)
 
42
 
 
43
    def items(self):
 
44
        return self.changes_qs.order_by('-modified')[:30]
 
45
        
 
46
    def item_pubdate(self, item):
 
47
        """
 
48
        Return the item's pubdate. It's this modified date
 
49
        """
 
50
        return item.modified
 
51
 
 
52
 
 
53
class AtomHistoryFeed(atom.Feed):
 
54
 
 
55
    feed_title = 'History for all articles'
 
56
    feed_subtitle = 'Recent changes in wiki'
 
57
 
 
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, 
 
61
                 extra_context=None, 
 
62
                 title_template = u'feeds/history_title.html', 
 
63
                 description_template = u'feeds/history_description.html', 
 
64
                 *args, **kw):
 
65
 
 
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)
 
71
        else:
 
72
            self.changes_qs = changes_qs
 
73
 
 
74
        self.title_template = get_template(title_template)
 
75
        self.description_template = get_template(description_template)
 
76
        super(AtomHistoryFeed, self).__init__('', request)
 
77
 
 
78
    def feed_id(self):
 
79
        return "feed_id"
 
80
 
 
81
    def items(self):
 
82
        return self.changes_qs.order_by('-modified')[:30]
 
83
 
 
84
    def item_id(self, item):
 
85
        return "%s" % item.id
 
86
 
 
87
    def item_title(self, item):
 
88
        c = Context({'obj' : item})
 
89
        return self.title_template.render(c)
 
90
 
 
91
    def item_updated(self, item):
 
92
        return item.modified
 
93
 
 
94
    def item_authors(self, item):
 
95
        if item.is_anonymous_change():
 
96
            return [{'name' : _('Anonimous')},]
 
97
        return [{'name' : item.editor.username},]
 
98
 
 
99
    def item_links(self, item):
 
100
        return [{'href': item.get_absolute_url()}, ]
 
101
 
 
102
    def item_content(self, item):
 
103
        c = Context({'obj' : item,})
 
104
        return ({'type': 'html'}, self.description_template.render(c))
 
105
 
 
106
 
 
107
class RssArticleHistoryFeed(Feed):
 
108
 
 
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,
 
112
                extra_context=None,
 
113
                title_template = u'feeds/history_title.html',
 
114
                description_template = u'feeds/history_description.html',
 
115
                *args, **kw):
 
116
 
 
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),
 
121
                                           object_id=group.id)
 
122
        else:
 
123
            self.article_qs = article_qs
 
124
 
 
125
        self.title_template = title_template
 
126
        self.description_template = description_template
 
127
        super(RssArticleHistoryFeed, self).__init__(title, request)
 
128
 
 
129
    def get_object(self, bits):
 
130
        return self.article_qs.get(title = bits[0])
 
131
 
 
132
    def title(self, obj):
 
133
        return "History for: %s " % obj.title
 
134
 
 
135
    def link(self, obj):
 
136
        if not obj:
 
137
            raise FeedDoesNotExist
 
138
        return obj.get_absolute_url()
 
139
 
 
140
    def description(self, obj):
 
141
        return "Recent changes in %s" % obj.title
 
142
 
 
143
    def items(self, obj):
 
144
        return ChangeSet.objects.filter(article__id__exact=obj.id).order_by('-modified')[:30]
 
145
 
 
146
    def item_pubdate(self, item):
 
147
        """
 
148
        Returns the modified date
 
149
        """
 
150
        return item.modified
 
151
 
 
152
 
 
153
class AtomArticleHistoryFeed(atom.Feed):
 
154
    
 
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,
 
158
                extra_context=None,
 
159
                title_template = u'feeds/history_title.html',
 
160
                description_template = u'feeds/history_description.html',
 
161
                *args, **kw):
 
162
 
 
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),
 
167
                                           object_id=group.id)
 
168
        else:
 
169
            self.article_qs = article_qs
 
170
 
 
171
        self.title_template = get_template(title_template)
 
172
        self.description_template = get_template(description_template)
 
173
        super(AtomArticleHistoryFeed, self).__init__('', request)
 
174
 
 
175
    def get_object(self, bits):
 
176
        return self.article_qs.get(title = bits[0])
 
177
 
 
178
    def feed_title(self, obj):
 
179
        return "History for: %s " % obj.title
 
180
 
 
181
    def feed_subtitle(self, obj):
 
182
        return "Recent changes in %s" % obj.title
 
183
 
 
184
    def feed_id(self):
 
185
        return "feed_id"
 
186
 
 
187
    def items(self, obj):
 
188
        return ChangeSet.objects.filter(article__id__exact=obj.id).order_by('-modified')[:30]
 
189
 
 
190
    def item_id(self, item):
 
191
        return "%s" % item.id
 
192
 
 
193
    def item_title(self, item):
 
194
        c = Context({'obj' : item})
 
195
        return self.title_template.render(c)
 
196
 
 
197
    def item_updated(self, item):
 
198
        return item.modified
 
199
 
 
200
    def item_authors(self, item):
 
201
        if item.is_anonymous_change():
 
202
            return [{'name' : _('Anonimous')},]
 
203
        return [{'name' : item.editor.username},]
 
204
 
 
205
    def item_links(self, item):
 
206
        return [{'href': item.get_absolute_url()},]
 
207
 
 
208
    def item_content(self, item):
 
209
        c = Context({'obj' : item, })
 
210
        return ({'type': 'html'}, self.description_template.render(c))