##// END OF EJS Templates
fixes #37 python import on json
marcink -
r608:101e07f8 default
parent child Browse files
Show More
@@ -1,90 +1,94 b''
1 1 #!/usr/bin/env python
2 2 # encoding: utf-8
3 3 # changelog controller for pylons
4 4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
5 5 #
6 6 # This program is free software; you can redistribute it and/or
7 7 # modify it under the terms of the GNU General Public License
8 8 # as published by the Free Software Foundation; version 2
9 9 # of the License or (at your opinion) any later version of the license.
10 10 #
11 11 # This program is distributed in the hope that it will be useful,
12 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 14 # GNU General Public License for more details.
15 15 #
16 16 # You should have received a copy of the GNU General Public License
17 17 # along with this program; if not, write to the Free Software
18 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 19 # MA 02110-1301, USA.
20 20 """
21 21 Created on April 21, 2010
22 22 changelog controller for pylons
23 23 @author: marcink
24 24 """
25 from json import dumps
25 try:
26 import json
27 except ImportError:
28 #python 2.5 compatibility
29 import simplejson as json
26 30 from mercurial.graphmod import colored, CHANGESET, revisions as graph_rev
27 31 from pylons import request, session, tmpl_context as c
28 32 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
29 33 from rhodecode.lib.base import BaseController, render
30 34 from rhodecode.model.hg_model import HgModel
31 35 from webhelpers.paginate import Page
32 36 import logging
33 37 log = logging.getLogger(__name__)
34 38
35 39 class ChangelogController(BaseController):
36 40
37 41 @LoginRequired()
38 42 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
39 43 'repository.admin')
40 44 def __before__(self):
41 45 super(ChangelogController, self).__before__()
42 46
43 47 def index(self):
44 48 limit = 100
45 49 default = 20
46 50 if request.params.get('size'):
47 51 try:
48 52 int_size = int(request.params.get('size'))
49 53 except ValueError:
50 54 int_size = default
51 55 int_size = int_size if int_size <= limit else limit
52 56 c.size = int_size
53 57 session['changelog_size'] = c.size
54 58 session.save()
55 59 else:
56 60 c.size = int(session.get('changelog_size', default))
57 61
58 62 changesets = HgModel().get_repo(c.repo_name)
59 63
60 64 p = int(request.params.get('page', 1))
61 65 c.total_cs = len(changesets)
62 66 c.pagination = Page(changesets, page=p, item_count=c.total_cs,
63 67 items_per_page=c.size)
64 68
65 69 self._graph(changesets, c.size, p)
66 70
67 71 return render('changelog/changelog.html')
68 72
69 73
70 74 def _graph(self, repo, size, p):
71 75 revcount = size
72 if not repo.revisions:return dumps([]), 0
76 if not repo.revisions:return json.dumps([]), 0
73 77
74 78 max_rev = repo.revisions[-1]
75 79 offset = 1 if p == 1 else ((p - 1) * revcount + 1)
76 80 rev_start = repo.revisions[(-1 * offset)]
77 81
78 82 revcount = min(max_rev, revcount)
79 83 rev_end = max(0, rev_start - revcount)
80 84 dag = graph_rev(repo.repo, rev_start, rev_end)
81 85
82 86 c.dag = tree = list(colored(dag))
83 87 data = []
84 88 for (id, type, ctx, vtx, edges) in tree:
85 89 if type != CHANGESET:
86 90 continue
87 91 data.append(('', vtx, edges))
88 92
89 c.jsdata = dumps(data)
93 c.jsdata = json.dumps(data)
90 94
@@ -1,104 +1,108 b''
1 1 #!/usr/bin/env python
2 2 # encoding: utf-8
3 3 # summary controller for pylons
4 4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
5 5 #
6 6 # This program is free software; you can redistribute it and/or
7 7 # modify it under the terms of the GNU General Public License
8 8 # as published by the Free Software Foundation; version 2
9 9 # of the License or (at your opinion) any later version of the license.
10 10 #
11 11 # This program is distributed in the hope that it will be useful,
12 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 14 # GNU General Public License for more details.
15 15 #
16 16 # You should have received a copy of the GNU General Public License
17 17 # along with this program; if not, write to the Free Software
18 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 19 # MA 02110-1301, USA.
20 20 """
21 21 Created on April 18, 2010
22 22 summary controller for pylons
23 23 @author: marcink
24 24 """
25 25 from pylons import tmpl_context as c, request, url
26 26 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
27 27 from rhodecode.lib.base import BaseController, render
28 28 from rhodecode.lib.utils import OrderedDict
29 29 from rhodecode.model.hg_model import HgModel
30 30 from rhodecode.model.db import Statistics
31 31 from webhelpers.paginate import Page
32 32 from rhodecode.lib.celerylib import run_task
33 33 from rhodecode.lib.celerylib.tasks import get_commits_stats
34 34 from datetime import datetime, timedelta
35 35 from time import mktime
36 36 import calendar
37 37 import logging
38 import json
38 try:
39 import json
40 except ImportError:
41 #python 2.5 compatibility
42 import simplejson as json
39 43 log = logging.getLogger(__name__)
40 44
41 45 class SummaryController(BaseController):
42 46
43 47 @LoginRequired()
44 48 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
45 49 'repository.admin')
46 50 def __before__(self):
47 51 super(SummaryController, self).__before__()
48 52
49 53 def index(self):
50 54 hg_model = HgModel()
51 55 c.repo_info = hg_model.get_repo(c.repo_name)
52 56 c.repo_changesets = Page(list(c.repo_info[:10]), page=1, items_per_page=20)
53 57 e = request.environ
54 58
55 59 uri = u'%(protocol)s://%(user)s@%(host)s%(prefix)s/%(repo_name)s' % {
56 60 'protocol': e.get('wsgi.url_scheme'),
57 61 'user':str(c.rhodecode_user.username),
58 62 'host':e.get('HTTP_HOST'),
59 63 'prefix':e.get('SCRIPT_NAME'),
60 64 'repo_name':c.repo_name, }
61 65 c.clone_repo_url = uri
62 66 c.repo_tags = OrderedDict()
63 67 for name, hash in c.repo_info.tags.items()[:10]:
64 68 c.repo_tags[name] = c.repo_info.get_changeset(hash)
65 69
66 70 c.repo_branches = OrderedDict()
67 71 for name, hash in c.repo_info.branches.items()[:10]:
68 72 c.repo_branches[name] = c.repo_info.get_changeset(hash)
69 73
70 74 td = datetime.today() + timedelta(days=1)
71 75 y, m, d = td.year, td.month, td.day
72 76
73 77 ts_min_y = mktime((y - 1, (td - timedelta(days=calendar.mdays[m])).month,
74 78 d, 0, 0, 0, 0, 0, 0,))
75 79 ts_min_m = mktime((y, (td - timedelta(days=calendar.mdays[m])).month,
76 80 d, 0, 0, 0, 0, 0, 0,))
77 81
78 82 ts_max_y = mktime((y, m, d, 0, 0, 0, 0, 0, 0,))
79 83
80 84 run_task(get_commits_stats, c.repo_info.name, ts_min_y, ts_max_y)
81 85 c.ts_min = ts_min_m
82 86 c.ts_max = ts_max_y
83 87
84 88 stats = self.sa.query(Statistics)\
85 89 .filter(Statistics.repository == c.repo_info.dbrepo)\
86 90 .scalar()
87 91
88 92
89 93 if stats and stats.languages:
90 94 lang_stats = json.loads(stats.languages)
91 95 c.commit_data = stats.commit_activity
92 96 c.overview_data = stats.commit_activity_combined
93 97 c.trending_languages = json.dumps(OrderedDict(
94 98 sorted(lang_stats.items(), reverse=True,
95 99 key=lambda k: k[1])[:2]
96 100 )
97 101 )
98 102 else:
99 103 c.commit_data = json.dumps({})
100 104 c.overview_data = json.dumps([[ts_min_y, 0], [ts_max_y, 0] ])
101 105 c.trending_languages = json.dumps({})
102 106
103 107 return render('summary/summary.html')
104 108
General Comments 0
You need to be logged in to leave comments. Login now