Mercurial > kallithea
annotate rhodecode/controllers/admin/repos_groups.py @ 1974:edd3f202da4e beta
bumped mercurial to 2.1
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Wed, 01 Feb 2012 22:50:10 +0200 |
parents | f48bce87475b |
children | 87f0800abc7b |
rev | line source |
---|---|
1824
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
1 # -*- coding: utf-8 -*- |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
2 """ |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
3 rhodecode.controllers.admin.repos_groups |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
5 |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
6 repos groups controller for RhodeCode |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
7 |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
8 :created_on: Mar 23, 2010 |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
9 :author: marcink |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
10 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com> |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
11 :license: GPLv3, see COPYING for more details. |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
12 """ |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
13 # This program is free software: you can redistribute it and/or modify |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
14 # it under the terms of the GNU General Public License as published by |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
15 # the Free Software Foundation, either version 3 of the License, or |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
16 # (at your option) any later version. |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
17 # |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
18 # This program is distributed in the hope that it will be useful, |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
21 # GNU General Public License for more details. |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
22 # |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
23 # You should have received a copy of the GNU General Public License |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
24 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
25 |
1171 | 26 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
|
27 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
|
28 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
|
29 |
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 from formencode import htmlfill |
1171 | 31 |
32 from pylons import request, response, session, tmpl_context as c, url | |
33 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
|
34 from pylons.i18n.translation import _ |
1171 | 35 |
1543
ada6926c374f
Added friendly message about removing a group that still contains subgroups.
Marcin Kuzminski <marcin@python-works.com>
parents:
1538
diff
changeset
|
36 from sqlalchemy.exc import IntegrityError |
ada6926c374f
Added friendly message about removing a group that still contains subgroups.
Marcin Kuzminski <marcin@python-works.com>
parents:
1538
diff
changeset
|
37 |
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
|
38 from rhodecode.lib import helpers as h |
1543
ada6926c374f
Added friendly message about removing a group that still contains subgroups.
Marcin Kuzminski <marcin@python-works.com>
parents:
1538
diff
changeset
|
39 from rhodecode.lib.auth import LoginRequired, HasPermissionAnyDecorator |
1171 | 40 from rhodecode.lib.base import BaseController, render |
1633
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1547
diff
changeset
|
41 from rhodecode.model.db import RepoGroup |
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
|
42 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
|
43 from rhodecode.model.forms import ReposGroupForm |
1734
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
44 from rhodecode.model.meta import Session |
1171 | 45 |
46 log = logging.getLogger(__name__) | |
47 | |
1245
5f2fbab7c429
PEP8ify - controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
1193
diff
changeset
|
48 |
1171 | 49 class ReposGroupsController(BaseController): |
50 """REST Controller styled on the Atom Publishing Protocol""" | |
51 # To properly map this controller, ensure your config/routing.py | |
52 # file has a resource setup: | |
53 # map.resource('repos_group', 'repos_groups') | |
54 | |
1347
43b8e161be3f
#47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
55 @LoginRequired() |
43b8e161be3f
#47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
56 def __before__(self): |
43b8e161be3f
#47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
57 super(ReposGroupsController, self).__before__() |
43b8e161be3f
#47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
58 |
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
|
59 def __load_defaults(self): |
1633
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1547
diff
changeset
|
60 c.repo_groups = RepoGroup.groups_choices() |
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
|
61 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
|
62 |
1347
43b8e161be3f
#47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
63 def __load_data(self, group_id): |
43b8e161be3f
#47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
64 """ |
43b8e161be3f
#47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
65 Load defaults settings for edit, and update |
43b8e161be3f
#47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
66 |
43b8e161be3f
#47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
67 :param group_id: |
43b8e161be3f
#47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
68 """ |
43b8e161be3f
#47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
69 self.__load_defaults() |
43b8e161be3f
#47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
70 |
1633
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1547
diff
changeset
|
71 repo_group = RepoGroup.get(group_id) |
1347
43b8e161be3f
#47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
72 |
1349
526120c77a38
#47 added editing of groups, and moving them between. Added check constraint for groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1347
diff
changeset
|
73 data = repo_group.get_dict() |
1347
43b8e161be3f
#47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
74 |
1538
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1482
diff
changeset
|
75 data['group_name'] = repo_group.name |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1482
diff
changeset
|
76 |
1349
526120c77a38
#47 added editing of groups, and moving them between. Added check constraint for groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1347
diff
changeset
|
77 return data |
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
|
78 |
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 @HasPermissionAnyDecorator('hg.admin') |
1171 | 80 def index(self, format='html'): |
81 """GET /repos_groups: All items in the collection""" | |
82 # url('repos_groups') | |
83 | |
1898
a7dfe823933a
added validation to repo groups to check for conflicting repository name fixes #337
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
84 sk = lambda g: g.parents[0].group_name if g.parents else g.group_name |
1633
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1547
diff
changeset
|
85 c.groups = sorted(RepoGroup.query().all(), key=sk) |
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
|
86 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
|
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 | 89 def create(self): |
90 """POST /repos_groups: Create a new item""" | |
91 # 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
|
92 self.__load_defaults() |
1898
a7dfe823933a
added validation to repo groups to check for conflicting repository name fixes #337
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
93 repos_group_form = ReposGroupForm(available_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
|
94 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
|
95 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
|
96 form_result = repos_group_form.to_python(dict(request.POST)) |
1734
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
97 ReposGroupModel().create(form_result) |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
98 Session.commit() |
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
|
99 h.flash(_('created repos group %s') \ |
1347
43b8e161be3f
#47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
100 % form_result['group_name'], category='success') |
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
|
101 #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
|
102 except formencode.Invalid, errors: |
1171 | 103 |
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
|
104 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
|
105 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
|
106 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
|
107 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
|
108 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
|
109 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
|
110 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
|
111 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
|
112 h.flash(_('error occurred during creation of repos group %s') \ |
1347
43b8e161be3f
#47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
113 % request.POST.get('group_name'), category='error') |
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
|
114 |
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
|
115 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
|
116 |
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
|
117 @HasPermissionAnyDecorator('hg.admin') |
1171 | 118 def new(self, format='html'): |
119 """GET /repos_groups/new: Form to create a new item""" | |
120 # 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
|
121 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
|
122 return render('admin/repos_groups/repos_groups_add.html') |
1171 | 123 |
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
|
124 @HasPermissionAnyDecorator('hg.admin') |
1171 | 125 def update(self, id): |
126 """PUT /repos_groups/id: Update an existing item""" | |
127 # Forms posted to this method should contain a hidden field: | |
128 # <input type="hidden" name="_method" value="PUT" /> | |
129 # Or using helpers: | |
130 # h.form(url('repos_group', id=ID), | |
131 # method='put') | |
132 # url('repos_group', id=ID) | |
133 | |
1347
43b8e161be3f
#47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
134 self.__load_defaults() |
1633
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1547
diff
changeset
|
135 c.repos_group = RepoGroup.get(id) |
1347
43b8e161be3f
#47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
136 |
43b8e161be3f
#47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
137 repos_group_form = ReposGroupForm(edit=True, |
43b8e161be3f
#47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
138 old_data=c.repos_group.get_dict(), |
43b8e161be3f
#47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
139 available_groups= |
43b8e161be3f
#47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
140 c.repo_groups_choices)() |
43b8e161be3f
#47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
141 try: |
43b8e161be3f
#47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
142 form_result = repos_group_form.to_python(dict(request.POST)) |
1734
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
143 ReposGroupModel().update(id, form_result) |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
144 Session.commit() |
1347
43b8e161be3f
#47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
145 h.flash(_('updated repos group %s') \ |
43b8e161be3f
#47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
146 % form_result['group_name'], category='success') |
43b8e161be3f
#47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
147 #TODO: in futureaction_logger(, '', '', '', self.sa) |
43b8e161be3f
#47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
148 except formencode.Invalid, errors: |
43b8e161be3f
#47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
149 |
43b8e161be3f
#47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
150 return htmlfill.render( |
43b8e161be3f
#47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
151 render('admin/repos_groups/repos_groups_edit.html'), |
43b8e161be3f
#47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
152 defaults=errors.value, |
43b8e161be3f
#47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
153 errors=errors.error_dict or {}, |
43b8e161be3f
#47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
154 prefix_error=False, |
43b8e161be3f
#47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
155 encoding="UTF-8") |
43b8e161be3f
#47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
156 except Exception: |
43b8e161be3f
#47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
157 log.error(traceback.format_exc()) |
1349
526120c77a38
#47 added editing of groups, and moving them between. Added check constraint for groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1347
diff
changeset
|
158 h.flash(_('error occurred during update of repos group %s') \ |
1347
43b8e161be3f
#47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
159 % request.POST.get('group_name'), category='error') |
43b8e161be3f
#47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
160 |
43b8e161be3f
#47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
161 return redirect(url('repos_groups')) |
43b8e161be3f
#47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
162 |
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
|
163 @HasPermissionAnyDecorator('hg.admin') |
1171 | 164 def delete(self, id): |
165 """DELETE /repos_groups/id: Delete an existing item""" | |
166 # Forms posted to this method should contain a hidden field: | |
167 # <input type="hidden" name="_method" value="DELETE" /> | |
168 # Or using helpers: | |
169 # h.form(url('repos_group', id=ID), | |
170 # method='delete') | |
171 # url('repos_group', id=ID) | |
172 | |
1633
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1547
diff
changeset
|
173 gr = RepoGroup.get(id) |
1346
cf78d302d441
#47 implemented deleting of empty groups. Fixed problem with full paths on nested groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1345
diff
changeset
|
174 repos = gr.repositories.all() |
cf78d302d441
#47 implemented deleting of empty groups. Fixed problem with full paths on nested groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1345
diff
changeset
|
175 if repos: |
cf78d302d441
#47 implemented deleting of empty groups. Fixed problem with full paths on nested groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1345
diff
changeset
|
176 h.flash(_('This group contains %s repositores and cannot be ' |
cf78d302d441
#47 implemented deleting of empty groups. Fixed problem with full paths on nested groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1345
diff
changeset
|
177 'deleted' % len(repos)), |
cf78d302d441
#47 implemented deleting of empty groups. Fixed problem with full paths on nested groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1345
diff
changeset
|
178 category='error') |
cf78d302d441
#47 implemented deleting of empty groups. Fixed problem with full paths on nested groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1345
diff
changeset
|
179 return redirect(url('repos_groups')) |
cf78d302d441
#47 implemented deleting of empty groups. Fixed problem with full paths on nested groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1345
diff
changeset
|
180 |
cf78d302d441
#47 implemented deleting of empty groups. Fixed problem with full paths on nested groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1345
diff
changeset
|
181 try: |
1734
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
182 ReposGroupModel().delete(id) |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
183 Session.commit() |
1346
cf78d302d441
#47 implemented deleting of empty groups. Fixed problem with full paths on nested groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1345
diff
changeset
|
184 h.flash(_('removed repos group %s' % gr.group_name), category='success') |
1482
a39c0e5fca89
removed obsolete sort code
Marcin Kuzminski <marcin@python-works.com>
parents:
1394
diff
changeset
|
185 #TODO: in future action_logger(, '', '', '', self.sa) |
1543
ada6926c374f
Added friendly message about removing a group that still contains subgroups.
Marcin Kuzminski <marcin@python-works.com>
parents:
1538
diff
changeset
|
186 except IntegrityError, e: |
1752
f28dc032adf0
Added handling of ignore whitespace flag in changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
187 if e.message.find('groups_group_parent_id_fkey') != -1: |
1543
ada6926c374f
Added friendly message about removing a group that still contains subgroups.
Marcin Kuzminski <marcin@python-works.com>
parents:
1538
diff
changeset
|
188 log.error(traceback.format_exc()) |
ada6926c374f
Added friendly message about removing a group that still contains subgroups.
Marcin Kuzminski <marcin@python-works.com>
parents:
1538
diff
changeset
|
189 h.flash(_('Cannot delete this group it still contains ' |
ada6926c374f
Added friendly message about removing a group that still contains subgroups.
Marcin Kuzminski <marcin@python-works.com>
parents:
1538
diff
changeset
|
190 'subgroups'), |
ada6926c374f
Added friendly message about removing a group that still contains subgroups.
Marcin Kuzminski <marcin@python-works.com>
parents:
1538
diff
changeset
|
191 category='warning') |
ada6926c374f
Added friendly message about removing a group that still contains subgroups.
Marcin Kuzminski <marcin@python-works.com>
parents:
1538
diff
changeset
|
192 else: |
ada6926c374f
Added friendly message about removing a group that still contains subgroups.
Marcin Kuzminski <marcin@python-works.com>
parents:
1538
diff
changeset
|
193 log.error(traceback.format_exc()) |
ada6926c374f
Added friendly message about removing a group that still contains subgroups.
Marcin Kuzminski <marcin@python-works.com>
parents:
1538
diff
changeset
|
194 h.flash(_('error occurred during deletion of repos ' |
ada6926c374f
Added friendly message about removing a group that still contains subgroups.
Marcin Kuzminski <marcin@python-works.com>
parents:
1538
diff
changeset
|
195 'group %s' % gr.group_name), category='error') |
ada6926c374f
Added friendly message about removing a group that still contains subgroups.
Marcin Kuzminski <marcin@python-works.com>
parents:
1538
diff
changeset
|
196 |
1346
cf78d302d441
#47 implemented deleting of empty groups. Fixed problem with full paths on nested groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1345
diff
changeset
|
197 except Exception: |
cf78d302d441
#47 implemented deleting of empty groups. Fixed problem with full paths on nested groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1345
diff
changeset
|
198 log.error(traceback.format_exc()) |
1543
ada6926c374f
Added friendly message about removing a group that still contains subgroups.
Marcin Kuzminski <marcin@python-works.com>
parents:
1538
diff
changeset
|
199 h.flash(_('error occurred during deletion of repos ' |
ada6926c374f
Added friendly message about removing a group that still contains subgroups.
Marcin Kuzminski <marcin@python-works.com>
parents:
1538
diff
changeset
|
200 'group %s' % gr.group_name), category='error') |
1346
cf78d302d441
#47 implemented deleting of empty groups. Fixed problem with full paths on nested groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1345
diff
changeset
|
201 |
cf78d302d441
#47 implemented deleting of empty groups. Fixed problem with full paths on nested groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1345
diff
changeset
|
202 return redirect(url('repos_groups')) |
cf78d302d441
#47 implemented deleting of empty groups. Fixed problem with full paths on nested groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1345
diff
changeset
|
203 |
1538
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1482
diff
changeset
|
204 def show_by_name(self, group_name): |
1633
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1547
diff
changeset
|
205 id_ = RepoGroup.get_by_group_name(group_name).group_id |
1538
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1482
diff
changeset
|
206 return self.show(id_) |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1482
diff
changeset
|
207 |
1171 | 208 def show(self, id, format='html'): |
209 """GET /repos_groups/id: Show a specific item""" | |
210 # url('repos_group', id=ID) | |
211 | |
1633
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1547
diff
changeset
|
212 c.group = RepoGroup.get(id) |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1349
diff
changeset
|
213 |
1193
523382549c45
Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents:
1171
diff
changeset
|
214 if c.group: |
1343
a04fe5986109
#47 implemented basic gui for browsing repo groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1245
diff
changeset
|
215 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
|
216 else: |
1394
416dacac46bf
fixed improper redirect for repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1366
diff
changeset
|
217 return redirect(url('home')) |
1193
523382549c45
Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents:
1171
diff
changeset
|
218 |
523382549c45
Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents:
1171
diff
changeset
|
219 #overwrite our cached list with current filter |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1349
diff
changeset
|
220 gr_filter = c.group_repos |
1193
523382549c45
Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents:
1171
diff
changeset
|
221 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
|
222 |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1349
diff
changeset
|
223 c.repos_list = c.cached_repo_list |
1193
523382549c45
Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents:
1171
diff
changeset
|
224 |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1349
diff
changeset
|
225 c.repo_cnt = 0 |
1343
a04fe5986109
#47 implemented basic gui for browsing repo groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1245
diff
changeset
|
226 |
1633
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1547
diff
changeset
|
227 c.groups = self.sa.query(RepoGroup).order_by(RepoGroup.group_name)\ |
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1547
diff
changeset
|
228 .filter(RepoGroup.group_parent_id == id).all() |
1343
a04fe5986109
#47 implemented basic gui for browsing repo groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1245
diff
changeset
|
229 |
1193
523382549c45
Added repo group page showing what reposiories are inside a group
Marcin Kuzminski <marcin@python-works.com>
parents:
1171
diff
changeset
|
230 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
|
231 |
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
|
232 @HasPermissionAnyDecorator('hg.admin') |
1171 | 233 def edit(self, id, format='html'): |
234 """GET /repos_groups/id/edit: Form to edit an existing item""" | |
235 # url('edit_repos_group', id=ID) | |
1349
526120c77a38
#47 added editing of groups, and moving them between. Added check constraint for groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1347
diff
changeset
|
236 |
1482
a39c0e5fca89
removed obsolete sort code
Marcin Kuzminski <marcin@python-works.com>
parents:
1394
diff
changeset
|
237 id_ = int(id) |
1349
526120c77a38
#47 added editing of groups, and moving them between. Added check constraint for groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1347
diff
changeset
|
238 |
1633
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1547
diff
changeset
|
239 c.repos_group = RepoGroup.get(id_) |
1482
a39c0e5fca89
removed obsolete sort code
Marcin Kuzminski <marcin@python-works.com>
parents:
1394
diff
changeset
|
240 defaults = self.__load_data(id_) |
1347
43b8e161be3f
#47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
241 |
1349
526120c77a38
#47 added editing of groups, and moving them between. Added check constraint for groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1347
diff
changeset
|
242 # we need to exclude this group from the group list for editing |
1482
a39c0e5fca89
removed obsolete sort code
Marcin Kuzminski <marcin@python-works.com>
parents:
1394
diff
changeset
|
243 c.repo_groups = filter(lambda x:x[0] != id_, c.repo_groups) |
1349
526120c77a38
#47 added editing of groups, and moving them between. Added check constraint for groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1347
diff
changeset
|
244 |
1347
43b8e161be3f
#47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
245 return htmlfill.render( |
43b8e161be3f
#47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
246 render('admin/repos_groups/repos_groups_edit.html'), |
43b8e161be3f
#47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
247 defaults=defaults, |
43b8e161be3f
#47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
248 encoding="UTF-8", |
43b8e161be3f
#47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
249 force_defaults=False |
43b8e161be3f
#47 implemented basic edition of groups
Marcin Kuzminski <marcin@python-works.com>
parents:
1346
diff
changeset
|
250 ) |