##// END OF EJS Templates
Added missing __get_cs_or_redirect method for file history....
marcink -
r3996:267bb347 default
parent child Browse files
Show More
@@ -1,175 +1,203 b''
1 1 # -*- coding: utf-8 -*-
2 2 """
3 3 rhodecode.controllers.changelog
4 4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 5
6 6 changelog controller for rhodecode
7 7
8 8 :created_on: Apr 21, 2010
9 9 :author: marcink
10 10 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com>
11 11 :license: GPLv3, see COPYING for more details.
12 12 """
13 13 # This program is free software: you can redistribute it and/or modify
14 14 # it under the terms of the GNU General Public License as published by
15 15 # the Free Software Foundation, either version 3 of the License, or
16 16 # (at your option) any later version.
17 17 #
18 18 # This program is distributed in the hope that it will be useful,
19 19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 21 # GNU General Public License for more details.
22 22 #
23 23 # You should have received a copy of the GNU General Public License
24 24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 25
26 26 import logging
27 27 import traceback
28 28
29 29 from pylons import request, url, session, tmpl_context as c
30 30 from pylons.controllers.util import redirect
31 31 from pylons.i18n.translation import _
32 from webob.exc import HTTPNotFound, HTTPBadRequest
32 33
33 34 import rhodecode.lib.helpers as h
34 35 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
35 36 from rhodecode.lib.base import BaseRepoController, render
36 37 from rhodecode.lib.helpers import RepoPage
37 38 from rhodecode.lib.compat import json
38 39 from rhodecode.lib.graphmod import _colored, _dagwalker
39 40 from rhodecode.lib.vcs.exceptions import RepositoryError, ChangesetDoesNotExistError,\
40 41 ChangesetError, NodeDoesNotExistError, EmptyRepositoryError
41 42 from rhodecode.lib.utils2 import safe_int
42 from webob.exc import HTTPNotFound
43
43 44
44 45 log = logging.getLogger(__name__)
45 46
46 47
47 48 def _load_changelog_summary():
48 49 p = safe_int(request.GET.get('page'), 1)
49 50 size = safe_int(request.GET.get('size'), 10)
50 51
51 52 def url_generator(**kw):
52 53 return url('changelog_summary_home',
53 54 repo_name=c.rhodecode_db_repo.repo_name, size=size, **kw)
54 55
55 56 collection = c.rhodecode_repo
56 57
57 58 c.repo_changesets = RepoPage(collection, page=p,
58 59 items_per_page=size,
59 60 url=url_generator)
60 61 page_revisions = [x.raw_id for x in list(c.repo_changesets)]
61 62 c.comments = c.rhodecode_db_repo.get_comments(page_revisions)
62 63 c.statuses = c.rhodecode_db_repo.statuses(page_revisions)
63 64
64 65
65 66 class ChangelogController(BaseRepoController):
66 67
67 68 def __before__(self):
68 69 super(ChangelogController, self).__before__()
69 70 c.affected_files_cut_off = 60
70 71
72 def __get_cs_or_redirect(self, rev, repo, redirect_after=True,
73 partial=False):
74 """
75 Safe way to get changeset if error occur it redirects to changeset with
76 proper message. If partial is set then don't do redirect raise Exception
77 instead
78
79 :param rev: revision to fetch
80 :param repo: repo instance
81 """
82
83 try:
84 return c.rhodecode_repo.get_changeset(rev)
85 except EmptyRepositoryError, e:
86 if not redirect_after:
87 return None
88 h.flash(h.literal(_('There are no changesets yet')),
89 category='warning')
90 redirect(url('changelog_home', repo_name=repo.repo_name))
91
92 except RepositoryError, e:
93 log.error(traceback.format_exc())
94 h.flash(str(e), category='warning')
95 if not partial:
96 redirect(h.url('changelog_home', repo_name=repo.repo_name))
97 raise HTTPBadRequest()
98
71 99 def _graph(self, repo, revs_int, repo_size, size, p):
72 100 """
73 101 Generates a DAG graph for repo
74 102
75 103 :param repo:
76 104 :param revs_int:
77 105 :param repo_size:
78 106 :param size:
79 107 :param p:
80 108 """
81 109 if not revs_int:
82 110 c.jsdata = json.dumps([])
83 111 return
84 112
85 113 data = []
86 114 revs = revs_int
87 115
88 116 dag = _dagwalker(repo, revs, repo.alias)
89 117 dag = _colored(dag)
90 118 for (id, type, ctx, vtx, edges) in dag:
91 119 data.append(['', vtx, edges])
92 120
93 121 c.jsdata = json.dumps(data)
94 122
95 123 @LoginRequired()
96 124 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
97 125 'repository.admin')
98 126 def index(self, repo_name, revision=None, f_path=None):
99 127 limit = 100
100 128 default = 20
101 129 if request.GET.get('size'):
102 130 c.size = max(min(safe_int(request.GET.get('size')), limit), 1)
103 131 session['changelog_size'] = c.size
104 132 session.save()
105 133 else:
106 134 c.size = int(session.get('changelog_size', default))
107 135 # min size must be 1
108 136 c.size = max(c.size, 1)
109 137 p = safe_int(request.GET.get('page', 1), 1)
110 138 branch_name = request.GET.get('branch', None)
111 139 c.changelog_for_path = f_path
112 140 try:
113 141
114 142 if f_path:
115 143 log.debug('generating changelog for path %s' % f_path)
116 144 # get the history for the file !
117 145 tip_cs = c.rhodecode_repo.get_changeset()
118 146 try:
119 147 collection = tip_cs.get_file_history(f_path)
120 148 except (NodeDoesNotExistError, ChangesetError):
121 149 #this node is not present at tip !
122 150 try:
123 cs = self.__get_cs_or_redirect(revision, repo_name)
151 cs = self.__get_css_or_redirect(revision, repo_name)
124 152 collection = cs.get_file_history(f_path)
125 153 except RepositoryError, e:
126 154 h.flash(str(e), category='warning')
127 155 redirect(h.url('changelog_home', repo_name=repo_name))
128 156 collection = list(reversed(collection))
129 157 else:
130 158 collection = c.rhodecode_repo.get_changesets(start=0,
131 159 branch_name=branch_name)
132 160 c.total_cs = len(collection)
133 161
134 162 c.pagination = RepoPage(collection, page=p, item_count=c.total_cs,
135 163 items_per_page=c.size, branch=branch_name,)
136 164 collection = list(c.pagination)
137 165 page_revisions = [x.raw_id for x in c.pagination]
138 166 c.comments = c.rhodecode_db_repo.get_comments(page_revisions)
139 167 c.statuses = c.rhodecode_db_repo.statuses(page_revisions)
140 168 except (EmptyRepositoryError), e:
141 169 h.flash(str(e), category='warning')
142 170 return redirect(url('summary_home', repo_name=c.repo_name))
143 171 except (RepositoryError, ChangesetDoesNotExistError, Exception), e:
144 172 log.error(traceback.format_exc())
145 173 h.flash(str(e), category='error')
146 174 return redirect(url('changelog_home', repo_name=c.repo_name))
147 175
148 176 c.branch_name = branch_name
149 177 c.branch_filters = [('', _('All Branches'))] + \
150 178 [(k, k) for k in c.rhodecode_repo.branches.keys()]
151 179 _revs = []
152 180 if not f_path:
153 181 _revs = [x.revision for x in c.pagination]
154 182 self._graph(c.rhodecode_repo, _revs, c.total_cs, c.size, p)
155 183
156 184 return render('changelog/changelog.html')
157 185
158 186 @LoginRequired()
159 187 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
160 188 'repository.admin')
161 189 def changelog_details(self, cs):
162 190 if request.environ.get('HTTP_X_PARTIAL_XHR'):
163 191 c.cs = c.rhodecode_repo.get_changeset(cs)
164 192 return render('changelog/changelog_details.html')
165 193 raise HTTPNotFound()
166 194
167 195 @LoginRequired()
168 196 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
169 197 'repository.admin')
170 198 def changelog_summary(self, repo_name):
171 199 if request.environ.get('HTTP_X_PARTIAL_XHR'):
172 200 _load_changelog_summary()
173 201
174 202 return render('changelog/changelog_summary_data.html')
175 203 raise HTTPNotFound()
General Comments 0
You need to be logged in to leave comments. Login now