annotate rhodecode/controllers/admin/repos_groups.py @ 1345:3bce31f026b8 beta

#47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods. Added new db unique key for Group
author Marcin Kuzminski <marcin@python-works.com>
date Mon, 23 May 2011 02:22:00 +0200
parents a04fe5986109
children cf78d302d441
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1171
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1 import logging
1345
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
2 import traceback
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
3 import formencode
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
4
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
5 from formencode import htmlfill
1193
523382549c45 Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents: 1171
diff changeset
6 from operator import itemgetter
1171
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
7
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
8 from pylons import request, response, session, tmpl_context as c, url
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
9 from pylons.controllers.util import abort, redirect
1345
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
10 from pylons.i18n.translation import _
1171
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
11
1345
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
12 from rhodecode.lib import helpers as h
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
13 from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator, \
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
14 HasPermissionAnyDecorator
1171
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
15 from rhodecode.lib.base import BaseController, render
1193
523382549c45 Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents: 1171
diff changeset
16 from rhodecode.model.db import Group
1345
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
17 from rhodecode.model.repos_group import ReposGroupModel
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
18 from rhodecode.model.forms import ReposGroupForm
1171
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
19
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
20 log = logging.getLogger(__name__)
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
21
1245
5f2fbab7c429 PEP8ify - controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 1193
diff changeset
22
1171
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
23 class ReposGroupsController(BaseController):
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
24 """REST Controller styled on the Atom Publishing Protocol"""
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
25 # To properly map this controller, ensure your config/routing.py
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
26 # file has a resource setup:
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
27 # map.resource('repos_group', 'repos_groups')
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
28
1345
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
29 def __load_defaults(self):
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
30
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
31 c.repo_groups = [('', '')]
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
32 parents_link = lambda k: h.literal('&raquo;'.join(
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
33 map(lambda k: k.group_name,
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
34 k.parents + [k])
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
35 )
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
36 )
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
37
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
38 c.repo_groups.extend([(x.group_id, parents_link(x)) for \
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
39 x in self.sa.query(Group).all()])
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
40
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
41 c.repo_groups = sorted(c.repo_groups,
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
42 key=lambda t: t[1].split('&raquo;')[0])
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
43 c.repo_groups_choices = map(lambda k: unicode(k[0]), c.repo_groups)
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
44
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
45 @LoginRequired()
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
46 def __before__(self):
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
47 super(ReposGroupsController, self).__before__()
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
48
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
49 @HasPermissionAnyDecorator('hg.admin')
1171
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
50 def index(self, format='html'):
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
51 """GET /repos_groups: All items in the collection"""
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
52 # url('repos_groups')
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
53
1345
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
54 sk = lambda g:g.parents[0].group_name if g.parents else g.group_name
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
55 c.groups = sorted(Group.query().all(), key=sk)
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
56 return render('admin/repos_groups/repos_groups_show.html')
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
57
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
58 @HasPermissionAnyDecorator('hg.admin')
1171
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
59 def create(self):
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
60 """POST /repos_groups: Create a new item"""
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
61 # url('repos_groups')
1345
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
62 self.__load_defaults()
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
63 repos_group_model = ReposGroupModel()
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
64 repos_group_form = ReposGroupForm(available_groups=
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
65 c.repo_groups_choices)()
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
66 try:
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
67 form_result = repos_group_form.to_python(dict(request.POST))
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
68 repos_group_model.create(form_result)
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
69 h.flash(_('created repos group %s') \
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
70 % form_result['repos_group_name'], category='success')
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
71 #TODO: in futureaction_logger(, '', '', '', self.sa)
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
72 except formencode.Invalid, errors:
1171
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
73
1345
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
74 return htmlfill.render(
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
75 render('admin/repos_groups/repos_groups_add.html'),
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
76 defaults=errors.value,
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
77 errors=errors.error_dict or {},
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
78 prefix_error=False,
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
79 encoding="UTF-8")
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
80 except Exception:
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
81 log.error(traceback.format_exc())
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
82 h.flash(_('error occurred during creation of repos group %s') \
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
83 % request.POST.get('repos_group_name'), category='error')
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
84
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
85 return redirect(url('repos_groups'))
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
86
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
87
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
88 @HasPermissionAnyDecorator('hg.admin')
1171
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
89 def new(self, format='html'):
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
90 """GET /repos_groups/new: Form to create a new item"""
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
91 # url('new_repos_group')
1345
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
92 self.__load_defaults()
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
93 return render('admin/repos_groups/repos_groups_add.html')
1171
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
94
1345
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
95 @HasPermissionAnyDecorator('hg.admin')
1171
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
96 def update(self, id):
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
97 """PUT /repos_groups/id: Update an existing item"""
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
98 # Forms posted to this method should contain a hidden field:
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
99 # <input type="hidden" name="_method" value="PUT" />
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
100 # Or using helpers:
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
101 # h.form(url('repos_group', id=ID),
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
102 # method='put')
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
103 # url('repos_group', id=ID)
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
104
1345
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
105 @HasPermissionAnyDecorator('hg.admin')
1171
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
106 def delete(self, id):
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
107 """DELETE /repos_groups/id: Delete an existing item"""
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
108 # Forms posted to this method should contain a hidden field:
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
109 # <input type="hidden" name="_method" value="DELETE" />
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
110 # Or using helpers:
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
111 # h.form(url('repos_group', id=ID),
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
112 # method='delete')
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
113 # url('repos_group', id=ID)
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
114
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
115 def show(self, id, format='html'):
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
116 """GET /repos_groups/id: Show a specific item"""
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
117 # url('repos_group', id=ID)
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
118
1193
523382549c45 Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents: 1171
diff changeset
119 c.group = Group.get(id)
523382549c45 Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents: 1171
diff changeset
120 if c.group:
1343
a04fe5986109 #47 implemented basic gui for browsing repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
121 c.group_repos = c.group.repositories.all()
1193
523382549c45 Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents: 1171
diff changeset
122 else:
523382549c45 Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents: 1171
diff changeset
123 return redirect(url('repos_group'))
523382549c45 Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents: 1171
diff changeset
124
523382549c45 Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents: 1171
diff changeset
125 sortables = ['name', 'description', 'last_change', 'tip', 'owner']
523382549c45 Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents: 1171
diff changeset
126 current_sort = request.GET.get('sort', 'name')
523382549c45 Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents: 1171
diff changeset
127 current_sort_slug = current_sort.replace('-', '')
523382549c45 Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents: 1171
diff changeset
128
523382549c45 Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents: 1171
diff changeset
129 if current_sort_slug not in sortables:
523382549c45 Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents: 1171
diff changeset
130 c.sort_by = 'name'
523382549c45 Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents: 1171
diff changeset
131 current_sort_slug = c.sort_by
523382549c45 Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents: 1171
diff changeset
132 else:
523382549c45 Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents: 1171
diff changeset
133 c.sort_by = current_sort
523382549c45 Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents: 1171
diff changeset
134 c.sort_slug = current_sort_slug
523382549c45 Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents: 1171
diff changeset
135
523382549c45 Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents: 1171
diff changeset
136 sort_key = current_sort_slug + '_sort'
523382549c45 Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents: 1171
diff changeset
137
523382549c45 Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents: 1171
diff changeset
138 #overwrite our cached list with current filter
523382549c45 Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents: 1171
diff changeset
139 gr_filter = [r.repo_name for r in c.group_repos]
523382549c45 Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents: 1171
diff changeset
140 c.cached_repo_list = self.scm_model.get_repos(all_repos=gr_filter)
523382549c45 Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents: 1171
diff changeset
141
523382549c45 Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents: 1171
diff changeset
142 if c.sort_by.startswith('-'):
523382549c45 Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents: 1171
diff changeset
143 c.repos_list = sorted(c.cached_repo_list, key=itemgetter(sort_key),
523382549c45 Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents: 1171
diff changeset
144 reverse=True)
523382549c45 Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents: 1171
diff changeset
145 else:
523382549c45 Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents: 1171
diff changeset
146 c.repos_list = sorted(c.cached_repo_list, key=itemgetter(sort_key),
523382549c45 Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents: 1171
diff changeset
147 reverse=False)
523382549c45 Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents: 1171
diff changeset
148
523382549c45 Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents: 1171
diff changeset
149 c.repo_cnt = len(c.repos_list)
523382549c45 Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents: 1171
diff changeset
150
1343
a04fe5986109 #47 implemented basic gui for browsing repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
151
a04fe5986109 #47 implemented basic gui for browsing repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
152 c.groups = self.sa.query(Group).order_by(Group.group_name)\
a04fe5986109 #47 implemented basic gui for browsing repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
153 .filter(Group.group_parent_id == id).all()
a04fe5986109 #47 implemented basic gui for browsing repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1245
diff changeset
154
1193
523382549c45 Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents: 1171
diff changeset
155 return render('admin/repos_groups/repos_groups.html')
523382549c45 Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents: 1171
diff changeset
156
1345
3bce31f026b8 #47 implemented Adding of new repo_groups+forms+validators. Fixed sorting of repo groups by main names in multiple locations. Removed some unneeded calls to self.sa for exchange to .query() methods.
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
157 @HasPermissionAnyDecorator('hg.admin')
1171
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
158 def edit(self, id, format='html'):
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
159 """GET /repos_groups/id/edit: Form to edit an existing item"""
2ab211e0aecd changes for #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
160 # url('edit_repos_group', id=ID)