Mercurial > kallithea
comparison rhodecode/controllers/changelog.py @ 547:1e757ac98988
renamed project to rhodecode
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Wed, 06 Oct 2010 03:18:16 +0200 |
parents | pylons_app/controllers/changelog.py@3581656180b7 |
children | 0a48c1ec04fc 101e07f82f22 |
comparison
equal
deleted
inserted
replaced
546:7c2f5e4d7bbf | 547:1e757ac98988 |
---|---|
1 #!/usr/bin/env python | |
2 # encoding: utf-8 | |
3 # changelog controller for pylons | |
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> | |
5 # | |
6 # This program is free software; you can redistribute it and/or | |
7 # modify it under the terms of the GNU General Public License | |
8 # as published by the Free Software Foundation; version 2 | |
9 # of the License or (at your opinion) any later version of the license. | |
10 # | |
11 # This program is distributed in the hope that it will be useful, | |
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 # GNU General Public License for more details. | |
15 # | |
16 # You should have received a copy of the GNU General Public License | |
17 # along with this program; if not, write to the Free Software | |
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | |
19 # MA 02110-1301, USA. | |
20 """ | |
21 Created on April 21, 2010 | |
22 changelog controller for pylons | |
23 @author: marcink | |
24 """ | |
25 from json import dumps | |
26 from mercurial.graphmod import colored, CHANGESET, revisions as graph_rev | |
27 from pylons import request, session, tmpl_context as c | |
28 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator | |
29 from rhodecode.lib.base import BaseController, render | |
30 from rhodecode.model.hg_model import HgModel | |
31 from webhelpers.paginate import Page | |
32 import logging | |
33 log = logging.getLogger(__name__) | |
34 | |
35 class ChangelogController(BaseController): | |
36 | |
37 @LoginRequired() | |
38 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', | |
39 'repository.admin') | |
40 def __before__(self): | |
41 super(ChangelogController, self).__before__() | |
42 | |
43 def index(self): | |
44 limit = 100 | |
45 default = 20 | |
46 if request.params.get('size'): | |
47 try: | |
48 int_size = int(request.params.get('size')) | |
49 except ValueError: | |
50 int_size = default | |
51 int_size = int_size if int_size <= limit else limit | |
52 c.size = int_size | |
53 session['changelog_size'] = c.size | |
54 session.save() | |
55 else: | |
56 c.size = int(session.get('changelog_size', default)) | |
57 | |
58 changesets = HgModel().get_repo(c.repo_name) | |
59 | |
60 p = int(request.params.get('page', 1)) | |
61 c.total_cs = len(changesets) | |
62 c.pagination = Page(changesets, page=p, item_count=c.total_cs, | |
63 items_per_page=c.size) | |
64 | |
65 self._graph(changesets, c.size, p) | |
66 | |
67 return render('changelog/changelog.html') | |
68 | |
69 | |
70 def _graph(self, repo, size, p): | |
71 revcount = size | |
72 if not repo.revisions:return dumps([]), 0 | |
73 | |
74 max_rev = repo.revisions[-1] | |
75 offset = 1 if p == 1 else ((p - 1) * revcount + 1) | |
76 rev_start = repo.revisions[(-1 * offset)] | |
77 | |
78 revcount = min(max_rev, revcount) | |
79 rev_end = max(0, rev_start - revcount) | |
80 dag = graph_rev(repo.repo, rev_start, rev_end) | |
81 | |
82 c.dag = tree = list(colored(dag)) | |
83 data = [] | |
84 for (id, type, ctx, vtx, edges) in tree: | |
85 if type != CHANGESET: | |
86 continue | |
87 data.append(('', vtx, edges)) | |
88 | |
89 c.jsdata = dumps(data) | |
90 |