comparison rhodecode/controllers/feed.py @ 547:1e757ac98988

renamed project to rhodecode
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 06 Oct 2010 03:18:16 +0200
parents pylons_app/controllers/feed.py@d945c95ba4ac
children 7e536d1af60d
comparison
equal deleted inserted replaced
546:7c2f5e4d7bbf 547:1e757ac98988
1 #!/usr/bin/env python
2 # encoding: utf-8
3 # feed controller for pylons
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
5
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; version 2
9 # of the License or (at your opinion) any later version of the license.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 # MA 02110-1301, USA.
20 """
21 Created on April 23, 2010
22 feed controller for pylons
23 @author: marcink
24 """
25 from pylons import tmpl_context as c, url, response
26 from rhodecode.lib.base import BaseController, render
27 from rhodecode.model.hg_model import HgModel
28 from webhelpers.feedgenerator import Atom1Feed, Rss201rev2Feed
29 import logging
30 log = logging.getLogger(__name__)
31
32 class FeedController(BaseController):
33
34 #secure it or not ?
35 def __before__(self):
36 super(FeedController, self).__before__()
37 #common values for feeds
38 self.description = 'Changes on %s repository'
39 self.title = "%s feed"
40 self.language = 'en-us'
41 self.ttl = "5"
42 self.feed_nr = 10
43
44 def atom(self, repo_name):
45 """Produce an atom-1.0 feed via feedgenerator module"""
46 feed = Atom1Feed(title=self.title % repo_name,
47 link=url('summary_home', repo_name=repo_name, qualified=True),
48 description=self.description % repo_name,
49 language=self.language,
50 ttl=self.ttl)
51
52 changesets = HgModel().get_repo(repo_name)
53
54 for cs in changesets[:self.feed_nr]:
55 feed.add_item(title=cs.message,
56 link=url('changeset_home', repo_name=repo_name,
57 revision=cs.short_id, qualified=True),
58 description=str(cs.date))
59
60 response.content_type = feed.mime_type
61 return feed.writeString('utf-8')
62
63
64 def rss(self, repo_name):
65 """Produce an rss2 feed via feedgenerator module"""
66 feed = Rss201rev2Feed(title=self.title % repo_name,
67 link=url('summary_home', repo_name=repo_name, qualified=True),
68 description=self.description % repo_name,
69 language=self.language,
70 ttl=self.ttl)
71
72 changesets = HgModel().get_repo(repo_name)
73 for cs in changesets[:self.feed_nr]:
74 feed.add_item(title=cs.message,
75 link=url('changeset_home', repo_name=repo_name,
76 revision=cs.short_id, qualified=True),
77 description=str(cs.date))
78
79 response.content_type = feed.mime_type
80 return feed.writeString('utf-8')