annotate pylons_app/controllers/changelog.py @ 192:f191f99f59c9

full changelog caching, secured changelog with LoginRequired, some minor changes in graph
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 22 May 2010 01:58:36 +0200
parents f7218849798a
children 568f95056716
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
192
f191f99f59c9 full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
1 from beaker.cache import cache_region
f191f99f59c9 full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
2 from mercurial.graphmod import revisions as graph_rev, colored, CHANGESET
f191f99f59c9 full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
3 from mercurial.node import short
142
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
4 from pylons import request, response, session, tmpl_context as c, url, config, \
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
5 app_globals as g
93
aec4c0071cb3 added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
6 from pylons.controllers.util import abort, redirect
192
f191f99f59c9 full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
7 from pylons_app.lib.auth import LoginRequired
93
aec4c0071cb3 added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
8 from pylons_app.lib.base import BaseController, render
192
f191f99f59c9 full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
9 from pylons_app.lib.filters import age as _age, person
93
aec4c0071cb3 added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
10 from pylons_app.lib.utils import get_repo_slug
aec4c0071cb3 added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
11 from pylons_app.model.hg_model import HgModel
192
f191f99f59c9 full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
12 from simplejson import dumps
f191f99f59c9 full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
13 from webhelpers.paginate import Page
f191f99f59c9 full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
14 import logging
142
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
15
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
16
192
f191f99f59c9 full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
17 @cache_region('long_term', 'full_changelog')
f191f99f59c9 full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
18 def _full_changelog_cached(repo_name):
f191f99f59c9 full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
19 hg_model = HgModel()
f191f99f59c9 full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
20 return list(reversed(list(hg_model.get_repo(repo_name))))
93
aec4c0071cb3 added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
21
aec4c0071cb3 added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
22 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
23
aec4c0071cb3 added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
24 class ChangelogController(BaseController):
192
f191f99f59c9 full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
25
f191f99f59c9 full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
26 @LoginRequired()
93
aec4c0071cb3 added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
27 def __before__(self):
192
f191f99f59c9 full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
28 super(ChangelogController, self).__before__()
f191f99f59c9 full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
29
93
aec4c0071cb3 added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
30 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
31 hg_model = HgModel()
192
f191f99f59c9 full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
32 if request.params.get('size'):
f191f99f59c9 full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
33 c.size = int(request.params['size'])
f191f99f59c9 full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
34 session['changelog_size'] = c.size
f191f99f59c9 full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
35 session.save()
142
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
36 else:
192
f191f99f59c9 full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
37 c.size = session.get('changelog_size', 20)
f191f99f59c9 full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
38
f191f99f59c9 full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
39
f191f99f59c9 full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
40
f191f99f59c9 full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
41 changesets = _full_changelog_cached(c.repo_name)
f191f99f59c9 full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
42
f191f99f59c9 full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
43 p = int(request.params.get('page', 1))
f191f99f59c9 full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
44 c.pagination = Page(changesets, page=p, item_count=len(changesets),
f191f99f59c9 full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
45 items_per_page=c.size)
f191f99f59c9 full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
46
f191f99f59c9 full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
47 #self._graph(c.repo, c.size,p)
142
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
48
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
49 return render('changelog/changelog.html')
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
50
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
51
192
f191f99f59c9 full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
52 def _graph(self, repo, size, p):
142
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
53 revcount = size
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
54 if not repo.revisions:return dumps([]), 0
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
55
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
56 max_rev = repo.revisions[-1]
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
57 offset = 1 if p == 1 else ((p - 1) * revcount)
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
58 rev_start = repo.revisions[(-1 * offset)]
192
f191f99f59c9 full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
59 c.bg_height = 120
142
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
60
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
61 revcount = min(max_rev, revcount)
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
62 rev_end = max(0, rev_start - revcount)
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
63 dag = graph_rev(repo.repo, rev_start, rev_end)
192
f191f99f59c9 full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
64
f191f99f59c9 full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
65 c.dag = tree = list(colored(dag))
f191f99f59c9 full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
66 canvasheight = (len(tree) + 1) * c.bg_height - 27
142
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
67 data = []
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
68 for (id, type, ctx, vtx, edges) in tree:
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
69 if type != CHANGESET:
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
70 continue
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
71 node = short(ctx.node())
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
72 age = _age(ctx.date())
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
73 desc = ctx.description()
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
74 user = person(ctx.user())
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
75 branch = ctx.branch()
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
76 branch = branch, repo.repo.branchtags().get(branch) == ctx.node()
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
77 data.append((node, vtx, edges, desc, user, age, branch, ctx.tags()))
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
78
192
f191f99f59c9 full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
79 c.jsdata = dumps(data)
f191f99f59c9 full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
80 c.canvasheight = canvasheight
142
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 127
diff changeset
81