##// END OF EJS Templates
fixed sorting of tags and branches. Fix made in vcs.
marcink -
r389:174785aa default
parent child Browse files
Show More
@@ -1,46 +1,47 b''
1 #!/usr/bin/env python
1 #!/usr/bin/env python
2 # encoding: utf-8
2 # encoding: utf-8
3 # branches controller for pylons
3 # branches controller for pylons
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
5
5 #
6 # This program is free software; you can redistribute it and/or
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; version 2
8 # as published by the Free Software Foundation; version 2
9 # of the License or (at your opinion) any later version of the license.
9 # of the License or (at your opinion) any later version of the license.
10 #
10 #
11 # This program is distributed in the hope that it will be useful,
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
14 # GNU General Public License for more details.
15 #
15 #
16 # You should have received a copy of the GNU General Public License
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
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 # MA 02110-1301, USA.
19 # MA 02110-1301, USA.
20 """
20 """
21 Created on April 21, 2010
21 Created on April 21, 2010
22 branches controller for pylons
22 branches controller for pylons
23 @author: marcink
23 @author: marcink
24 """
24 """
25 from pylons import tmpl_context as c, request
25 from pylons import tmpl_context as c
26 from pylons_app.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
26 from pylons_app.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
27 from pylons_app.lib.base import BaseController, render
27 from pylons_app.lib.base import BaseController, render
28 from pylons_app.lib.utils import OrderedDict
28 from pylons_app.model.hg_model import HgModel
29 from pylons_app.model.hg_model import HgModel
29 import logging
30 import logging
30 log = logging.getLogger(__name__)
31 log = logging.getLogger(__name__)
31
32
32 class BranchesController(BaseController):
33 class BranchesController(BaseController):
33
34
34 @LoginRequired()
35 @LoginRequired()
35 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', 'repository.admin')
36 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', 'repository.admin')
36 def __before__(self):
37 def __before__(self):
37 super(BranchesController, self).__before__()
38 super(BranchesController, self).__before__()
38
39
39 def index(self):
40 def index(self):
40 hg_model = HgModel()
41 hg_model = HgModel()
41 c.repo_info = hg_model.get_repo(c.repo_name)
42 c.repo_info = hg_model.get_repo(c.repo_name)
42 c.repo_branches = {}
43 c.repo_branches = OrderedDict()
43 for name, hash_ in c.repo_info.branches.items():
44 for name, hash_ in c.repo_info.branches.items():
44 c.repo_branches[name] = c.repo_info.get_changeset(hash_)
45 c.repo_branches[name] = c.repo_info.get_changeset(hash_)
45
46
46 return render('branches/branches.html')
47 return render('branches/branches.html')
@@ -1,121 +1,121 b''
1 #!/usr/bin/env python
1 #!/usr/bin/env python
2 # encoding: utf-8
2 # encoding: utf-8
3 # summary controller for pylons
3 # summary controller for pylons
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
5 #
5 #
6 # This program is free software; you can redistribute it and/or
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; version 2
8 # as published by the Free Software Foundation; version 2
9 # of the License or (at your opinion) any later version of the license.
9 # of the License or (at your opinion) any later version of the license.
10 #
10 #
11 # This program is distributed in the hope that it will be useful,
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
14 # GNU General Public License for more details.
15 #
15 #
16 # You should have received a copy of the GNU General Public License
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
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 # MA 02110-1301, USA.
19 # MA 02110-1301, USA.
20 """
20 """
21 Created on April 18, 2010
21 Created on April 18, 2010
22 summary controller for pylons
22 summary controller for pylons
23 @author: marcink
23 @author: marcink
24 """
24 """
25 from datetime import datetime, timedelta
25 from datetime import datetime, timedelta
26 from pylons import tmpl_context as c, request
26 from pylons import tmpl_context as c, request
27 from pylons_app.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
27 from pylons_app.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
28 from pylons_app.lib.base import BaseController, render
28 from pylons_app.lib.base import BaseController, render
29 from pylons_app.lib.helpers import person
29 from pylons_app.lib.helpers import person
30 from pylons_app.lib.utils import OrderedDict
30 from pylons_app.lib.utils import OrderedDict
31 from pylons_app.model.hg_model import HgModel
31 from pylons_app.model.hg_model import HgModel
32 from time import mktime
32 from time import mktime
33 from webhelpers.paginate import Page
33 from webhelpers.paginate import Page
34 import calendar
34 import calendar
35 import logging
35 import logging
36
36
37 log = logging.getLogger(__name__)
37 log = logging.getLogger(__name__)
38
38
39 class SummaryController(BaseController):
39 class SummaryController(BaseController):
40
40
41 @LoginRequired()
41 @LoginRequired()
42 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
42 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
43 'repository.admin')
43 'repository.admin')
44 def __before__(self):
44 def __before__(self):
45 super(SummaryController, self).__before__()
45 super(SummaryController, self).__before__()
46
46
47 def index(self):
47 def index(self):
48 hg_model = HgModel()
48 hg_model = HgModel()
49 c.repo_info = hg_model.get_repo(c.repo_name)
49 c.repo_info = hg_model.get_repo(c.repo_name)
50 c.repo_changesets = Page(list(c.repo_info[:10]), page=1, items_per_page=20)
50 c.repo_changesets = Page(list(c.repo_info[:10]), page=1, items_per_page=20)
51 e = request.environ
51 e = request.environ
52 uri = u'%(protocol)s://%(user)s@%(host)s/%(repo_name)s' % {
52 uri = u'%(protocol)s://%(user)s@%(host)s/%(repo_name)s' % {
53 'protocol': e.get('wsgi.url_scheme'),
53 'protocol': e.get('wsgi.url_scheme'),
54 'user':str(c.hg_app_user.username),
54 'user':str(c.hg_app_user.username),
55 'host':e.get('HTTP_HOST'),
55 'host':e.get('HTTP_HOST'),
56 'repo_name':c.repo_name, }
56 'repo_name':c.repo_name, }
57 c.clone_repo_url = uri
57 c.clone_repo_url = uri
58 c.repo_tags = {}
58 c.repo_tags = OrderedDict()
59 for name, hash in c.repo_info.tags.items()[:10]:
59 for name, hash in c.repo_info.tags.items()[:10]:
60 c.repo_tags[name] = c.repo_info.get_changeset(hash)
60 c.repo_tags[name] = c.repo_info.get_changeset(hash)
61
61
62 c.repo_branches = {}
62 c.repo_branches = OrderedDict()
63 for name, hash in c.repo_info.branches.items()[:10]:
63 for name, hash in c.repo_info.branches.items()[:10]:
64 c.repo_branches[name] = c.repo_info.get_changeset(hash)
64 c.repo_branches[name] = c.repo_info.get_changeset(hash)
65
65
66 c.commit_data = self.__get_commit_stats(c.repo_info)
66 c.commit_data = self.__get_commit_stats(c.repo_info)
67
67
68 return render('summary/summary.html')
68 return render('summary/summary.html')
69
69
70
70
71
71
72 def __get_commit_stats(self, repo):
72 def __get_commit_stats(self, repo):
73 aggregate = OrderedDict()
73 aggregate = OrderedDict()
74
74
75 #graph range
75 #graph range
76 td = datetime.today()
76 td = datetime.today()
77 y = td.year
77 y = td.year
78 m = td.month
78 m = td.month
79 d = td.day
79 d = td.day
80 c.ts_min = mktime((y, (td - timedelta(days=calendar.mdays[m] - 1)).month, d, 0, 0, 0, 0, 0, 0,))
80 c.ts_min = mktime((y, (td - timedelta(days=calendar.mdays[m] - 1)).month, d, 0, 0, 0, 0, 0, 0,))
81 c.ts_max = mktime((y, m, d, 0, 0, 0, 0, 0, 0,))
81 c.ts_max = mktime((y, m, d, 0, 0, 0, 0, 0, 0,))
82
82
83
83
84 def author_key_cleaner(k):
84 def author_key_cleaner(k):
85 k = person(k)
85 k = person(k)
86 return k
86 return k
87
87
88 for cs in repo:
88 for cs in repo:
89 k = '%s-%s-%s' % (cs.date.timetuple()[0], cs.date.timetuple()[1],
89 k = '%s-%s-%s' % (cs.date.timetuple()[0], cs.date.timetuple()[1],
90 cs.date.timetuple()[2])
90 cs.date.timetuple()[2])
91 timetupple = [int(x) for x in k.split('-')]
91 timetupple = [int(x) for x in k.split('-')]
92 timetupple.extend([0 for _ in xrange(6)])
92 timetupple.extend([0 for _ in xrange(6)])
93 k = mktime(timetupple)
93 k = mktime(timetupple)
94 if aggregate.has_key(author_key_cleaner(cs.author)):
94 if aggregate.has_key(author_key_cleaner(cs.author)):
95 if aggregate[author_key_cleaner(cs.author)].has_key(k):
95 if aggregate[author_key_cleaner(cs.author)].has_key(k):
96 aggregate[author_key_cleaner(cs.author)][k] += 1
96 aggregate[author_key_cleaner(cs.author)][k] += 1
97 else:
97 else:
98 #aggregate[author_key_cleaner(cs.author)].update(dates_range)
98 #aggregate[author_key_cleaner(cs.author)].update(dates_range)
99 if k >= c.ts_min and k <= c.ts_max:
99 if k >= c.ts_min and k <= c.ts_max:
100 aggregate[author_key_cleaner(cs.author)][k] = 1
100 aggregate[author_key_cleaner(cs.author)][k] = 1
101 else:
101 else:
102 if k >= c.ts_min and k <= c.ts_max:
102 if k >= c.ts_min and k <= c.ts_max:
103 aggregate[author_key_cleaner(cs.author)] = OrderedDict()
103 aggregate[author_key_cleaner(cs.author)] = OrderedDict()
104 #aggregate[author_key_cleaner(cs.author)].update(dates_range)
104 #aggregate[author_key_cleaner(cs.author)].update(dates_range)
105 aggregate[author_key_cleaner(cs.author)][k] = 1
105 aggregate[author_key_cleaner(cs.author)][k] = 1
106
106
107 d = ''
107 d = ''
108 tmpl0 = u""""%s":%s"""
108 tmpl0 = u""""%s":%s"""
109 tmpl1 = u"""{label:"%s",data:%s},"""
109 tmpl1 = u"""{label:"%s",data:%s},"""
110 for author in aggregate:
110 for author in aggregate:
111 d += tmpl0 % (author.decode('utf8'),
111 d += tmpl0 % (author.decode('utf8'),
112 tmpl1 \
112 tmpl1 \
113 % (author.decode('utf8'),
113 % (author.decode('utf8'),
114 [[x, aggregate[author][x]] for x in aggregate[author]]))
114 [[x, aggregate[author][x]] for x in aggregate[author]]))
115 if d == '':
115 if d == '':
116 d = '"%s":{label:"%s",data:[[0,0],]}' \
116 d = '"%s":{label:"%s",data:[[0,0],]}' \
117 % (author_key_cleaner(repo.contact),
117 % (author_key_cleaner(repo.contact),
118 author_key_cleaner(repo.contact))
118 author_key_cleaner(repo.contact))
119 return d
119 return d
120
120
121
121
@@ -1,46 +1,47 b''
1 #!/usr/bin/env python
1 #!/usr/bin/env python
2 # encoding: utf-8
2 # encoding: utf-8
3 # tags controller for pylons
3 # tags controller for pylons
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
5
5 #
6 # This program is free software; you can redistribute it and/or
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; version 2
8 # as published by the Free Software Foundation; version 2
9 # of the License or (at your opinion) any later version of the license.
9 # of the License or (at your opinion) any later version of the license.
10 #
10 #
11 # This program is distributed in the hope that it will be useful,
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
14 # GNU General Public License for more details.
15 #
15 #
16 # You should have received a copy of the GNU General Public License
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
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 # MA 02110-1301, USA.
19 # MA 02110-1301, USA.
20 """
20 """
21 Created on April 21, 2010
21 Created on April 21, 2010
22 tags controller for pylons
22 tags controller for pylons
23 @author: marcink
23 @author: marcink
24 """
24 """
25 from pylons import tmpl_context as c, request
25 from pylons import tmpl_context as c
26 from pylons_app.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
26 from pylons_app.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
27 from pylons_app.lib.base import BaseController, render
27 from pylons_app.lib.base import BaseController, render
28 from pylons_app.lib.utils import OrderedDict
28 from pylons_app.model.hg_model import HgModel
29 from pylons_app.model.hg_model import HgModel
29 import logging
30 import logging
30 log = logging.getLogger(__name__)
31 log = logging.getLogger(__name__)
31
32
32 class TagsController(BaseController):
33 class TagsController(BaseController):
33
34
34 @LoginRequired()
35 @LoginRequired()
35 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', 'repository.admin')
36 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', 'repository.admin')
36 def __before__(self):
37 def __before__(self):
37 super(TagsController, self).__before__()
38 super(TagsController, self).__before__()
38
39
39 def index(self):
40 def index(self):
40 hg_model = HgModel()
41 hg_model = HgModel()
41 c.repo_info = hg_model.get_repo(c.repo_name)
42 c.repo_info = hg_model.get_repo(c.repo_name)
42 c.repo_tags = {}
43 c.repo_tags = OrderedDict()
43 for name, hash in c.repo_info.tags.items():
44 for name, hash_ in c.repo_info.tags.items():
44 c.repo_tags[name] = c.repo_info.get_changeset(hash)
45 c.repo_tags[name] = c.repo_info.get_changeset(hash_)
45
46
46 return render('tags/tags.html')
47 return render('tags/tags.html')
General Comments 0
You need to be logged in to leave comments. Login now