##// END OF EJS Templates
fixed wrong order of changes in feeds...
marcink -
r1162:76c5b69c beta
parent child Browse files
Show More
@@ -1,87 +1,115
1 1 # -*- coding: utf-8 -*-
2 2 """
3 3 rhodecode.controllers.feed
4 4 ~~~~~~~~~~~~~~~~~~~~~~~~~~
5 5
6 6 Feed controller for rhodecode
7 7
8 8 :created_on: Apr 23, 2010
9 9 :author: marcink
10 10 :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com>
11 11 :license: GPLv3, see COPYING for more details.
12 12 """
13 13 # This program is free software; you can redistribute it and/or
14 14 # modify it under the terms of the GNU General Public License
15 15 # as published by the Free Software Foundation; version 2
16 16 # of the License or (at your opinion) any later version of the license.
17 17 #
18 18 # This program is distributed in the hope that it will be useful,
19 19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 21 # GNU General Public License for more details.
22 22 #
23 23 # You should have received a copy of the GNU General Public License
24 24 # along with this program; if not, write to the Free Software
25 25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
26 26 # MA 02110-1301, USA.
27 27
28 28 import logging
29 29
30 30 from pylons import url, response, tmpl_context as c
31 31 from pylons.i18n.translation import _
32 32
33 33 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
34 34 from rhodecode.lib.base import BaseRepoController
35 35
36 36 from webhelpers.feedgenerator import Atom1Feed, Rss201rev2Feed
37 37
38 38 log = logging.getLogger(__name__)
39 39
40 40 class FeedController(BaseRepoController):
41 41
42 42 @LoginRequired(api_access=True)
43 43 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
44 44 'repository.admin')
45 45 def __before__(self):
46 46 super(FeedController, self).__before__()
47 47 #common values for feeds
48 48 self.description = _('Changes on %s repository')
49 49 self.title = self.title = _('%s %s feed') % (c.rhodecode_name, '%s')
50 50 self.language = 'en-us'
51 51 self.ttl = "5"
52 52 self.feed_nr = 10
53 53
54 def __changes(self, cs):
55 changes = ''
56
57 a = [n.path for n in cs.added]
58 if a:
59 changes += '\nA ' + '\nA '.join(a)
60
61 m = [n.path for n in cs.changed]
62 if m:
63 changes += '\nM ' + '\nM '.join(m)
64
65 d = [n.path for n in cs.removed]
66 if d:
67 changes += '\nD ' + '\nD '.join(d)
68
69 changes += '</pre>'
70
71 return changes
72
54 73 def atom(self, repo_name):
55 74 """Produce an atom-1.0 feed via feedgenerator module"""
56 75 feed = Atom1Feed(title=self.title % repo_name,
57 76 link=url('summary_home', repo_name=repo_name, qualified=True),
58 77 description=self.description % repo_name,
59 78 language=self.language,
60 79 ttl=self.ttl)
61 80
62 for cs in c.rhodecode_repo[:self.feed_nr]:
81 for cs in reversed(list(c.rhodecode_repo[-self.feed_nr:])):
82 desc = '%s - %s<br/><pre>' % (cs.author, cs.date)
83 desc += self.__changes(cs)
84
63 85 feed.add_item(title=cs.message,
64 86 link=url('changeset_home', repo_name=repo_name,
65 87 revision=cs.raw_id, qualified=True),
66 description=str(cs.date))
88 author_name=cs.author,
89 description=desc)
67 90
68 91 response.content_type = feed.mime_type
69 92 return feed.writeString('utf-8')
70 93
71 94
72 95 def rss(self, repo_name):
73 96 """Produce an rss2 feed via feedgenerator module"""
74 97 feed = Rss201rev2Feed(title=self.title % repo_name,
75 98 link=url('summary_home', repo_name=repo_name, qualified=True),
76 99 description=self.description % repo_name,
77 100 language=self.language,
78 101 ttl=self.ttl)
79 102
80 for cs in c.rhodecode_repo[:self.feed_nr]:
103 for cs in reversed(list(c.rhodecode_repo[-self.feed_nr:])):
104 desc = '%s - %s<br/><pre>' % (cs.author, cs.date)
105 desc += self.__changes(cs)
106
81 107 feed.add_item(title=cs.message,
82 108 link=url('changeset_home', repo_name=repo_name,
83 109 revision=cs.raw_id, qualified=True),
84 description=str(cs.date))
110 author_name=cs.author,
111 description=desc,
112 )
85 113
86 114 response.content_type = feed.mime_type
87 115 return feed.writeString('utf-8')
General Comments 0
You need to be logged in to leave comments. Login now