fix user status view (activate, deactivate user without js)

This commit is contained in:
Oskar Hahn 2014-03-30 10:54:09 +02:00
parent 7addd69050
commit 3b65e89f7c
2 changed files with 8 additions and 3 deletions

View File

@ -147,13 +147,14 @@ class UserDeleteView(DeleteView):
super(UserDeleteView, self).pre_post_redirect(request, *args, **kwargs) super(UserDeleteView, self).pre_post_redirect(request, *args, **kwargs)
class SetUserStatusView(RedirectView, SingleObjectMixin): class SetUserStatusView(SingleObjectMixin, RedirectView):
""" """
Activate or deactivate an user. Activate or deactivate an user.
""" """
permission_required = 'participant.can_manage_participant' permission_required = 'participant.can_manage_participant'
allow_ajax = True allow_ajax = True
url_name = 'user_overview' url_name = 'user_overview'
url_name_args = []
model = User model = User
def pre_redirect(self, request, *args, **kwargs): def pre_redirect(self, request, *args, **kwargs):
@ -164,7 +165,7 @@ class SetUserStatusView(RedirectView, SingleObjectMixin):
elif action == 'deactivate': elif action == 'deactivate':
if self.object.user == self.request.user: if self.object.user == self.request.user:
messages.error(request, _("You can not deactivate yourself.")) messages.error(request, _("You can not deactivate yourself."))
return else:
self.object.is_active = False self.object.is_active = False
elif action == 'toggle': elif action == 'toggle':
self.object.is_active = not self.object.is_active self.object.is_active = not self.object.is_active

View File

@ -40,6 +40,10 @@ class UserViews(TestCase):
'is_active': 'yes'}) 'is_active': 'yes'})
self.assertRedirects(response, '/participant/') self.assertRedirects(response, '/participant/')
def test_activate(self):
response = self.client.get('/participant/1/status/activate/')
self.assertEqual(response.status_code, 302)
class GroupViews(TestCase): class GroupViews(TestCase):
""" """