Mercurial > kallithea
annotate kallithea/controllers/feed.py @ 4196:06e49be38d78 kallithea-2.2.5-rebrand
Rename rhodecode_repo to db_repo_scm_instance
author | Bradley M. Kuhn <bkuhn@sfconservancy.org> |
---|---|
date | Wed, 02 Jul 2014 19:05:00 -0400 |
parents | 9581233e9275 |
children | a540f7e69c82 |
rev | line source |
---|---|
861
fd2ea6ceadc8
updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
1 # -*- coding: utf-8 -*- |
1206
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
2 # This program is free software: you can redistribute it and/or modify |
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
3 # it under the terms of the GNU General Public License as published by |
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
4 # the Free Software Foundation, either version 3 of the License, or |
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
5 # (at your option) any later version. |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1162
diff
changeset
|
6 # |
252
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
7 # 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
|
8 # 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
|
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
10 # GNU General Public License for more details. |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1162
diff
changeset
|
11 # |
252
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
12 # You should have received a copy of the GNU General Public License |
1206
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
13 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4098
diff
changeset
|
14 """ |
4186
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4116
diff
changeset
|
15 kallithea.controllers.feed |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4098
diff
changeset
|
16 ~~~~~~~~~~~~~~~~~~~~~~~~~~ |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4098
diff
changeset
|
17 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4098
diff
changeset
|
18 Feed controller for rhodecode |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4098
diff
changeset
|
19 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4098
diff
changeset
|
20 :created_on: Apr 23, 2010 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4098
diff
changeset
|
21 :author: marcink |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4098
diff
changeset
|
22 :copyright: (c) 2013 RhodeCode GmbH. |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4098
diff
changeset
|
23 :license: GPLv3, see LICENSE for more details. |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4098
diff
changeset
|
24 """ |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4098
diff
changeset
|
25 |
861
fd2ea6ceadc8
updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
26 |
fd2ea6ceadc8
updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
27 import logging |
fd2ea6ceadc8
updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
28 |
1045
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
29 from pylons import url, response, tmpl_context as c |
1038
5554aa9c2480
another major code rafactor, reimplemented (almost from scratch)
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
30 from pylons.i18n.translation import _ |
862
4bdd0bf1b1f4
security bugfix: protected feeds, from unauthorized access, even without this, the feeds would crash and were unreadable, But proper way of securing it is with the secure decarators.
Marcin Kuzminski <marcin@python-works.com>
parents:
861
diff
changeset
|
31 |
3018
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
32 from beaker.cache import cache_region, region_invalidate |
2385
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
33 from webhelpers.feedgenerator import Atom1Feed, Rss201rev2Feed |
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
34 |
4186
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4116
diff
changeset
|
35 from kallithea.lib import helpers as h |
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4116
diff
changeset
|
36 from kallithea.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator |
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4116
diff
changeset
|
37 from kallithea.lib.base import BaseRepoController |
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4116
diff
changeset
|
38 from kallithea.lib.diffs import DiffProcessor, LimitedDiffContainer |
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4116
diff
changeset
|
39 from kallithea.model.db import CacheInvalidation |
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4116
diff
changeset
|
40 from kallithea.lib.utils2 import safe_int, str2bool, safe_unicode |
861
fd2ea6ceadc8
updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
41 |
205
66b20f525750
Added feed controllers, urls,and changed index page to use them.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
42 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
|
43 |
1212 | 44 |
1045
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
45 class FeedController(BaseRepoController): |
861
fd2ea6ceadc8
updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
46 |
1120
a8d759613d8f
fixed some bugs in api key auth, added access by api key into rss/atom feeds in global journal
Marcin Kuzminski <marcin@python-works.com>
parents:
1088
diff
changeset
|
47 @LoginRequired(api_access=True) |
862
4bdd0bf1b1f4
security bugfix: protected feeds, from unauthorized access, even without this, the feeds would crash and were unreadable, But proper way of securing it is with the secure decarators.
Marcin Kuzminski <marcin@python-works.com>
parents:
861
diff
changeset
|
48 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', |
4bdd0bf1b1f4
security bugfix: protected feeds, from unauthorized access, even without this, the feeds would crash and were unreadable, But proper way of securing it is with the secure decarators.
Marcin Kuzminski <marcin@python-works.com>
parents:
861
diff
changeset
|
49 'repository.admin') |
205
66b20f525750
Added feed controllers, urls,and changed index page to use them.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
50 def __before__(self): |
66b20f525750
Added feed controllers, urls,and changed index page to use them.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
51 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
|
52 #common values for feeds |
1038
5554aa9c2480
another major code rafactor, reimplemented (almost from scratch)
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
53 self.description = _('Changes on %s repository') |
1088
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
54 self.title = self.title = _('%s %s feed') % (c.rhodecode_name, '%s') |
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 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
|
56 self.ttl = "5" |
4186
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4116
diff
changeset
|
57 import kallithea |
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4116
diff
changeset
|
58 CONF = kallithea.CONFIG |
3028
30a226406fa4
Implemented #661 Add option to include diff in RSS feed
Marcin Kuzminski <marcin@python-works.com>
parents:
3018
diff
changeset
|
59 self.include_diff = str2bool(CONF.get('rss_include_diff', False)) |
30a226406fa4
Implemented #661 Add option to include diff in RSS feed
Marcin Kuzminski <marcin@python-works.com>
parents:
3018
diff
changeset
|
60 self.feed_nr = safe_int(CONF.get('rss_items_per_page', 20)) |
3018
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
61 # we need to protect from parsing huge diffs here other way |
3028
30a226406fa4
Implemented #661 Add option to include diff in RSS feed
Marcin Kuzminski <marcin@python-works.com>
parents:
3018
diff
changeset
|
62 # we can kill the server |
3030
48cbd37cf6fc
fix safe_int default arg
Marcin Kuzminski <marcin@python-works.com>
parents:
3029
diff
changeset
|
63 self.feed_diff_limit = safe_int(CONF.get('rss_cut_off_limit', 32 * 1024)) |
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 |
1897
0f22dedb588f
added short_id to feeds, and made it more compact
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
65 def _get_title(self, cs): |
2385
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
66 return "%s" % ( |
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
67 h.shorter(cs.message, 160) |
1897
0f22dedb588f
added short_id to feeds, and made it more compact
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
68 ) |
0f22dedb588f
added short_id to feeds, and made it more compact
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
69 |
1162
76c5b69c1b27
fixed wrong order of changes in feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
1120
diff
changeset
|
70 def __changes(self, cs): |
1359
54fc83f2192c
Removed all string concat for exchange of ''.join()
Marcin Kuzminski <marcin@python-works.com>
parents:
1295
diff
changeset
|
71 changes = [] |
3018
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
72 diff_processor = DiffProcessor(cs.diff(), |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
73 diff_limit=self.feed_diff_limit) |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
74 _parsed = diff_processor.prepare(inline_diff=False) |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
75 limited_diff = False |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
76 if isinstance(_parsed, LimitedDiffContainer): |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
77 limited_diff = True |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
78 |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
79 for st in _parsed: |
3821
ce4b7023a492
diff parser: redefined operations stats for changes
Marcin Kuzminski <marcin@python-works.com>
parents:
3773
diff
changeset
|
80 st.update({'added': st['stats']['added'], |
ce4b7023a492
diff parser: redefined operations stats for changes
Marcin Kuzminski <marcin@python-works.com>
parents:
3773
diff
changeset
|
81 'removed': st['stats']['deleted']}) |
2385
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
82 changes.append('\n %(operation)s %(filename)s ' |
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
83 '(%(added)s lines added, %(removed)s lines removed)' |
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
84 % st) |
3018
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
85 if limited_diff: |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
86 changes = changes + ['\n ' + |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
87 _('Changeset was too big and was cut off...')] |
3028
30a226406fa4
Implemented #661 Add option to include diff in RSS feed
Marcin Kuzminski <marcin@python-works.com>
parents:
3018
diff
changeset
|
88 return diff_processor, changes |
1162
76c5b69c1b27
fixed wrong order of changes in feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
1120
diff
changeset
|
89 |
2385
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
90 def __get_desc(self, cs): |
3890
f5a1314886ec
replace list appends with list literals when possible
Marcin Kuzminski <marcin@python-works.com>
parents:
3821
diff
changeset
|
91 desc_msg = [(_('%s committed on %s') |
f5a1314886ec
replace list appends with list literals when possible
Marcin Kuzminski <marcin@python-works.com>
parents:
3821
diff
changeset
|
92 % (h.person(cs.author), h.fmt_date(cs.date))) + '<br/>'] |
2980
234435584a0d
implements #632,
Marcin Kuzminski <marcin@python-works.com>
parents:
2783
diff
changeset
|
93 #branches, tags, bookmarks |
234435584a0d
implements #632,
Marcin Kuzminski <marcin@python-works.com>
parents:
2783
diff
changeset
|
94 if cs.branch: |
234435584a0d
implements #632,
Marcin Kuzminski <marcin@python-works.com>
parents:
2783
diff
changeset
|
95 desc_msg.append('branch: %s<br/>' % cs.branch) |
4196
06e49be38d78
Rename rhodecode_repo to db_repo_scm_instance
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4195
diff
changeset
|
96 if h.is_hg(c.db_repo_scm_instance): |
2980
234435584a0d
implements #632,
Marcin Kuzminski <marcin@python-works.com>
parents:
2783
diff
changeset
|
97 for book in cs.bookmarks: |
234435584a0d
implements #632,
Marcin Kuzminski <marcin@python-works.com>
parents:
2783
diff
changeset
|
98 desc_msg.append('bookmark: %s<br/>' % book) |
234435584a0d
implements #632,
Marcin Kuzminski <marcin@python-works.com>
parents:
2783
diff
changeset
|
99 for tag in cs.tags: |
234435584a0d
implements #632,
Marcin Kuzminski <marcin@python-works.com>
parents:
2783
diff
changeset
|
100 desc_msg.append('tag: %s<br/>' % tag) |
3028
30a226406fa4
Implemented #661 Add option to include diff in RSS feed
Marcin Kuzminski <marcin@python-works.com>
parents:
3018
diff
changeset
|
101 diff_processor, changes = self.__changes(cs) |
2980
234435584a0d
implements #632,
Marcin Kuzminski <marcin@python-works.com>
parents:
2783
diff
changeset
|
102 # rev link |
4195
9581233e9275
Rename rhodecode_db_repo to db_repo - it stores db repo abstractions
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4187
diff
changeset
|
103 _url = url('changeset_home', repo_name=c.db_repo.repo_name, |
2980
234435584a0d
implements #632,
Marcin Kuzminski <marcin@python-works.com>
parents:
2783
diff
changeset
|
104 revision=cs.raw_id, qualified=True) |
3654
ec6354949623
Fix a lot of casings - use standard casing in most places
Mads Kiilerich <madski@unity3d.com>
parents:
3292
diff
changeset
|
105 desc_msg.append('changeset: <a href="%s">%s</a>' % (_url, cs.raw_id[:8])) |
2980
234435584a0d
implements #632,
Marcin Kuzminski <marcin@python-works.com>
parents:
2783
diff
changeset
|
106 |
2385
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
107 desc_msg.append('<pre>') |
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
108 desc_msg.append(cs.message) |
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
109 desc_msg.append('\n') |
3028
30a226406fa4
Implemented #661 Add option to include diff in RSS feed
Marcin Kuzminski <marcin@python-works.com>
parents:
3018
diff
changeset
|
110 desc_msg.extend(changes) |
30a226406fa4
Implemented #661 Add option to include diff in RSS feed
Marcin Kuzminski <marcin@python-works.com>
parents:
3018
diff
changeset
|
111 if self.include_diff: |
30a226406fa4
Implemented #661 Add option to include diff in RSS feed
Marcin Kuzminski <marcin@python-works.com>
parents:
3018
diff
changeset
|
112 desc_msg.append('\n\n') |
30a226406fa4
Implemented #661 Add option to include diff in RSS feed
Marcin Kuzminski <marcin@python-works.com>
parents:
3018
diff
changeset
|
113 desc_msg.append(diff_processor.as_raw()) |
2385
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
114 desc_msg.append('</pre>') |
3292
2464ac75d77a
fixed #746 unicodeDedode errors on feed controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
3030
diff
changeset
|
115 return map(safe_unicode, desc_msg) |
1162
76c5b69c1b27
fixed wrong order of changes in feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
1120
diff
changeset
|
116 |
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
|
117 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
|
118 """Produce an atom-1.0 feed via feedgenerator module""" |
3018
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
119 |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
120 @cache_region('long_term') |
3773
8e2cd46f765b
invalidate: encapsulate how key is generated from repo_name and kind
Mads Kiilerich <madski@unity3d.com>
parents:
3772
diff
changeset
|
121 def _get_feed_from_cache(key, kind): |
3018
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
122 feed = Atom1Feed( |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
123 title=self.title % repo_name, |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
124 link=url('summary_home', repo_name=repo_name, |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
125 qualified=True), |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
126 description=self.description % repo_name, |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
127 language=self.language, |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
128 ttl=self.ttl |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
129 ) |
1897
0f22dedb588f
added short_id to feeds, and made it more compact
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
130 |
4196
06e49be38d78
Rename rhodecode_repo to db_repo_scm_instance
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4195
diff
changeset
|
131 for cs in reversed(list(c.db_repo_scm_instance[-self.feed_nr:])): |
3018
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
132 feed.add_item(title=self._get_title(cs), |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
133 link=url('changeset_home', repo_name=repo_name, |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
134 revision=cs.raw_id, qualified=True), |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
135 author_name=cs.author, |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
136 description=''.join(self.__get_desc(cs)), |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
137 pubdate=cs.date, |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
138 ) |
861
fd2ea6ceadc8
updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
139 |
3018
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
140 response.content_type = feed.mime_type |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
141 return feed.writeString('utf-8') |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
142 |
3773
8e2cd46f765b
invalidate: encapsulate how key is generated from repo_name and kind
Mads Kiilerich <madski@unity3d.com>
parents:
3772
diff
changeset
|
143 kind = 'ATOM' |
8e2cd46f765b
invalidate: encapsulate how key is generated from repo_name and kind
Mads Kiilerich <madski@unity3d.com>
parents:
3772
diff
changeset
|
144 valid = CacheInvalidation.test_and_set_valid(repo_name, kind) |
3772
910ad1ffee99
invalidation: merge .invalidate and .set_valid as .test_and_set_valid
Mads Kiilerich <madski@unity3d.com>
parents:
3654
diff
changeset
|
145 if not valid: |
3773
8e2cd46f765b
invalidate: encapsulate how key is generated from repo_name and kind
Mads Kiilerich <madski@unity3d.com>
parents:
3772
diff
changeset
|
146 region_invalidate(_get_feed_from_cache, None, repo_name, kind) |
8e2cd46f765b
invalidate: encapsulate how key is generated from repo_name and kind
Mads Kiilerich <madski@unity3d.com>
parents:
3772
diff
changeset
|
147 return _get_feed_from_cache(repo_name, kind) |
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
|
148 |
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
|
149 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
|
150 """Produce an rss2 feed via feedgenerator module""" |
3018
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
151 |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
152 @cache_region('long_term') |
3773
8e2cd46f765b
invalidate: encapsulate how key is generated from repo_name and kind
Mads Kiilerich <madski@unity3d.com>
parents:
3772
diff
changeset
|
153 def _get_feed_from_cache(key, kind): |
3018
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
154 feed = Rss201rev2Feed( |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
155 title=self.title % repo_name, |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
156 link=url('summary_home', repo_name=repo_name, |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
157 qualified=True), |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
158 description=self.description % repo_name, |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
159 language=self.language, |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
160 ttl=self.ttl |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
161 ) |
1897
0f22dedb588f
added short_id to feeds, and made it more compact
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
162 |
4196
06e49be38d78
Rename rhodecode_repo to db_repo_scm_instance
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4195
diff
changeset
|
163 for cs in reversed(list(c.db_repo_scm_instance[-self.feed_nr:])): |
3018
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
164 feed.add_item(title=self._get_title(cs), |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
165 link=url('changeset_home', repo_name=repo_name, |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
166 revision=cs.raw_id, qualified=True), |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
167 author_name=cs.author, |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
168 description=''.join(self.__get_desc(cs)), |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
169 pubdate=cs.date, |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
170 ) |
861
fd2ea6ceadc8
updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
171 |
3018
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
172 response.content_type = feed.mime_type |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
173 return feed.writeString('utf-8') |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
174 |
3773
8e2cd46f765b
invalidate: encapsulate how key is generated from repo_name and kind
Mads Kiilerich <madski@unity3d.com>
parents:
3772
diff
changeset
|
175 kind = 'RSS' |
8e2cd46f765b
invalidate: encapsulate how key is generated from repo_name and kind
Mads Kiilerich <madski@unity3d.com>
parents:
3772
diff
changeset
|
176 valid = CacheInvalidation.test_and_set_valid(repo_name, kind) |
3772
910ad1ffee99
invalidation: merge .invalidate and .set_valid as .test_and_set_valid
Mads Kiilerich <madski@unity3d.com>
parents:
3654
diff
changeset
|
177 if not valid: |
3773
8e2cd46f765b
invalidate: encapsulate how key is generated from repo_name and kind
Mads Kiilerich <madski@unity3d.com>
parents:
3772
diff
changeset
|
178 region_invalidate(_get_feed_from_cache, None, repo_name, kind) |
8e2cd46f765b
invalidate: encapsulate how key is generated from repo_name and kind
Mads Kiilerich <madski@unity3d.com>
parents:
3772
diff
changeset
|
179 return _get_feed_from_cache(repo_name, kind) |