Mercurial > kallithea
annotate pylons_app/controllers/graph.py @ 282:237470e64bb8
switched filters into webhelpers for easy of usage.
Rewrite of html to use predefined templates from branches shortlog tags, for DRY usage.
Added info messages about empty branches/tags etc.
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sun, 13 Jun 2010 23:56:16 +0200 |
parents | 3782a6d698af |
children |
rev | line source |
---|---|
252
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
1 #!/usr/bin/env python |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
2 # encoding: utf-8 |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
3 # graph controller for pylons |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
5 |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
6 # This program is free software; you can redistribute it and/or |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
7 # modify it under the terms of the GNU General Public License |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
8 # as published by the Free Software Foundation; version 2 |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
9 # 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:
191
diff
changeset
|
10 # |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
11 # This program is distributed in the hope that it will be useful, |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
14 # GNU General Public License for more details. |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
15 # |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
16 # You should have received a copy of the GNU General Public License |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
17 # along with this program; if not, write to the Free Software |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
19 # MA 02110-1301, USA. |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
20 """ |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
21 Created on April 21, 2010 |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
22 graph controller for pylons |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
23 @author: marcink |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
24 """ |
191
b68b2246e5a6
Authenticated controller with LoginRequired decorator, and cleaned __before__ (used in baseController now). fixed User for clone url with logged in session user.
Marcin Kuzminski <marcin@python-works.com>
parents:
137
diff
changeset
|
25 from mercurial.graphmod import revisions as graph_rev, colored, CHANGESET |
b68b2246e5a6
Authenticated controller with LoginRequired decorator, and cleaned __before__ (used in baseController now). fixed User for clone url with logged in session user.
Marcin Kuzminski <marcin@python-works.com>
parents:
137
diff
changeset
|
26 from mercurial.node import short |
252
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
27 from pylons import request, tmpl_context as c |
282
237470e64bb8
switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents:
252
diff
changeset
|
28 import pylons_app.lib.helpers as h |
191
b68b2246e5a6
Authenticated controller with LoginRequired decorator, and cleaned __before__ (used in baseController now). fixed User for clone url with logged in session user.
Marcin Kuzminski <marcin@python-works.com>
parents:
137
diff
changeset
|
29 from pylons_app.lib.auth import LoginRequired |
106
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
30 from pylons_app.lib.base import BaseController, render |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
31 from pylons_app.model.hg_model import HgModel |
191
b68b2246e5a6
Authenticated controller with LoginRequired decorator, and cleaned __before__ (used in baseController now). fixed User for clone url with logged in session user.
Marcin Kuzminski <marcin@python-works.com>
parents:
137
diff
changeset
|
32 from simplejson import dumps |
b68b2246e5a6
Authenticated controller with LoginRequired decorator, and cleaned __before__ (used in baseController now). fixed User for clone url with logged in session user.
Marcin Kuzminski <marcin@python-works.com>
parents:
137
diff
changeset
|
33 from webhelpers.paginate import Page |
b68b2246e5a6
Authenticated controller with LoginRequired decorator, and cleaned __before__ (used in baseController now). fixed User for clone url with logged in session user.
Marcin Kuzminski <marcin@python-works.com>
parents:
137
diff
changeset
|
34 import logging |
93
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
35 |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
36 log = logging.getLogger(__name__) |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
37 |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
38 class GraphController(BaseController): |
191
b68b2246e5a6
Authenticated controller with LoginRequired decorator, and cleaned __before__ (used in baseController now). fixed User for clone url with logged in session user.
Marcin Kuzminski <marcin@python-works.com>
parents:
137
diff
changeset
|
39 |
b68b2246e5a6
Authenticated controller with LoginRequired decorator, and cleaned __before__ (used in baseController now). fixed User for clone url with logged in session user.
Marcin Kuzminski <marcin@python-works.com>
parents:
137
diff
changeset
|
40 @LoginRequired() |
106
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
41 def __before__(self): |
191
b68b2246e5a6
Authenticated controller with LoginRequired decorator, and cleaned __before__ (used in baseController now). fixed User for clone url with logged in session user.
Marcin Kuzminski <marcin@python-works.com>
parents:
137
diff
changeset
|
42 super(GraphController, self).__before__() |
106
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
43 |
93
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
44 def index(self): |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
45 # Return a rendered template |
106
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
46 hg_model = HgModel() |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
47 if request.POST.get('size'): |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
48 c.size = int(request.params.get('size', 20)) |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
49 else: |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
50 c.size = int(request.params.get('size', 20)) |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
51 c.jsdata, c.canvasheight = self.graph(hg_model.get_repo(c.repo_name), c.size) |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
52 |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
53 return render('/graph.html') |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
54 |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
55 |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
56 def graph(self, repo, size): |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
57 revcount = size |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
58 p = int(request.params.get('page', 1)) |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
59 c.pagination = Page(repo.revisions, page=p, item_count=len(repo.revisions), items_per_page=revcount) |
137
cf32c4cc26e8
fixed graph when repository is empty moved imports to top and removed some lfet over prints
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
60 if not repo.revisions:return dumps([]), 0 |
cf32c4cc26e8
fixed graph when repository is empty moved imports to top and removed some lfet over prints
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
61 |
106
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
62 max_rev = repo.revisions[-1] |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
63 offset = 1 if p == 1 else ((p - 1) * revcount) |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
64 rev_start = repo.revisions[(-1 * offset)] |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
65 bg_height = 39 |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
66 |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
67 revcount = min(max_rev, revcount) |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
68 rev_end = max(0, rev_start - revcount) |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
69 dag = graph_rev(repo.repo, rev_start, rev_end) |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
70 tree = list(colored(dag)) |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
71 canvasheight = (len(tree) + 1) * bg_height - 27 |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
72 data = [] |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
73 for (id, type, ctx, vtx, edges) in tree: |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
74 if type != CHANGESET: |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
75 continue |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
76 node = short(ctx.node()) |
282
237470e64bb8
switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents:
252
diff
changeset
|
77 age = h.age(ctx.date()) |
106
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
78 desc = ctx.description() |
282
237470e64bb8
switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents:
252
diff
changeset
|
79 user = h.person(ctx.user()) |
106
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
80 branch = ctx.branch() |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
81 branch = branch, repo.repo.branchtags().get(branch) == ctx.node() |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
82 data.append((node, vtx, edges, desc, user, age, branch, ctx.tags())) |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
83 |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
84 return dumps(data), canvasheight |