Mercurial > kallithea
comparison rhodecode/controllers/summary.py @ 547:1e757ac98988
renamed project to rhodecode
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Wed, 06 Oct 2010 03:18:16 +0200 |
parents | pylons_app/controllers/summary.py@9bedaa073c23 |
children | b75b77ef649d |
comparison
equal
deleted
inserted
replaced
546:7c2f5e4d7bbf | 547:1e757ac98988 |
---|---|
1 #!/usr/bin/env python | |
2 # encoding: utf-8 | |
3 # summary controller for pylons | |
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> | |
5 # | |
6 # This program is free software; you can redistribute it and/or | |
7 # modify it under the terms of the GNU General Public License | |
8 # as published by the Free Software Foundation; version 2 | |
9 # of the License or (at your opinion) any later version of the license. | |
10 # | |
11 # This program is distributed in the hope that it will be useful, | |
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 # GNU General Public License for more details. | |
15 # | |
16 # You should have received a copy of the GNU General Public License | |
17 # along with this program; if not, write to the Free Software | |
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | |
19 # MA 02110-1301, USA. | |
20 """ | |
21 Created on April 18, 2010 | |
22 summary controller for pylons | |
23 @author: marcink | |
24 """ | |
25 from pylons import tmpl_context as c, request, url | |
26 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator | |
27 from rhodecode.lib.base import BaseController, render | |
28 from rhodecode.lib.utils import OrderedDict | |
29 from rhodecode.model.hg_model import HgModel | |
30 from rhodecode.model.db import Statistics | |
31 from webhelpers.paginate import Page | |
32 from rhodecode.lib.celerylib import run_task | |
33 from rhodecode.lib.celerylib.tasks import get_commits_stats | |
34 from datetime import datetime, timedelta | |
35 from time import mktime | |
36 import calendar | |
37 import logging | |
38 import json | |
39 log = logging.getLogger(__name__) | |
40 | |
41 class SummaryController(BaseController): | |
42 | |
43 @LoginRequired() | |
44 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', | |
45 'repository.admin') | |
46 def __before__(self): | |
47 super(SummaryController, self).__before__() | |
48 | |
49 def index(self): | |
50 hg_model = HgModel() | |
51 c.repo_info = hg_model.get_repo(c.repo_name) | |
52 c.repo_changesets = Page(list(c.repo_info[:10]), page=1, items_per_page=20) | |
53 e = request.environ | |
54 | |
55 uri = u'%(protocol)s://%(user)s@%(host)s%(prefix)s/%(repo_name)s' % { | |
56 'protocol': e.get('wsgi.url_scheme'), | |
57 'user':str(c.hg_app_user.username), | |
58 'host':e.get('HTTP_HOST'), | |
59 'prefix':e.get('SCRIPT_NAME'), | |
60 'repo_name':c.repo_name, } | |
61 c.clone_repo_url = uri | |
62 c.repo_tags = OrderedDict() | |
63 for name, hash in c.repo_info.tags.items()[:10]: | |
64 c.repo_tags[name] = c.repo_info.get_changeset(hash) | |
65 | |
66 c.repo_branches = OrderedDict() | |
67 for name, hash in c.repo_info.branches.items()[:10]: | |
68 c.repo_branches[name] = c.repo_info.get_changeset(hash) | |
69 | |
70 td = datetime.today() + timedelta(days=1) | |
71 y, m, d = td.year, td.month, td.day | |
72 | |
73 ts_min_y = mktime((y - 1, (td - timedelta(days=calendar.mdays[m])).month, | |
74 d, 0, 0, 0, 0, 0, 0,)) | |
75 ts_min_m = mktime((y, (td - timedelta(days=calendar.mdays[m])).month, | |
76 d, 0, 0, 0, 0, 0, 0,)) | |
77 | |
78 ts_max_y = mktime((y, m, d, 0, 0, 0, 0, 0, 0,)) | |
79 | |
80 run_task(get_commits_stats, c.repo_info.name, ts_min_y, ts_max_y) | |
81 c.ts_min = ts_min_m | |
82 c.ts_max = ts_max_y | |
83 | |
84 stats = self.sa.query(Statistics)\ | |
85 .filter(Statistics.repository == c.repo_info.dbrepo)\ | |
86 .scalar() | |
87 | |
88 | |
89 if stats and stats.languages: | |
90 lang_stats = json.loads(stats.languages) | |
91 c.commit_data = stats.commit_activity | |
92 c.overview_data = stats.commit_activity_combined | |
93 c.trending_languages = json.dumps(OrderedDict( | |
94 sorted(lang_stats.items(), reverse=True, | |
95 key=lambda k: k[1])[:2] | |
96 ) | |
97 ) | |
98 else: | |
99 c.commit_data = json.dumps({}) | |
100 c.overview_data = json.dumps([[ts_min_y, 0], [ts_max_y, 0] ]) | |
101 c.trending_languages = json.dumps({}) | |
102 | |
103 return render('summary/summary.html') | |
104 |