Mercurial > kallithea
annotate pylons_app/controllers/graph.py @ 106:a86c8de926b4
some fixes in graph tab. Little fixes in files
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sun, 25 Apr 2010 23:26:14 +0200 |
parents | aec4c0071cb3 |
children | cf32c4cc26e8 |
rev | line source |
---|---|
106
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
1 from pylons import request, response, session, tmpl_context as c, url, config, \ |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
2 app_globals as g |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
3 from pylons.controllers.util import abort, redirect |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
4 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
|
5 from pylons_app.lib.utils import get_repo_slug |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
6 from pylons_app.model.hg_model import HgModel |
93
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
7 import logging |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
8 |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
9 |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
10 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
|
11 |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
12 class GraphController(BaseController): |
106
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
13 def __before__(self): |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
14 c.repos_prefix = config['repos_name'] |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
15 c.repo_name = get_repo_slug(request) |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
16 |
93
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
17 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
|
18 # 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
|
19 hg_model = HgModel() |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
20 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
|
21 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
|
22 else: |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
23 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
|
24 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
|
25 |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
26 return render('/graph.html') |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
27 |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
28 |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
29 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
|
30 from mercurial.graphmod import revisions as graph_rev, colored, CHANGESET |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
31 from pylons_app.lib.filters import age as _age, person |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
32 from simplejson import dumps |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
33 from mercurial.node import short |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
34 from webhelpers.paginate import Page |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
35 revcount = size |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
36 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
|
37 c.pagination = Page(repo.revisions, page=p, item_count=len(repo.revisions), items_per_page=revcount) |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
38 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
|
39 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
|
40 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
|
41 bg_height = 39 |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
42 |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
43 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
|
44 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
|
45 print rev_start, rev_end |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
46 print 'x' * 100 |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
47 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
|
48 tree = list(colored(dag)) |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
49 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
|
50 data = [] |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
51 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
|
52 if type != CHANGESET: |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
53 continue |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
54 node = short(ctx.node()) |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
55 age = _age(ctx.date()) |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
56 desc = ctx.description() |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
57 user = person(ctx.user()) |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
58 branch = ctx.branch() |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
59 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
|
60 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
|
61 |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
62 return dumps(data), canvasheight |