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