##// END OF EJS Templates
some docs updates on controller
marcink -
r853:f67868ef beta
parent child Browse files
Show More
@@ -1,53 +1,53
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """
2 """
3 package.rhodecode.controllers.admin.admin
3 rhodecode.controllers.admin.admin
4 ~~~~~~~~~~~~~~
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5
5
6 Controller for Admin panel of Rhodecode
6 Controller for Admin panel of Rhodecode
7
7
8 :created_on: Apr 7, 2010
8 :created_on: Apr 7, 2010
9 :author: marcink
9 :author: marcink
10 :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
10 :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
11 :license: GPLv3, see COPYING for more details.
11 :license: GPLv3, see COPYING for more details.
12 """
12 """
13 # This program is free software; you can redistribute it and/or
13 # This program is free software; you can redistribute it and/or
14 # modify it under the terms of the GNU General Public License
14 # modify it under the terms of the GNU General Public License
15 # as published by the Free Software Foundation; version 2
15 # as published by the Free Software Foundation; version 2
16 # of the License or (at your opinion) any later version of the license.
16 # of the License or (at your opinion) any later version of the license.
17 #
17 #
18 # This program is distributed in the hope that it will be useful,
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
21 # GNU General Public License for more details.
22 #
22 #
23 # You should have received a copy of the GNU General Public License
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
26 # MA 02110-1301, USA.
26 # MA 02110-1301, USA.
27
27
28 import logging
28 import logging
29 from pylons import request, tmpl_context as c
29 from pylons import request, tmpl_context as c
30 from rhodecode.lib.base import BaseController, render
30 from rhodecode.lib.base import BaseController, render
31 from rhodecode.model.db import UserLog
31 from rhodecode.model.db import UserLog
32 from webhelpers.paginate import Page
32 from webhelpers.paginate import Page
33 from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator
33 from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator
34
34
35 log = logging.getLogger(__name__)
35 log = logging.getLogger(__name__)
36
36
37 class AdminController(BaseController):
37 class AdminController(BaseController):
38
38
39 @LoginRequired()
39 @LoginRequired()
40 def __before__(self):
40 def __before__(self):
41 super(AdminController, self).__before__()
41 super(AdminController, self).__before__()
42
42
43 @HasPermissionAllDecorator('hg.admin')
43 @HasPermissionAllDecorator('hg.admin')
44 def index(self):
44 def index(self):
45
45
46 users_log = self.sa.query(UserLog).order_by(UserLog.action_date.desc())
46 users_log = self.sa.query(UserLog).order_by(UserLog.action_date.desc())
47 p = int(request.params.get('page', 1))
47 p = int(request.params.get('page', 1))
48 c.users_log = Page(users_log, page=p, items_per_page=10)
48 c.users_log = Page(users_log, page=p, items_per_page=10)
49 c.log_data = render('admin/admin_log.html')
49 c.log_data = render('admin/admin_log.html')
50 if request.params.get('partial'):
50 if request.params.get('partial'):
51 return c.log_data
51 return c.log_data
52 return render('admin/admin.html')
52 return render('admin/admin.html')
53
53
@@ -1,170 +1,171
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """
2 """
3 package.rhodecode.controllers.admin.permissions
3 rhodecode.controllers.admin.permissions
4 ~~~~~~~~~~~~~~
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5
5 permissions controller for Rhodecode
6 permissions controller for Rhodecode
6
7
7 :created_on: Apr 27, 2010
8 :created_on: Apr 27, 2010
8 :author: marcink
9 :author: marcink
9 :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
10 :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
10 :license: GPLv3, see COPYING for more details.
11 :license: GPLv3, see COPYING for more details.
11 """
12 """
12 # This program is free software; you can redistribute it and/or
13 # This program is free software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License
14 # modify it under the terms of the GNU General Public License
14 # as published by the Free Software Foundation; version 2
15 # as published by the Free Software Foundation; version 2
15 # of the License or (at your opinion) any later version of the license.
16 # of the License or (at your opinion) any later version of the license.
16 #
17 #
17 # This program is distributed in the hope that it will be useful,
18 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
21 # GNU General Public License for more details.
21 #
22 #
22 # You should have received a copy of the GNU General Public License
23 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write to the Free Software
24 # along with this program; if not, write to the Free Software
24 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
25 # MA 02110-1301, USA.
26 # MA 02110-1301, USA.
26
27
27 from formencode import htmlfill
28 from formencode import htmlfill
28 from pylons import request, session, tmpl_context as c, url
29 from pylons import request, session, tmpl_context as c, url
29 from pylons.controllers.util import abort, redirect
30 from pylons.controllers.util import abort, redirect
30 from pylons.i18n.translation import _
31 from pylons.i18n.translation import _
31 from rhodecode.lib import helpers as h
32 from rhodecode.lib import helpers as h
32 from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator
33 from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator
33 from rhodecode.lib.auth_ldap import LdapImportError
34 from rhodecode.lib.auth_ldap import LdapImportError
34 from rhodecode.lib.base import BaseController, render
35 from rhodecode.lib.base import BaseController, render
35 from rhodecode.model.forms import LdapSettingsForm, DefaultPermissionsForm
36 from rhodecode.model.forms import LdapSettingsForm, DefaultPermissionsForm
36 from rhodecode.model.permission import PermissionModel
37 from rhodecode.model.permission import PermissionModel
37 from rhodecode.model.settings import SettingsModel
38 from rhodecode.model.settings import SettingsModel
38 from rhodecode.model.user import UserModel
39 from rhodecode.model.user import UserModel
39 import formencode
40 import formencode
40 import logging
41 import logging
41 import traceback
42 import traceback
42
43
43 log = logging.getLogger(__name__)
44 log = logging.getLogger(__name__)
44
45
45 class PermissionsController(BaseController):
46 class PermissionsController(BaseController):
46 """REST Controller styled on the Atom Publishing Protocol"""
47 """REST Controller styled on the Atom Publishing Protocol"""
47 # To properly map this controller, ensure your config/routing.py
48 # To properly map this controller, ensure your config/routing.py
48 # file has a resource setup:
49 # file has a resource setup:
49 # map.resource('permission', 'permissions')
50 # map.resource('permission', 'permissions')
50
51
51 @LoginRequired()
52 @LoginRequired()
52 @HasPermissionAllDecorator('hg.admin')
53 @HasPermissionAllDecorator('hg.admin')
53 def __before__(self):
54 def __before__(self):
54 c.admin_user = session.get('admin_user')
55 c.admin_user = session.get('admin_user')
55 c.admin_username = session.get('admin_username')
56 c.admin_username = session.get('admin_username')
56 super(PermissionsController, self).__before__()
57 super(PermissionsController, self).__before__()
57
58
58 self.perms_choices = [('repository.none', _('None'),),
59 self.perms_choices = [('repository.none', _('None'),),
59 ('repository.read', _('Read'),),
60 ('repository.read', _('Read'),),
60 ('repository.write', _('Write'),),
61 ('repository.write', _('Write'),),
61 ('repository.admin', _('Admin'),)]
62 ('repository.admin', _('Admin'),)]
62 self.register_choices = [
63 self.register_choices = [
63 ('hg.register.none',
64 ('hg.register.none',
64 _('disabled')),
65 _('disabled')),
65 ('hg.register.manual_activate',
66 ('hg.register.manual_activate',
66 _('allowed with manual account activation')),
67 _('allowed with manual account activation')),
67 ('hg.register.auto_activate',
68 ('hg.register.auto_activate',
68 _('allowed with automatic account activation')), ]
69 _('allowed with automatic account activation')), ]
69
70
70 self.create_choices = [('hg.create.none', _('Disabled')),
71 self.create_choices = [('hg.create.none', _('Disabled')),
71 ('hg.create.repository', _('Enabled'))]
72 ('hg.create.repository', _('Enabled'))]
72
73
73
74
74 def index(self, format='html'):
75 def index(self, format='html'):
75 """GET /permissions: All items in the collection"""
76 """GET /permissions: All items in the collection"""
76 # url('permissions')
77 # url('permissions')
77
78
78 def create(self):
79 def create(self):
79 """POST /permissions: Create a new item"""
80 """POST /permissions: Create a new item"""
80 # url('permissions')
81 # url('permissions')
81
82
82 def new(self, format='html'):
83 def new(self, format='html'):
83 """GET /permissions/new: Form to create a new item"""
84 """GET /permissions/new: Form to create a new item"""
84 # url('new_permission')
85 # url('new_permission')
85
86
86 def update(self, id):
87 def update(self, id):
87 """PUT /permissions/id: Update an existing item"""
88 """PUT /permissions/id: Update an existing item"""
88 # Forms posted to this method should contain a hidden field:
89 # Forms posted to this method should contain a hidden field:
89 # <input type="hidden" name="_method" value="PUT" />
90 # <input type="hidden" name="_method" value="PUT" />
90 # Or using helpers:
91 # Or using helpers:
91 # h.form(url('permission', id=ID),
92 # h.form(url('permission', id=ID),
92 # method='put')
93 # method='put')
93 # url('permission', id=ID)
94 # url('permission', id=ID)
94
95
95 permission_model = PermissionModel()
96 permission_model = PermissionModel()
96
97
97 _form = DefaultPermissionsForm([x[0] for x in self.perms_choices],
98 _form = DefaultPermissionsForm([x[0] for x in self.perms_choices],
98 [x[0] for x in self.register_choices],
99 [x[0] for x in self.register_choices],
99 [x[0] for x in self.create_choices])()
100 [x[0] for x in self.create_choices])()
100
101
101 try:
102 try:
102 form_result = _form.to_python(dict(request.POST))
103 form_result = _form.to_python(dict(request.POST))
103 form_result.update({'perm_user_name':id})
104 form_result.update({'perm_user_name':id})
104 permission_model.update(form_result)
105 permission_model.update(form_result)
105 h.flash(_('Default permissions updated successfully'),
106 h.flash(_('Default permissions updated successfully'),
106 category='success')
107 category='success')
107
108
108 except formencode.Invalid, errors:
109 except formencode.Invalid, errors:
109 c.perms_choices = self.perms_choices
110 c.perms_choices = self.perms_choices
110 c.register_choices = self.register_choices
111 c.register_choices = self.register_choices
111 c.create_choices = self.create_choices
112 c.create_choices = self.create_choices
112 defaults = errors.value
113 defaults = errors.value
113
114
114 return htmlfill.render(
115 return htmlfill.render(
115 render('admin/permissions/permissions.html'),
116 render('admin/permissions/permissions.html'),
116 defaults=defaults,
117 defaults=defaults,
117 errors=errors.error_dict or {},
118 errors=errors.error_dict or {},
118 prefix_error=False,
119 prefix_error=False,
119 encoding="UTF-8")
120 encoding="UTF-8")
120 except Exception:
121 except Exception:
121 log.error(traceback.format_exc())
122 log.error(traceback.format_exc())
122 h.flash(_('error occured during update of permissions'),
123 h.flash(_('error occured during update of permissions'),
123 category='error')
124 category='error')
124
125
125 return redirect(url('edit_permission', id=id))
126 return redirect(url('edit_permission', id=id))
126
127
127
128
128
129
129 def delete(self, id):
130 def delete(self, id):
130 """DELETE /permissions/id: Delete an existing item"""
131 """DELETE /permissions/id: Delete an existing item"""
131 # Forms posted to this method should contain a hidden field:
132 # Forms posted to this method should contain a hidden field:
132 # <input type="hidden" name="_method" value="DELETE" />
133 # <input type="hidden" name="_method" value="DELETE" />
133 # Or using helpers:
134 # Or using helpers:
134 # h.form(url('permission', id=ID),
135 # h.form(url('permission', id=ID),
135 # method='delete')
136 # method='delete')
136 # url('permission', id=ID)
137 # url('permission', id=ID)
137
138
138 def show(self, id, format='html'):
139 def show(self, id, format='html'):
139 """GET /permissions/id: Show a specific item"""
140 """GET /permissions/id: Show a specific item"""
140 # url('permission', id=ID)
141 # url('permission', id=ID)
141
142
142 def edit(self, id, format='html'):
143 def edit(self, id, format='html'):
143 """GET /permissions/id/edit: Form to edit an existing item"""
144 """GET /permissions/id/edit: Form to edit an existing item"""
144 #url('edit_permission', id=ID)
145 #url('edit_permission', id=ID)
145 c.perms_choices = self.perms_choices
146 c.perms_choices = self.perms_choices
146 c.register_choices = self.register_choices
147 c.register_choices = self.register_choices
147 c.create_choices = self.create_choices
148 c.create_choices = self.create_choices
148
149
149 if id == 'default':
150 if id == 'default':
150 default_user = UserModel().get_by_username('default')
151 default_user = UserModel().get_by_username('default')
151 defaults = {'_method':'put',
152 defaults = {'_method':'put',
152 'anonymous':default_user.active}
153 'anonymous':default_user.active}
153
154
154 for p in default_user.user_perms:
155 for p in default_user.user_perms:
155 if p.permission.permission_name.startswith('repository.'):
156 if p.permission.permission_name.startswith('repository.'):
156 defaults['default_perm'] = p.permission.permission_name
157 defaults['default_perm'] = p.permission.permission_name
157
158
158 if p.permission.permission_name.startswith('hg.register.'):
159 if p.permission.permission_name.startswith('hg.register.'):
159 defaults['default_register'] = p.permission.permission_name
160 defaults['default_register'] = p.permission.permission_name
160
161
161 if p.permission.permission_name.startswith('hg.create.'):
162 if p.permission.permission_name.startswith('hg.create.'):
162 defaults['default_create'] = p.permission.permission_name
163 defaults['default_create'] = p.permission.permission_name
163
164
164 return htmlfill.render(
165 return htmlfill.render(
165 render('admin/permissions/permissions.html'),
166 render('admin/permissions/permissions.html'),
166 defaults=defaults,
167 defaults=defaults,
167 encoding="UTF-8",
168 encoding="UTF-8",
168 force_defaults=True,)
169 force_defaults=True,)
169 else:
170 else:
170 return redirect(url('admin_home'))
171 return redirect(url('admin_home'))
@@ -1,167 +1,172
1 #!/usr/bin/env python
1 # -*- coding: utf-8 -*-
2 # encoding: utf-8
2 """
3 # users controller for pylons
3 rhodecode.controllers.admin.users
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 #
5
6 Users crud controller for pylons
7
8 :created_on: Apr 4, 2010
9 :author: marcink
10 :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
11 :license: GPLv3, see COPYING for more details.
12 """
6 # This program is free software; you can redistribute it and/or
13 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
14 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; version 2
15 # as published by the Free Software Foundation; version 2
9 # of the License or (at your opinion) any later version of the license.
16 # of the License or (at your opinion) any later version of the license.
10 #
17 #
11 # This program is distributed in the hope that it will be useful,
18 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
21 # GNU General Public License for more details.
15 #
22 #
16 # You should have received a copy of the GNU General Public License
23 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
24 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 # MA 02110-1301, USA.
26 # MA 02110-1301, USA.
20 """
27
21 Created on April 4, 2010
28 import logging
22 users controller for pylons
29 import traceback
23 @author: marcink
30 import formencode
24 """
25
31
26 from formencode import htmlfill
32 from formencode import htmlfill
27 from pylons import request, session, tmpl_context as c, url
33 from pylons import request, session, tmpl_context as c, url
28 from pylons.controllers.util import abort, redirect
34 from pylons.controllers.util import abort, redirect
29 from pylons.i18n.translation import _
35 from pylons.i18n.translation import _
36
30 from rhodecode.lib.exceptions import *
37 from rhodecode.lib.exceptions import *
31 from rhodecode.lib import helpers as h
38 from rhodecode.lib import helpers as h
32 from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator
39 from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator
33 from rhodecode.lib.base import BaseController, render
40 from rhodecode.lib.base import BaseController, render
41
34 from rhodecode.model.db import User
42 from rhodecode.model.db import User
35 from rhodecode.model.forms import UserForm
43 from rhodecode.model.forms import UserForm
36 from rhodecode.model.user import UserModel
44 from rhodecode.model.user import UserModel
37 import formencode
38 import logging
39 import traceback
40
45
41 log = logging.getLogger(__name__)
46 log = logging.getLogger(__name__)
42
47
43 class UsersController(BaseController):
48 class UsersController(BaseController):
44 """REST Controller styled on the Atom Publishing Protocol"""
49 """REST Controller styled on the Atom Publishing Protocol"""
45 # To properly map this controller, ensure your config/routing.py
50 # To properly map this controller, ensure your config/routing.py
46 # file has a resource setup:
51 # file has a resource setup:
47 # map.resource('user', 'users')
52 # map.resource('user', 'users')
48
53
49 @LoginRequired()
54 @LoginRequired()
50 @HasPermissionAllDecorator('hg.admin')
55 @HasPermissionAllDecorator('hg.admin')
51 def __before__(self):
56 def __before__(self):
52 c.admin_user = session.get('admin_user')
57 c.admin_user = session.get('admin_user')
53 c.admin_username = session.get('admin_username')
58 c.admin_username = session.get('admin_username')
54 super(UsersController, self).__before__()
59 super(UsersController, self).__before__()
55
60
56
61
57 def index(self, format='html'):
62 def index(self, format='html'):
58 """GET /users: All items in the collection"""
63 """GET /users: All items in the collection"""
59 # url('users')
64 # url('users')
60
65
61 c.users_list = self.sa.query(User).all()
66 c.users_list = self.sa.query(User).all()
62 return render('admin/users/users.html')
67 return render('admin/users/users.html')
63
68
64 def create(self):
69 def create(self):
65 """POST /users: Create a new item"""
70 """POST /users: Create a new item"""
66 # url('users')
71 # url('users')
67
72
68 user_model = UserModel()
73 user_model = UserModel()
69 login_form = UserForm()()
74 login_form = UserForm()()
70 try:
75 try:
71 form_result = login_form.to_python(dict(request.POST))
76 form_result = login_form.to_python(dict(request.POST))
72 user_model.create(form_result)
77 user_model.create(form_result)
73 h.flash(_('created user %s') % form_result['username'],
78 h.flash(_('created user %s') % form_result['username'],
74 category='success')
79 category='success')
75 #action_logger(self.rhodecode_user, 'new_user', '', '', self.sa)
80 #action_logger(self.rhodecode_user, 'new_user', '', '', self.sa)
76 except formencode.Invalid, errors:
81 except formencode.Invalid, errors:
77 return htmlfill.render(
82 return htmlfill.render(
78 render('admin/users/user_add.html'),
83 render('admin/users/user_add.html'),
79 defaults=errors.value,
84 defaults=errors.value,
80 errors=errors.error_dict or {},
85 errors=errors.error_dict or {},
81 prefix_error=False,
86 prefix_error=False,
82 encoding="UTF-8")
87 encoding="UTF-8")
83 except Exception:
88 except Exception:
84 log.error(traceback.format_exc())
89 log.error(traceback.format_exc())
85 h.flash(_('error occured during creation of user %s') \
90 h.flash(_('error occured during creation of user %s') \
86 % request.POST.get('username'), category='error')
91 % request.POST.get('username'), category='error')
87 return redirect(url('users'))
92 return redirect(url('users'))
88
93
89 def new(self, format='html'):
94 def new(self, format='html'):
90 """GET /users/new: Form to create a new item"""
95 """GET /users/new: Form to create a new item"""
91 # url('new_user')
96 # url('new_user')
92 return render('admin/users/user_add.html')
97 return render('admin/users/user_add.html')
93
98
94 def update(self, id):
99 def update(self, id):
95 """PUT /users/id: Update an existing item"""
100 """PUT /users/id: Update an existing item"""
96 # Forms posted to this method should contain a hidden field:
101 # Forms posted to this method should contain a hidden field:
97 # <input type="hidden" name="_method" value="PUT" />
102 # <input type="hidden" name="_method" value="PUT" />
98 # Or using helpers:
103 # Or using helpers:
99 # h.form(url('user', id=ID),
104 # h.form(url('user', id=ID),
100 # method='put')
105 # method='put')
101 # url('user', id=ID)
106 # url('user', id=ID)
102 user_model = UserModel()
107 user_model = UserModel()
103 c.user = user_model.get(id)
108 c.user = user_model.get(id)
104
109
105 _form = UserForm(edit=True, old_data={'user_id':id,
110 _form = UserForm(edit=True, old_data={'user_id':id,
106 'email':c.user.email})()
111 'email':c.user.email})()
107 form_result = {}
112 form_result = {}
108 try:
113 try:
109 form_result = _form.to_python(dict(request.POST))
114 form_result = _form.to_python(dict(request.POST))
110 user_model.update(id, form_result)
115 user_model.update(id, form_result)
111 h.flash(_('User updated succesfully'), category='success')
116 h.flash(_('User updated succesfully'), category='success')
112
117
113 except formencode.Invalid, errors:
118 except formencode.Invalid, errors:
114 return htmlfill.render(
119 return htmlfill.render(
115 render('admin/users/user_edit.html'),
120 render('admin/users/user_edit.html'),
116 defaults=errors.value,
121 defaults=errors.value,
117 errors=errors.error_dict or {},
122 errors=errors.error_dict or {},
118 prefix_error=False,
123 prefix_error=False,
119 encoding="UTF-8")
124 encoding="UTF-8")
120 except Exception:
125 except Exception:
121 log.error(traceback.format_exc())
126 log.error(traceback.format_exc())
122 h.flash(_('error occured during update of user %s') \
127 h.flash(_('error occurred during update of user %s') \
123 % form_result.get('username'), category='error')
128 % form_result.get('username'), category='error')
124
129
125 return redirect(url('users'))
130 return redirect(url('users'))
126
131
127 def delete(self, id):
132 def delete(self, id):
128 """DELETE /users/id: Delete an existing item"""
133 """DELETE /users/id: Delete an existing item"""
129 # Forms posted to this method should contain a hidden field:
134 # Forms posted to this method should contain a hidden field:
130 # <input type="hidden" name="_method" value="DELETE" />
135 # <input type="hidden" name="_method" value="DELETE" />
131 # Or using helpers:
136 # Or using helpers:
132 # h.form(url('user', id=ID),
137 # h.form(url('user', id=ID),
133 # method='delete')
138 # method='delete')
134 # url('user', id=ID)
139 # url('user', id=ID)
135 user_model = UserModel()
140 user_model = UserModel()
136 try:
141 try:
137 user_model.delete(id)
142 user_model.delete(id)
138 h.flash(_('sucessfully deleted user'), category='success')
143 h.flash(_('sucessfully deleted user'), category='success')
139 except (UserOwnsReposException, DefaultUserException), e:
144 except (UserOwnsReposException, DefaultUserException), e:
140 h.flash(str(e), category='warning')
145 h.flash(str(e), category='warning')
141 except Exception:
146 except Exception:
142 h.flash(_('An error occured during deletion of user'),
147 h.flash(_('An error occured during deletion of user'),
143 category='error')
148 category='error')
144 return redirect(url('users'))
149 return redirect(url('users'))
145
150
146 def show(self, id, format='html'):
151 def show(self, id, format='html'):
147 """GET /users/id: Show a specific item"""
152 """GET /users/id: Show a specific item"""
148 # url('user', id=ID)
153 # url('user', id=ID)
149
154
150
155
151 def edit(self, id, format='html'):
156 def edit(self, id, format='html'):
152 """GET /users/id/edit: Form to edit an existing item"""
157 """GET /users/id/edit: Form to edit an existing item"""
153 # url('edit_user', id=ID)
158 # url('edit_user', id=ID)
154 c.user = self.sa.query(User).get(id)
159 c.user = self.sa.query(User).get(id)
155 if not c.user:
160 if not c.user:
156 return redirect(url('users'))
161 return redirect(url('users'))
157 if c.user.username == 'default':
162 if c.user.username == 'default':
158 h.flash(_("You can't edit this user"), category='warning')
163 h.flash(_("You can't edit this user"), category='warning')
159 return redirect(url('users'))
164 return redirect(url('users'))
160
165
161 defaults = c.user.get_dict()
166 defaults = c.user.get_dict()
162 return htmlfill.render(
167 return htmlfill.render(
163 render('admin/users/user_edit.html'),
168 render('admin/users/user_edit.html'),
164 defaults=defaults,
169 defaults=defaults,
165 encoding="UTF-8",
170 encoding="UTF-8",
166 force_defaults=False
171 force_defaults=False
167 )
172 )
General Comments 0
You need to be logged in to leave comments. Login now