~widelands-dev/widelands-website/trunk

« back to all changes in this revision

Viewing changes to wiki/feeds.py

  • Committer: Holger Rapp
  • Date: 2009-02-26 22:38:49 UTC
  • Revision ID: sirver@kallisto.local-20090226223849-1563ij0uuw0lz0zu
First version of widelands online help

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
13
13
 
14
14
ALL_ARTICLES = Article.objects.all()
15
15
ALL_CHANGES = ChangeSet.objects.all()
16
16
 
17
17
class RssHistoryFeed(Feed):
18
18
 
19
 
    feed_type = Rss201rev2Feed
20
19
    title = 'History for all articles'
21
 
    link = '/wiki/feeds/rss'
 
20
    link = '/wiki/'
22
21
    description = 'Recent changes in wiki'
23
22
 
24
23
    def __init__(self, request,
50
49
        """
51
50
        return item.modified
52
51
 
53
 
    def item_author_name(self, item):
54
 
        """
55
 
        Takes the object returned by get_object and returns the feeds's
56
 
        auhor's name as a Python string
57
 
        """
58
 
        if item.is_anonymous_change():
59
 
            return _("Anonymous")
60
 
        return item.editor.username
61
 
 
62
 
 
63
 
class AtomHistoryFeed(RssHistoryFeed):
64
 
 
65
 
    feed_type = Atom1Feed
 
52
 
 
53
class AtomHistoryFeed(atom.Feed):
 
54
 
 
55
    feed_title = 'History for all articles'
66
56
    feed_subtitle = 'Recent changes in wiki'
67
 
    link = '/wiki/feeds/atom'
 
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]
68
83
 
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))
90
105
 
91
 
    def item_author_name(self, item):
92
 
        """
93
 
        Takes the object returned by get_object and returns the feeds's
94
 
        auhor's name as a Python string
95
 
        """
96
 
        if item.is_anonymous_change():
97
 
            return _("Anonymous")
98
 
        return item.editor.username
99
 
 
100
106
 
101
107
class RssArticleHistoryFeed(Feed):
102
108
 
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
146
151
 
147
152
 
148
 
class AtomArticleHistoryFeed(RssArticleHistoryFeed):
149
 
    feed_type = Atom1Feed
 
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)
150
174
 
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])
156
 
        
157
176
        return self.article_qs.get(title = bits[0])
158
177
 
159
 
 
160
178
    def feed_title(self, obj):
161
179
        return "History for: %s " % obj.title
162
180
 
166
184
    def feed_id(self):
167
185
        return "feed_id"
168
186
 
 
187
    def items(self, obj):
 
188
        return ChangeSet.objects.filter(article__id__exact=obj.id).order_by('-modified')[:30]
 
189
 
169
190
    def item_id(self, item):
170
191
        return "%s" % item.id
171
192