##// END OF EJS Templates
full changelog caching, secured changelog with LoginRequired, some minor changes in graph
marcink -
r192:f191f99f default
parent child Browse files
Show More
@@ -1,54 +1,69 b''
1 import logging
1 from beaker.cache import cache_region
2 from mercurial.graphmod import revisions as graph_rev, colored, CHANGESET
3 from mercurial.node import short
2 from pylons import request, response, session, tmpl_context as c, url, config, \
4 from pylons import request, response, session, tmpl_context as c, url, config, \
3 app_globals as g
5 app_globals as g
4 from pylons.controllers.util import abort, redirect
6 from pylons.controllers.util import abort, redirect
7 from pylons_app.lib.auth import LoginRequired
5 from pylons_app.lib.base import BaseController, render
8 from pylons_app.lib.base import BaseController, render
9 from pylons_app.lib.filters import age as _age, person
6 from pylons_app.lib.utils import get_repo_slug
10 from pylons_app.lib.utils import get_repo_slug
7 from pylons_app.model.hg_model import HgModel
11 from pylons_app.model.hg_model import HgModel
12 from simplejson import dumps
13 from webhelpers.paginate import Page
14 import logging
8
15
9 from mercurial.graphmod import revisions as graph_rev, colored, CHANGESET
10 from pylons_app.lib.filters import age as _age, person
11 from simplejson import dumps
12 from mercurial.node import short
13 from webhelpers.paginate import Page
14
16
15
17 @cache_region('long_term', 'full_changelog')
18 def _full_changelog_cached(repo_name):
19 hg_model = HgModel()
20 return list(reversed(list(hg_model.get_repo(repo_name))))
16
21
17 log = logging.getLogger(__name__)
22 log = logging.getLogger(__name__)
18
23
19 class ChangelogController(BaseController):
24 class ChangelogController(BaseController):
25
26 @LoginRequired()
20 def __before__(self):
27 def __before__(self):
21 c.repos_prefix = config['repos_name']
28 super(ChangelogController, self).__before__()
22 c.repo_name = get_repo_slug(request)
29
23
24 def index(self):
30 def index(self):
25 # Return a rendered template
26 hg_model = HgModel()
31 hg_model = HgModel()
27 if request.POST.get('size'):
32 if request.params.get('size'):
28 c.size = int(request.params.get('size', 20))
33 c.size = int(request.params['size'])
34 session['changelog_size'] = c.size
35 session.save()
29 else:
36 else:
30 c.size = int(request.params.get('size', 20))
37 c.size = session.get('changelog_size', 20)
31 c.jsdata, c.canvasheight = self.graph(hg_model.get_repo(c.repo_name), c.size)
38
39
40
41 changesets = _full_changelog_cached(c.repo_name)
42
43 p = int(request.params.get('page', 1))
44 c.pagination = Page(changesets, page=p, item_count=len(changesets),
45 items_per_page=c.size)
46
47 #self._graph(c.repo, c.size,p)
32
48
33 return render('changelog/changelog.html')
49 return render('changelog/changelog.html')
34
50
35
51
36 def graph(self, repo, size):
52 def _graph(self, repo, size, p):
37 revcount = size
53 revcount = size
38 p = int(request.params.get('page', 1))
39 c.pagination = Page(repo.revisions, page=p, item_count=len(repo.revisions), items_per_page=revcount)
40 if not repo.revisions:return dumps([]), 0
54 if not repo.revisions:return dumps([]), 0
41
55
42 max_rev = repo.revisions[-1]
56 max_rev = repo.revisions[-1]
43 offset = 1 if p == 1 else ((p - 1) * revcount)
57 offset = 1 if p == 1 else ((p - 1) * revcount)
44 rev_start = repo.revisions[(-1 * offset)]
58 rev_start = repo.revisions[(-1 * offset)]
45 bg_height = 39
59 c.bg_height = 120
46
60
47 revcount = min(max_rev, revcount)
61 revcount = min(max_rev, revcount)
48 rev_end = max(0, rev_start - revcount)
62 rev_end = max(0, rev_start - revcount)
49 dag = graph_rev(repo.repo, rev_start, rev_end)
63 dag = graph_rev(repo.repo, rev_start, rev_end)
50 tree = list(colored(dag))
64
51 canvasheight = (len(tree) + 1) * bg_height - 27
65 c.dag = tree = list(colored(dag))
66 canvasheight = (len(tree) + 1) * c.bg_height - 27
52 data = []
67 data = []
53 for (id, type, ctx, vtx, edges) in tree:
68 for (id, type, ctx, vtx, edges) in tree:
54 if type != CHANGESET:
69 if type != CHANGESET:
@@ -61,5 +76,6 b' class ChangelogController(BaseController'
61 branch = branch, repo.repo.branchtags().get(branch) == ctx.node()
76 branch = branch, repo.repo.branchtags().get(branch) == ctx.node()
62 data.append((node, vtx, edges, desc, user, age, branch, ctx.tags()))
77 data.append((node, vtx, edges, desc, user, age, branch, ctx.tags()))
63
78
64 return dumps(data), canvasheight
79 c.jsdata = dumps(data)
80 c.canvasheight = canvasheight
65
81
General Comments 0
You need to be logged in to leave comments. Login now