Mercurial > kallithea
annotate pylons_app/controllers/changelog.py @ 269:183c06406127
fixed bug in middleware config
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Mon, 07 Jun 2010 14:54:27 +0200 |
parents | 3782a6d698af |
children | 5e59f29edf66 |
rev | line source |
---|---|
252
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
1 #!/usr/bin/env python |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
2 # encoding: utf-8 |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
3 # changelog controller for pylons |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
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:
245
diff
changeset
|
5 |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
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:
245
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:
245
diff
changeset
|
8 # as published by the Free Software Foundation; version 2 |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
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:
245
diff
changeset
|
10 # |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
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:
245
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:
245
diff
changeset
|
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
14 # GNU General Public License for more details. |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
15 # |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
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:
245
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:
245
diff
changeset
|
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
19 # MA 02110-1301, USA. |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
20 """ |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
21 Created on April 21, 2010 |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
22 changelog controller for pylons |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
23 @author: marcink |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
24 """ |
245
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
213
diff
changeset
|
25 from pylons import request, session, tmpl_context as c |
192
f191f99f59c9
full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
26 from pylons_app.lib.auth import LoginRequired |
245
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
213
diff
changeset
|
27 from pylons_app.lib.base import BaseController, render |
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
213
diff
changeset
|
28 from pylons_app.model.hg_model import _full_changelog_cached |
192
f191f99f59c9
full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
29 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
|
30 import logging |
196
568f95056716
moved all cache function out to Base Controller for easier maintainance
Marcin Kuzminski <marcin@python-works.com>
parents:
192
diff
changeset
|
31 log = logging.getLogger(__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
|
32 |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
33 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
|
34 |
f191f99f59c9
full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
35 @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
|
36 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
|
37 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
|
38 |
93
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
39 def index(self): |
213 | 40 limit = 100 |
41 default = 20 | |
192
f191f99f59c9
full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
42 if request.params.get('size'): |
211
a3a7c3e03b76
version bump. Bugfix when changelog parameter was not an int. Added limit for 100 changelogs to view at once.
Marcin Kuzminski <marcin@python-works.com>
parents:
196
diff
changeset
|
43 try: |
a3a7c3e03b76
version bump. Bugfix when changelog parameter was not an int. Added limit for 100 changelogs to view at once.
Marcin Kuzminski <marcin@python-works.com>
parents:
196
diff
changeset
|
44 int_size = int(request.params.get('size')) |
a3a7c3e03b76
version bump. Bugfix when changelog parameter was not an int. Added limit for 100 changelogs to view at once.
Marcin Kuzminski <marcin@python-works.com>
parents:
196
diff
changeset
|
45 except ValueError: |
a3a7c3e03b76
version bump. Bugfix when changelog parameter was not an int. Added limit for 100 changelogs to view at once.
Marcin Kuzminski <marcin@python-works.com>
parents:
196
diff
changeset
|
46 int_size = default |
a3a7c3e03b76
version bump. Bugfix when changelog parameter was not an int. Added limit for 100 changelogs to view at once.
Marcin Kuzminski <marcin@python-works.com>
parents:
196
diff
changeset
|
47 int_size = int_size if int_size <= limit else limit |
a3a7c3e03b76
version bump. Bugfix when changelog parameter was not an int. Added limit for 100 changelogs to view at once.
Marcin Kuzminski <marcin@python-works.com>
parents:
196
diff
changeset
|
48 c.size = int_size |
192
f191f99f59c9
full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
49 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
|
50 session.save() |
142
f7218849798a
Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
51 else: |
211
a3a7c3e03b76
version bump. Bugfix when changelog parameter was not an int. Added limit for 100 changelogs to view at once.
Marcin Kuzminski <marcin@python-works.com>
parents:
196
diff
changeset
|
52 c.size = session.get('changelog_size', default) |
192
f191f99f59c9
full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
53 |
f191f99f59c9
full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
54 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
|
55 |
f191f99f59c9
full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
56 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
|
57 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
|
58 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
|
59 |
f191f99f59c9
full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
60 #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
|
61 |
f7218849798a
Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
62 return render('changelog/changelog.html') |
f7218849798a
Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
63 |
f7218849798a
Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
64 |
192
f191f99f59c9
full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
65 def _graph(self, repo, size, p): |
252
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
66 pass |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
67 # revcount = size |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
68 # if not repo.revisions:return dumps([]), 0 |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
69 # |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
70 # max_rev = repo.revisions[-1] |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
71 # offset = 1 if p == 1 else ((p - 1) * revcount) |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
72 # rev_start = repo.revisions[(-1 * offset)] |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
73 # c.bg_height = 120 |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
74 # |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
75 # revcount = min(max_rev, revcount) |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
76 # rev_end = max(0, rev_start - revcount) |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
77 # dag = graph_rev(repo.repo, rev_start, rev_end) |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
78 # |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
79 # c.dag = tree = list(colored(dag)) |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
80 # canvasheight = (len(tree) + 1) * c.bg_height - 27 |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
81 # data = [] |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
82 # for (id, type, ctx, vtx, edges) in tree: |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
83 # if type != CHANGESET: |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
84 # continue |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
85 # node = short(ctx.node()) |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
86 # age = _age(ctx.date()) |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
87 # desc = ctx.description() |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
88 # user = person(ctx.user()) |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
89 # branch = ctx.branch() |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
90 # branch = branch, repo.repo.branchtags().get(branch) == ctx.node() |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
91 # data.append((node, vtx, edges, desc, user, age, branch, ctx.tags())) |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
92 # |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
93 # c.jsdata = dumps(data) |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
94 # c.canvasheight = canvasheight |
142
f7218849798a
Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
95 |