Mercurial > kallithea
annotate rhodecode/controllers/admin/users_groups.py @ 1039:51b70569c330 beta
extended admin rescan to show what repositories was added and what removed
fixed found bugs, added expunge to cached getter since it introduce some more problems.
Added some relationship to properly clean related objects from database.
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sun, 13 Feb 2011 01:38:39 +0100 |
parents | f6658c70eeeb |
children | 6eb5bb24a948 |
rev | line source |
---|---|
956
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2 """ |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3 rhodecode.controllers.admin.users_groups |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
5 |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
6 Users Groups crud controller for pylons |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
7 |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
8 :created_on: Jan 25, 2011 |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
9 :author: marcink |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
10 :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com> |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
11 :license: GPLv3, see COPYING for more details. |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
12 """ |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
13 # This program is free software; you can redistribute it and/or |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
14 # modify it under the terms of the GNU General Public License |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
15 # as published by the Free Software Foundation; version 2 |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
16 # of the License or (at your opinion) any later version of the license. |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
17 # |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
18 # This program is distributed in the hope that it will be useful, |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
21 # GNU General Public License for more details. |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
22 # |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
23 # You should have received a copy of the GNU General Public License |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
24 # along with this program; if not, write to the Free Software |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
26 # MA 02110-1301, USA. |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
27 |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
28 import logging |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
29 import traceback |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
30 import formencode |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
31 |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
32 from formencode import htmlfill |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
33 from pylons import request, session, tmpl_context as c, url, config |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
34 from pylons.controllers.util import abort, redirect |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
35 from pylons.i18n.translation import _ |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
36 |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
37 from rhodecode.lib.exceptions import DefaultUserException, UserOwnsReposException |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
38 from rhodecode.lib import helpers as h |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
39 from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator, \ |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
40 fill_perms |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
41 from rhodecode.lib.base import BaseController, render |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
42 |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
43 from rhodecode.model.db import User, UsersGroup |
959
fff21c9b075c
#56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents:
956
diff
changeset
|
44 from rhodecode.model.forms import UserForm, UsersGroupForm |
956
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
45 from rhodecode.model.user import UserModel |
959
fff21c9b075c
#56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents:
956
diff
changeset
|
46 from rhodecode.model.users_group import UsersGroupModel |
956
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
47 |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
48 log = logging.getLogger(__name__) |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
49 |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
50 class UsersGroupsController(BaseController): |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
51 """REST Controller styled on the Atom Publishing Protocol""" |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
52 # To properly map this controller, ensure your config/routing.py |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
53 # file has a resource setup: |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
54 # map.resource('users_group', 'users_groups') |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
55 |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
56 @LoginRequired() |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
57 @HasPermissionAllDecorator('hg.admin') |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
58 def __before__(self): |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
59 c.admin_user = session.get('admin_user') |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
60 c.admin_username = session.get('admin_username') |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
61 super(UsersGroupsController, self).__before__() |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
62 c.available_permissions = config['available_permissions'] |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
63 |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
64 def index(self, format='html'): |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
65 """GET /users_groups: All items in the collection""" |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
66 # url('users_groups') |
959
fff21c9b075c
#56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents:
956
diff
changeset
|
67 c.users_groups_list = self.sa.query(UsersGroup).all() |
956
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
68 return render('admin/users_groups/users_groups.html') |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
69 |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
70 def create(self): |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
71 """POST /users_groups: Create a new item""" |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
72 # url('users_groups') |
959
fff21c9b075c
#56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents:
956
diff
changeset
|
73 users_group_model = UsersGroupModel() |
fff21c9b075c
#56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents:
956
diff
changeset
|
74 users_group_form = UsersGroupForm()() |
fff21c9b075c
#56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents:
956
diff
changeset
|
75 try: |
fff21c9b075c
#56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents:
956
diff
changeset
|
76 form_result = users_group_form.to_python(dict(request.POST)) |
fff21c9b075c
#56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents:
956
diff
changeset
|
77 users_group_model.create(form_result) |
fff21c9b075c
#56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents:
956
diff
changeset
|
78 h.flash(_('created users group %s') % form_result['users_group_name'], |
fff21c9b075c
#56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents:
956
diff
changeset
|
79 category='success') |
fff21c9b075c
#56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents:
956
diff
changeset
|
80 #action_logger(self.rhodecode_user, 'new_user', '', '', self.sa) |
fff21c9b075c
#56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents:
956
diff
changeset
|
81 except formencode.Invalid, errors: |
fff21c9b075c
#56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents:
956
diff
changeset
|
82 return htmlfill.render( |
fff21c9b075c
#56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents:
956
diff
changeset
|
83 render('admin/users_groups/users_group_add.html'), |
fff21c9b075c
#56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents:
956
diff
changeset
|
84 defaults=errors.value, |
fff21c9b075c
#56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents:
956
diff
changeset
|
85 errors=errors.error_dict or {}, |
fff21c9b075c
#56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents:
956
diff
changeset
|
86 prefix_error=False, |
fff21c9b075c
#56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents:
956
diff
changeset
|
87 encoding="UTF-8") |
fff21c9b075c
#56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents:
956
diff
changeset
|
88 except Exception: |
fff21c9b075c
#56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents:
956
diff
changeset
|
89 log.error(traceback.format_exc()) |
fff21c9b075c
#56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents:
956
diff
changeset
|
90 h.flash(_('error occurred during creation of users group %s') \ |
fff21c9b075c
#56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents:
956
diff
changeset
|
91 % request.POST.get('users_group_name'), category='error') |
fff21c9b075c
#56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents:
956
diff
changeset
|
92 |
fff21c9b075c
#56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents:
956
diff
changeset
|
93 return redirect(url('users_groups')) |
956
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
94 |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
95 def new(self, format='html'): |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
96 """GET /users_groups/new: Form to create a new item""" |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
97 # url('new_users_group') |
959
fff21c9b075c
#56 fixed found bugs, implemented adding of new group + forms+validators
Marcin Kuzminski <marcin@python-works.com>
parents:
956
diff
changeset
|
98 return render('admin/users_groups/users_group_add.html') |
956
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
99 |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
100 def update(self, id): |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
101 """PUT /users_groups/id: Update an existing item""" |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
102 # Forms posted to this method should contain a hidden field: |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
103 # <input type="hidden" name="_method" value="PUT" /> |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
104 # Or using helpers: |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
105 # h.form(url('users_group', id=ID), |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
106 # method='put') |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
107 # url('users_group', id=ID) |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
108 |
972
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
109 |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
110 users_group_model = UsersGroupModel() |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
111 c.users_group = users_group_model.get(id) |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
112 c.group_members = [(x.user_id, x.user.username) for x in |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
113 c.users_group.members] |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
114 |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
115 c.available_members = [(x.user_id, x.username) for x in |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
116 self.sa.query(User).all()] |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
117 users_group_form = UsersGroupForm(edit=True, |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
118 old_data=c.users_group.get_dict(), |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
119 available_members=[str(x[0]) for x |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
120 in c.available_members])() |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
121 |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
122 try: |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
123 form_result = users_group_form.to_python(request.POST) |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
124 users_group_model.update(id, form_result) |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
125 h.flash(_('updated users group %s') % form_result['users_group_name'], |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
126 category='success') |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
127 #action_logger(self.rhodecode_user, 'new_user', '', '', self.sa) |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
128 except formencode.Invalid, errors: |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
129 return htmlfill.render( |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
130 render('admin/users_groups/users_group_edit.html'), |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
131 defaults=errors.value, |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
132 errors=errors.error_dict or {}, |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
133 prefix_error=False, |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
134 encoding="UTF-8") |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
135 except Exception: |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
136 log.error(traceback.format_exc()) |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
137 h.flash(_('error occurred during update of users group %s') \ |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
138 % request.POST.get('users_group_name'), category='error') |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
139 |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
140 return redirect(url('users_groups')) |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
141 |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
142 |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
143 |
956
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
144 def delete(self, id): |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
145 """DELETE /users_groups/id: Delete an existing item""" |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
146 # Forms posted to this method should contain a hidden field: |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
147 # <input type="hidden" name="_method" value="DELETE" /> |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
148 # Or using helpers: |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
149 # h.form(url('users_group', id=ID), |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
150 # method='delete') |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
151 # url('users_group', id=ID) |
973
9be6d46c72d6
#56 implemented users groups deletes
Marcin Kuzminski <marcin@python-works.com>
parents:
972
diff
changeset
|
152 users_group_model = UsersGroupModel() |
9be6d46c72d6
#56 implemented users groups deletes
Marcin Kuzminski <marcin@python-works.com>
parents:
972
diff
changeset
|
153 try: |
9be6d46c72d6
#56 implemented users groups deletes
Marcin Kuzminski <marcin@python-works.com>
parents:
972
diff
changeset
|
154 users_group_model.delete(id) |
9be6d46c72d6
#56 implemented users groups deletes
Marcin Kuzminski <marcin@python-works.com>
parents:
972
diff
changeset
|
155 h.flash(_('successfully deleted users group'), category='success') |
9be6d46c72d6
#56 implemented users groups deletes
Marcin Kuzminski <marcin@python-works.com>
parents:
972
diff
changeset
|
156 except Exception: |
9be6d46c72d6
#56 implemented users groups deletes
Marcin Kuzminski <marcin@python-works.com>
parents:
972
diff
changeset
|
157 h.flash(_('An error occurred during deletion of users group'), |
9be6d46c72d6
#56 implemented users groups deletes
Marcin Kuzminski <marcin@python-works.com>
parents:
972
diff
changeset
|
158 category='error') |
9be6d46c72d6
#56 implemented users groups deletes
Marcin Kuzminski <marcin@python-works.com>
parents:
972
diff
changeset
|
159 return redirect(url('users_groups')) |
956
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
160 |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
161 def show(self, id, format='html'): |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
162 """GET /users_groups/id: Show a specific item""" |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
163 # url('users_group', id=ID) |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
164 |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
165 def edit(self, id, format='html'): |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
166 """GET /users_groups/id/edit: Form to edit an existing item""" |
83d35d716a02
started working on issue #56
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
167 # url('edit_users_group', id=ID) |
972
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
168 |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
169 c.users_group = self.sa.query(UsersGroup).get(id) |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
170 if not c.users_group: |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
171 return redirect(url('users_groups')) |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
172 |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
173 c.users_group.permissions = {} |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
174 c.group_members = [(x.user_id, x.user.username) for x in |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
175 c.users_group.members] |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
176 c.available_members = [(x.user_id, x.username) for x in |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
177 self.sa.query(User).all()] |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
178 defaults = c.users_group.get_dict() |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
179 |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
180 return htmlfill.render( |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
181 render('admin/users_groups/users_group_edit.html'), |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
182 defaults=defaults, |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
183 encoding="UTF-8", |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
184 force_defaults=False |
2c8fd84935a4
#56 implemented users groups editing,
Marcin Kuzminski <marcin@python-works.com>
parents:
959
diff
changeset
|
185 ) |