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