Mercurial > kallithea
annotate rhodecode/controllers/feed.py @ 3212:6c28533d122c beta
IP restrictions now also enabled for IPv6
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Wed, 23 Jan 2013 23:51:57 +0100 |
parents | 48cbd37cf6fc |
children | a5f0bc867edc 2464ac75d77a |
rev | line source |
---|---|
861
fd2ea6ceadc8
updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
1 # -*- coding: utf-8 -*- |
fd2ea6ceadc8
updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
2 """ |
fd2ea6ceadc8
updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
3 rhodecode.controllers.feed |
fd2ea6ceadc8
updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~ |
fd2ea6ceadc8
updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
5 |
fd2ea6ceadc8
updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
6 Feed controller for rhodecode |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1162
diff
changeset
|
7 |
861
fd2ea6ceadc8
updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
8 :created_on: Apr 23, 2010 |
fd2ea6ceadc8
updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
9 :author: marcink |
1824
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1359
diff
changeset
|
10 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com> |
861
fd2ea6ceadc8
updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
11 :license: GPLv3, see COPYING for more details. |
fd2ea6ceadc8
updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
12 """ |
1206
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
13 # 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
|
14 # 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
|
15 # 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
|
16 # (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
|
17 # |
252
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
18 # 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
|
19 # 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
|
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
21 # 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
|
22 # |
252
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
23 # 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
|
24 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
861
fd2ea6ceadc8
updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
25 |
fd2ea6ceadc8
updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
26 import logging |
fd2ea6ceadc8
updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
27 |
1045
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
28 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
|
29 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
|
30 |
3018
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
31 from beaker.cache import cache_region, region_invalidate |
2385
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
32 from webhelpers.feedgenerator import Atom1Feed, Rss201rev2Feed |
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
33 |
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
34 from rhodecode.lib import helpers as h |
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
|
35 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator |
1045
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
36 from rhodecode.lib.base import BaseRepoController |
3018
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
37 from rhodecode.lib.diffs import DiffProcessor, LimitedDiffContainer |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
38 from rhodecode.model.db import CacheInvalidation |
3028
30a226406fa4
Implemented #661 Add option to include diff in RSS feed
Marcin Kuzminski <marcin@python-works.com>
parents:
3018
diff
changeset
|
39 from rhodecode.lib.utils2 import safe_int, str2bool |
861
fd2ea6ceadc8
updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
40 |
205
66b20f525750
Added feed controllers, urls,and changed index page to use them.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
41 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
|
42 |
1212 | 43 |
1045
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1038
diff
changeset
|
44 class FeedController(BaseRepoController): |
861
fd2ea6ceadc8
updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
45 |
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
|
46 @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
|
47 @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
|
48 'repository.admin') |
205
66b20f525750
Added feed controllers, urls,and changed index page to use them.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
49 def __before__(self): |
66b20f525750
Added feed controllers, urls,and changed index page to use them.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
50 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
|
51 #common values for feeds |
1038
5554aa9c2480
another major code rafactor, reimplemented (almost from scratch)
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
52 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
|
53 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
|
54 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
|
55 self.ttl = "5" |
3028
30a226406fa4
Implemented #661 Add option to include diff in RSS feed
Marcin Kuzminski <marcin@python-works.com>
parents:
3018
diff
changeset
|
56 import rhodecode |
30a226406fa4
Implemented #661 Add option to include diff in RSS feed
Marcin Kuzminski <marcin@python-works.com>
parents:
3018
diff
changeset
|
57 CONF = rhodecode.CONFIG |
30a226406fa4
Implemented #661 Add option to include diff in RSS feed
Marcin Kuzminski <marcin@python-works.com>
parents:
3018
diff
changeset
|
58 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
|
59 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
|
60 # 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
|
61 # we can kill the server |
3030
48cbd37cf6fc
fix safe_int default arg
Marcin Kuzminski <marcin@python-works.com>
parents:
3029
diff
changeset
|
62 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
|
63 |
1897
0f22dedb588f
added short_id to feeds, and made it more compact
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
64 def _get_title(self, cs): |
2385
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
65 return "%s" % ( |
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
66 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
|
67 ) |
0f22dedb588f
added short_id to feeds, and made it more compact
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
68 |
1162
76c5b69c1b27
fixed wrong order of changes in feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
1120
diff
changeset
|
69 def __changes(self, cs): |
1359
54fc83f2192c
Removed all string concat for exchange of ''.join()
Marcin Kuzminski <marcin@python-works.com>
parents:
1295
diff
changeset
|
70 changes = [] |
3018
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
71 diff_processor = DiffProcessor(cs.diff(), |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
72 diff_limit=self.feed_diff_limit) |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
73 _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
|
74 limited_diff = False |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
75 if isinstance(_parsed, LimitedDiffContainer): |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
76 limited_diff = True |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
77 |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
78 for st in _parsed: |
2385
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
79 st.update({'added': st['stats'][0], |
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
80 'removed': st['stats'][1]}) |
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
81 changes.append('\n %(operation)s %(filename)s ' |
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
82 '(%(added)s lines added, %(removed)s lines removed)' |
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
83 % st) |
3018
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
84 if limited_diff: |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
85 changes = changes + ['\n ' + |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
86 _('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
|
87 return diff_processor, changes |
1162
76c5b69c1b27
fixed wrong order of changes in feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
1120
diff
changeset
|
88 |
2385
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
89 def __get_desc(self, cs): |
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
90 desc_msg = [] |
3018
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
91 desc_msg.append('%s %s %s<br/>' % (h.person(cs.author), |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
92 _('commited on'), |
2419
513de5ffe608
Also use the date formatter on the feeds.
Vincent Duvert <vincent@duvert.net>
parents:
2385
diff
changeset
|
93 h.fmt_date(cs.date))) |
2980
234435584a0d
implements #632,
Marcin Kuzminski <marcin@python-works.com>
parents:
2783
diff
changeset
|
94 #branches, tags, bookmarks |
234435584a0d
implements #632,
Marcin Kuzminski <marcin@python-works.com>
parents:
2783
diff
changeset
|
95 if cs.branch: |
234435584a0d
implements #632,
Marcin Kuzminski <marcin@python-works.com>
parents:
2783
diff
changeset
|
96 desc_msg.append('branch: %s<br/>' % cs.branch) |
234435584a0d
implements #632,
Marcin Kuzminski <marcin@python-works.com>
parents:
2783
diff
changeset
|
97 if h.is_hg(c.rhodecode_repo): |
234435584a0d
implements #632,
Marcin Kuzminski <marcin@python-works.com>
parents:
2783
diff
changeset
|
98 for book in cs.bookmarks: |
234435584a0d
implements #632,
Marcin Kuzminski <marcin@python-works.com>
parents:
2783
diff
changeset
|
99 desc_msg.append('bookmark: %s<br/>' % book) |
234435584a0d
implements #632,
Marcin Kuzminski <marcin@python-works.com>
parents:
2783
diff
changeset
|
100 for tag in cs.tags: |
234435584a0d
implements #632,
Marcin Kuzminski <marcin@python-works.com>
parents:
2783
diff
changeset
|
101 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
|
102 diff_processor, changes = self.__changes(cs) |
2980
234435584a0d
implements #632,
Marcin Kuzminski <marcin@python-works.com>
parents:
2783
diff
changeset
|
103 # rev link |
234435584a0d
implements #632,
Marcin Kuzminski <marcin@python-works.com>
parents:
2783
diff
changeset
|
104 _url = url('changeset_home', repo_name=cs.repository.name, |
234435584a0d
implements #632,
Marcin Kuzminski <marcin@python-works.com>
parents:
2783
diff
changeset
|
105 revision=cs.raw_id, qualified=True) |
234435584a0d
implements #632,
Marcin Kuzminski <marcin@python-works.com>
parents:
2783
diff
changeset
|
106 desc_msg.append('changesest: <a href="%s">%s</a>' % (_url, cs.raw_id[:8])) |
234435584a0d
implements #632,
Marcin Kuzminski <marcin@python-works.com>
parents:
2783
diff
changeset
|
107 |
2385
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
108 desc_msg.append('<pre>') |
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
109 desc_msg.append(cs.message) |
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
110 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
|
111 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
|
112 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
|
113 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
|
114 desc_msg.append(diff_processor.as_raw()) |
2385
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
115 desc_msg.append('</pre>') |
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
116 return desc_msg |
1162
76c5b69c1b27
fixed wrong order of changes in feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
1120
diff
changeset
|
117 |
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
|
118 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
|
119 """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
|
120 |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
121 @cache_region('long_term') |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
122 def _get_feed_from_cache(key): |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
123 feed = Atom1Feed( |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
124 title=self.title % repo_name, |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
125 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
|
126 qualified=True), |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
127 description=self.description % repo_name, |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
128 language=self.language, |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
129 ttl=self.ttl |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
130 ) |
1897
0f22dedb588f
added short_id to feeds, and made it more compact
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
131 |
3018
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
132 for cs in reversed(list(c.rhodecode_repo[-self.feed_nr:])): |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
133 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
|
134 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
|
135 revision=cs.raw_id, qualified=True), |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
136 author_name=cs.author, |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
137 description=''.join(self.__get_desc(cs)), |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
138 pubdate=cs.date, |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
139 ) |
861
fd2ea6ceadc8
updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
140 |
3018
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
141 response.content_type = feed.mime_type |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
142 return feed.writeString('utf-8') |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
143 |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
144 key = repo_name + '_ATOM' |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
145 inv = CacheInvalidation.invalidate(key) |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
146 if inv is not None: |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
147 region_invalidate(_get_feed_from_cache, None, key) |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
148 CacheInvalidation.set_valid(inv.cache_key) |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
149 return _get_feed_from_cache(key) |
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
|
150 |
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
|
151 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
|
152 """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
|
153 |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
154 @cache_region('long_term') |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
155 def _get_feed_from_cache(key): |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
156 feed = Rss201rev2Feed( |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
157 title=self.title % repo_name, |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
158 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
|
159 qualified=True), |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
160 description=self.description % repo_name, |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
161 language=self.language, |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
162 ttl=self.ttl |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
163 ) |
1897
0f22dedb588f
added short_id to feeds, and made it more compact
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
164 |
3018
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
165 for cs in reversed(list(c.rhodecode_repo[-self.feed_nr:])): |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
166 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
|
167 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
|
168 revision=cs.raw_id, qualified=True), |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
169 author_name=cs.author, |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
170 description=''.join(self.__get_desc(cs)), |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
171 pubdate=cs.date, |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
172 ) |
861
fd2ea6ceadc8
updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
173 |
3018
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
174 response.content_type = feed.mime_type |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
175 return feed.writeString('utf-8') |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
176 |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
177 key = repo_name + '_RSS' |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
178 inv = CacheInvalidation.invalidate(key) |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
179 if inv is not None: |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
180 region_invalidate(_get_feed_from_cache, None, key) |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
181 CacheInvalidation.set_valid(inv.cache_key) |
023f7873ef59
added caching layer into RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2980
diff
changeset
|
182 return _get_feed_from_cache(key) |