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