Mercurial > kallithea
annotate rhodecode/controllers/feed.py @ 691:7486da5f0628 beta
Refactor codes for scm model
Some test updates, added test for admin user controller
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sun, 14 Nov 2010 22:54:16 +0100 |
parents | ffd07396d315 |
children | fd2ea6ceadc8 |
rev | line source |
---|---|
252
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
1 #!/usr/bin/env python |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
2 # encoding: utf-8 |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
3 # feed controller for pylons |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
5 |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
6 # This program is free software; you can redistribute it and/or |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
7 # modify it under the terms of the GNU General Public License |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
8 # as published by the Free Software Foundation; version 2 |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
9 # of the License or (at your opinion) any later version of the license. |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
10 # |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
11 # This program is distributed in the hope that it will be useful, |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
14 # GNU General Public License for more details. |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
15 # |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
16 # You should have received a copy of the GNU General Public License |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
17 # along with this program; if not, write to the Free Software |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
19 # MA 02110-1301, USA. |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
20 """ |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
21 Created on April 23, 2010 |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
22 feed controller for pylons |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
23 @author: marcink |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
24 """ |
245
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
207
diff
changeset
|
25 from pylons import tmpl_context as c, url, response |
547
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
512
diff
changeset
|
26 from rhodecode.lib.base import BaseController, render |
691
7486da5f0628
Refactor codes for scm model
Marcin Kuzminski <marcin@python-works.com>
parents:
636
diff
changeset
|
27 from rhodecode.model.scm import ScmModel |
245
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
207
diff
changeset
|
28 from webhelpers.feedgenerator import Atom1Feed, Rss201rev2Feed |
205
66b20f525750
Added feed controllers, urls,and changed index page to use them.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
29 import logging |
66b20f525750
Added feed controllers, urls,and changed index page to use them.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
30 log = logging.getLogger(__name__) |
66b20f525750
Added feed controllers, urls,and changed index page to use them.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
31 |
66b20f525750
Added feed controllers, urls,and changed index page to use them.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
32 class FeedController(BaseController): |
66b20f525750
Added feed controllers, urls,and changed index page to use them.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
33 |
66b20f525750
Added feed controllers, urls,and changed index page to use them.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
34 #secure it or not ? |
66b20f525750
Added feed controllers, urls,and changed index page to use them.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
35 def __before__(self): |
66b20f525750
Added feed controllers, urls,and changed index page to use them.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
36 super(FeedController, self).__before__() |
207
8bdec09436cb
bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents:
205
diff
changeset
|
37 #common values for feeds |
8bdec09436cb
bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents:
205
diff
changeset
|
38 self.description = 'Changes on %s repository' |
8bdec09436cb
bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents:
205
diff
changeset
|
39 self.title = "%s feed" |
8bdec09436cb
bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents:
205
diff
changeset
|
40 self.language = 'en-us' |
8bdec09436cb
bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents:
205
diff
changeset
|
41 self.ttl = "5" |
8bdec09436cb
bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents:
205
diff
changeset
|
42 self.feed_nr = 10 |
8bdec09436cb
bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents:
205
diff
changeset
|
43 |
8bdec09436cb
bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents:
205
diff
changeset
|
44 def atom(self, repo_name): |
8bdec09436cb
bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents:
205
diff
changeset
|
45 """Produce an atom-1.0 feed via feedgenerator module""" |
8bdec09436cb
bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents:
205
diff
changeset
|
46 feed = Atom1Feed(title=self.title % repo_name, |
8bdec09436cb
bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents:
205
diff
changeset
|
47 link=url('summary_home', repo_name=repo_name, qualified=True), |
8bdec09436cb
bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents:
205
diff
changeset
|
48 description=self.description % repo_name, |
8bdec09436cb
bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents:
205
diff
changeset
|
49 language=self.language, |
8bdec09436cb
bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents:
205
diff
changeset
|
50 ttl=self.ttl) |
205
66b20f525750
Added feed controllers, urls,and changed index page to use them.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
51 |
691
7486da5f0628
Refactor codes for scm model
Marcin Kuzminski <marcin@python-works.com>
parents:
636
diff
changeset
|
52 changesets = ScmModel().get_repo(repo_name) |
507
f420e86db893
drastic speed improvment in feed generation (was using old method)
Marcin Kuzminski <marcin@python-works.com>
parents:
252
diff
changeset
|
53 |
f420e86db893
drastic speed improvment in feed generation (was using old method)
Marcin Kuzminski <marcin@python-works.com>
parents:
252
diff
changeset
|
54 for cs in changesets[:self.feed_nr]: |
207
8bdec09436cb
bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents:
205
diff
changeset
|
55 feed.add_item(title=cs.message, |
245
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
207
diff
changeset
|
56 link=url('changeset_home', repo_name=repo_name, |
636
ffd07396d315
Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
57 revision=cs.raw_id, qualified=True), |
245
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
207
diff
changeset
|
58 description=str(cs.date)) |
207
8bdec09436cb
bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents:
205
diff
changeset
|
59 |
8bdec09436cb
bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents:
205
diff
changeset
|
60 response.content_type = feed.mime_type |
8bdec09436cb
bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents:
205
diff
changeset
|
61 return feed.writeString('utf-8') |
8bdec09436cb
bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents:
205
diff
changeset
|
62 |
205
66b20f525750
Added feed controllers, urls,and changed index page to use them.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
63 |
207
8bdec09436cb
bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents:
205
diff
changeset
|
64 def rss(self, repo_name): |
8bdec09436cb
bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents:
205
diff
changeset
|
65 """Produce an rss2 feed via feedgenerator module""" |
8bdec09436cb
bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents:
205
diff
changeset
|
66 feed = Rss201rev2Feed(title=self.title % repo_name, |
8bdec09436cb
bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents:
205
diff
changeset
|
67 link=url('summary_home', repo_name=repo_name, qualified=True), |
8bdec09436cb
bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents:
205
diff
changeset
|
68 description=self.description % repo_name, |
8bdec09436cb
bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents:
205
diff
changeset
|
69 language=self.language, |
8bdec09436cb
bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents:
205
diff
changeset
|
70 ttl=self.ttl) |
8bdec09436cb
bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents:
205
diff
changeset
|
71 |
691
7486da5f0628
Refactor codes for scm model
Marcin Kuzminski <marcin@python-works.com>
parents:
636
diff
changeset
|
72 changesets = ScmModel().get_repo(repo_name) |
507
f420e86db893
drastic speed improvment in feed generation (was using old method)
Marcin Kuzminski <marcin@python-works.com>
parents:
252
diff
changeset
|
73 for cs in changesets[:self.feed_nr]: |
207
8bdec09436cb
bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents:
205
diff
changeset
|
74 feed.add_item(title=cs.message, |
507
f420e86db893
drastic speed improvment in feed generation (was using old method)
Marcin Kuzminski <marcin@python-works.com>
parents:
252
diff
changeset
|
75 link=url('changeset_home', repo_name=repo_name, |
636
ffd07396d315
Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
76 revision=cs.raw_id, qualified=True), |
207
8bdec09436cb
bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents:
205
diff
changeset
|
77 description=str(cs.date)) |
8bdec09436cb
bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents:
205
diff
changeset
|
78 |
8bdec09436cb
bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents:
205
diff
changeset
|
79 response.content_type = feed.mime_type |
8bdec09436cb
bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents:
205
diff
changeset
|
80 return feed.writeString('utf-8') |