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