def remove_user(request, user_id): if str(user_id) == str(request.user.id): return HttpResponseRedirect(reverse('sentry-admin-users')) try: user = User.objects.get(pk=user_id) except User.DoesNotExist: return HttpResponseRedirect(reverse('sentry-admin-users')) form = RemoveUserForm(request.POST or None) if form.is_valid(): if form.cleaned_data['removal_type'] == '2': user.delete() else: User.objects.filter(pk=user.pk).update(is_active=False) return HttpResponseRedirect(reverse('sentry-admin-users')) context = csrf(request) context.update({ 'form': form, 'the_user': user, }) return render_to_response('sentry/admin/users/remove.html', context, request)