Mercurial > public > src > rhodecode
annotate pylons_app/controllers/graph.py @ 191:b68b2246e5a6
Authenticated controller with LoginRequired decorator, and cleaned __before__ (used in baseController now). fixed User for clone url with logged in session user.
Removed login form from admin.
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sat, 22 May 2010 01:47:07 +0200 |
parents | cf32c4cc26e8 |
children | 3782a6d698af |
rev | line source |
---|---|
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
|
1 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
|
2 from mercurial.node import short |
106
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
3 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
|
4 app_globals as g |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
5 from pylons.controllers.util import abort, redirect |
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
|
6 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
|
7 from pylons_app.lib.base import BaseController, render |
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
|
8 from pylons_app.lib.filters import age as _age, person |
106
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
9 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
|
10 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
|
11 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
|
12 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
|
13 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
|
14 |
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
|
15 |
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
|
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 |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
18 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
|
19 |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
20 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
|
21 |
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
|
22 @LoginRequired() |
106
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
23 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
|
24 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
|
25 |
93
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
26 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
|
27 # 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
|
28 hg_model = HgModel() |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
29 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
|
30 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
|
31 else: |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
32 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
|
33 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
|
34 |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
35 return render('/graph.html') |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
36 |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
37 |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
38 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
|
39 revcount = size |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
40 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
|
41 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
|
42 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
|
43 |
106
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
44 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
|
45 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
|
46 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
|
47 bg_height = 39 |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
48 |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
49 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
|
50 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
|
51 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
|
52 tree = list(colored(dag)) |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
53 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
|
54 data = [] |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
55 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
|
56 if type != CHANGESET: |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
57 continue |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
58 node = short(ctx.node()) |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
59 age = _age(ctx.date()) |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
60 desc = ctx.description() |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
61 user = person(ctx.user()) |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
62 branch = ctx.branch() |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
63 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
|
64 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
|
65 |
a86c8de926b4
some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
66 return dumps(data), canvasheight |