annotate rhodecode/controllers/changelog.py @ 861:fd2ea6ceadc8 beta

updated docs on every controller
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 18 Dec 2010 16:55:28 +0100
parents 52da7cba88a6
children 07a6e8c65526 a3b2b4b4e440
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
861
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 699
diff changeset
1 # -*- coding: utf-8 -*-
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 699
diff changeset
2 """
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 699
diff changeset
3 rhodecode.controllers.changelog
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 699
diff changeset
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 699
diff changeset
5
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 699
diff changeset
6 changelog controller for rhodecode
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 699
diff changeset
7
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 699
diff changeset
8 :created_on: Apr 21, 2010
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 699
diff changeset
9 :author: marcink
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 699
diff changeset
10 :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 699
diff changeset
11 :license: GPLv3, see COPYING for more details.
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 699
diff changeset
12 """
252
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
13 # 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
14 # 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
15 # as published by the Free Software Foundation; version 2
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
16 # 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
17 #
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.
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
22 #
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
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
24 # 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
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
26 # MA 02110-1301, USA.
861
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 699
diff changeset
27
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 699
diff changeset
28 import logging
592
0a48c1ec04fc #37 fixed json imports for python2.5
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
29
608
101e07f82f22 fixes #37 python import on json
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
30 try:
101e07f82f22 fixes #37 python import on json
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
31 import json
101e07f82f22 fixes #37 python import on json
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
32 except ImportError:
101e07f82f22 fixes #37 python import on json
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
33 #python 2.5 compatibility
101e07f82f22 fixes #37 python import on json
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
34 import simplejson as json
861
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 699
diff changeset
35
318
fdf9f6ee5217 Implemented permissions into hg app, secured admin controllers, templates and repository specific controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 291
diff changeset
36 from mercurial.graphmod import colored, CHANGESET, revisions as graph_rev
fdf9f6ee5217 Implemented permissions into hg app, secured admin controllers, templates and repository specific controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 291
diff changeset
37 from pylons import request, session, tmpl_context as c
861
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 699
diff changeset
38
547
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 361
diff changeset
39 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 361
diff changeset
40 from rhodecode.lib.base import BaseController, render
691
7486da5f0628 Refactor codes for scm model
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
41 from rhodecode.model.scm import ScmModel
861
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 699
diff changeset
42
318
fdf9f6ee5217 Implemented permissions into hg app, secured admin controllers, templates and repository specific controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 291
diff changeset
43 from webhelpers.paginate import Page
861
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 699
diff changeset
44
318
fdf9f6ee5217 Implemented permissions into hg app, secured admin controllers, templates and repository specific controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 291
diff changeset
45 log = logging.getLogger(__name__)
93
aec4c0071cb3 added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
46
aec4c0071cb3 added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
47 class ChangelogController(BaseController):
636
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
48
192
f191f99f59c9 full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
49 @LoginRequired()
318
fdf9f6ee5217 Implemented permissions into hg app, secured admin controllers, templates and repository specific controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 291
diff changeset
50 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
636
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
51 'repository.admin')
93
aec4c0071cb3 added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
52 def __before__(self):
192
f191f99f59c9 full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
53 super(ChangelogController, self).__before__()
636
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
54
93
aec4c0071cb3 added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
55 def index(self):
213
Marcin Kuzminski <marcin@python-works.com>
parents: 211
diff changeset
56 limit = 100
Marcin Kuzminski <marcin@python-works.com>
parents: 211
diff changeset
57 default = 20
192
f191f99f59c9 full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
58 if request.params.get('size'):
211
a3a7c3e03b76 version bump. Bugfix when changelog parameter was not an int. Added limit for 100 changelogs to view at once.
Marcin Kuzminski <marcin@python-works.com>
parents: 196
diff changeset
59 try:
a3a7c3e03b76 version bump. Bugfix when changelog parameter was not an int. Added limit for 100 changelogs to view at once.
Marcin Kuzminski <marcin@python-works.com>
parents: 196
diff changeset
60 int_size = int(request.params.get('size'))
a3a7c3e03b76 version bump. Bugfix when changelog parameter was not an int. Added limit for 100 changelogs to view at once.
Marcin Kuzminski <marcin@python-works.com>
parents: 196
diff changeset
61 except ValueError:
a3a7c3e03b76 version bump. Bugfix when changelog parameter was not an int. Added limit for 100 changelogs to view at once.
Marcin Kuzminski <marcin@python-works.com>
parents: 196
diff changeset
62 int_size = default
636
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
63 int_size = int_size if int_size <= limit else limit
211
a3a7c3e03b76 version bump. Bugfix when changelog parameter was not an int. Added limit for 100 changelogs to view at once.
Marcin Kuzminski <marcin@python-works.com>
parents: 196
diff changeset
64 c.size = int_size
192
f191f99f59c9 full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
65 session['changelog_size'] = c.size
f191f99f59c9 full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
66 session.save()
142
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
67 else:
282
237470e64bb8 switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
68 c.size = int(session.get('changelog_size', default))
192
f191f99f59c9 full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
69
691
7486da5f0628 Refactor codes for scm model
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
70 changesets = ScmModel().get_repo(c.repo_name)
636
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
71
192
f191f99f59c9 full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
72 p = int(request.params.get('page', 1))
282
237470e64bb8 switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
73 c.total_cs = len(changesets)
237470e64bb8 switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents: 276
diff changeset
74 c.pagination = Page(changesets, page=p, item_count=c.total_cs,
192
f191f99f59c9 full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
75 items_per_page=c.size)
636
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
76
288
ab1afe7444f3 Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents: 282
diff changeset
77 self._graph(changesets, c.size, p)
636
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
78
142
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
79 return render('changelog/changelog.html')
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
80
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
81
192
f191f99f59c9 full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
82 def _graph(self, repo, size, p):
288
ab1afe7444f3 Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents: 282
diff changeset
83 revcount = size
699
52da7cba88a6 Code refactor for auth func, preparing for ldap support
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
84 if not repo.revisions or repo.alias == 'git':
52da7cba88a6 Code refactor for auth func, preparing for ldap support
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
85 c.jsdata = json.dumps([])
52da7cba88a6 Code refactor for auth func, preparing for ldap support
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
86 return
636
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
87
288
ab1afe7444f3 Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents: 282
diff changeset
88 max_rev = repo.revisions[-1]
636
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
89
322
46b7d108ea7a made graphg ticker, and fixes a paging bug caused grapgh disaligment
Marcin Kuzminski <marcin@python-works.com>
parents: 318
diff changeset
90 offset = 1 if p == 1 else ((p - 1) * revcount + 1)
636
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
91
288
ab1afe7444f3 Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents: 282
diff changeset
92 rev_start = repo.revisions[(-1 * offset)]
636
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
93
288
ab1afe7444f3 Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents: 282
diff changeset
94 revcount = min(max_rev, revcount)
ab1afe7444f3 Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents: 282
diff changeset
95 rev_end = max(0, rev_start - revcount)
ab1afe7444f3 Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents: 282
diff changeset
96 dag = graph_rev(repo.repo, rev_start, rev_end)
636
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
97
288
ab1afe7444f3 Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents: 282
diff changeset
98 c.dag = tree = list(colored(dag))
ab1afe7444f3 Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents: 282
diff changeset
99 data = []
ab1afe7444f3 Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents: 282
diff changeset
100 for (id, type, ctx, vtx, edges) in tree:
ab1afe7444f3 Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents: 282
diff changeset
101 if type != CHANGESET:
ab1afe7444f3 Initial graph release.
Marcin Kuzminski <marcin@python-works.com>
parents: 282
diff changeset
102 continue
291
a61b19036de0 code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 288
diff changeset
103 data.append(('', vtx, edges))
142
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
104
636
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
105 c.jsdata = json.dumps(data)
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
106