def edit_user(request, user_id): current_user = request.fmsuser users = FMSUser.objects.all() if current_user.organisation: users = users.filter(organisation=current_user.organisation) elif not request.user.is_superuser: raise PermissionDenied() users = users.filter(logical_deleted=False) user_to_edit = users.get(id=user_id) can_edit = current_user.leader and not user_to_edit.leader if request.method == "POST" and can_edit: user_form = FmsUserForm(request.POST, instance=user_to_edit) if user_form.is_valid(): user_form.save() messages.add_message(request, messages.SUCCESS, _("User has been updated successfully")) return HttpResponseRedirect(reverse('list_users')) else: user_form = FmsUserForm(instance=user_to_edit) return render_to_response("pro/auth/user_edit.html", { 'can_edit': can_edit, 'user_form': user_form }, context_instance=RequestContext(request))
def edit_user(request, user_id): current_user = request.fmsuser users = FMSUser.objects.all() if current_user.organisation: users = users.filter(organisation=current_user.organisation) elif not request.user.is_superuser: raise PermissionDenied() users = users.filter(logical_deleted=False) user_to_edit = users.get(id=user_id) can_edit = current_user.leader and not user_to_edit.leader if request.method == "POST" and can_edit: user_form = FmsUserForm(request.POST, instance=user_to_edit) if user_form.is_valid(): user_form.save() messages.add_message(request, messages.SUCCESS, _("User has been updated successfully")) return HttpResponseRedirect(reverse('list_users')) else: user_form = FmsUserForm(instance=user_to_edit) return render_to_response("pro/auth/user_edit.html", { 'can_edit': can_edit, 'user_form': user_form }, context_instance=RequestContext(request))
def test_double_pro_case_insensitive(self): pro_data = { "email" : "*****@*****.**", "last_name": "user", "telephone": "123456789", "quality" : 1 } # Create first pro pro_form = FmsUserForm(pro_data) # Form has to be valid self.assertTrue(pro_form.is_valid()) pro_form.save() # Create second pro with a caps in email pro_data['email'] = pro_data['email'].upper() pro_form = FmsUserForm(pro_data) # Form has to be INVALID because the email is already existing self.assertFalse(pro_form.is_valid()) self.assertTrue(pro_form.errors)
def test_double_pro_case_insensitive(self): pro_data = { "email": "*****@*****.**", "last_name": "user", "telephone": "123456789", "quality": 1 } # Create first pro pro_form = FmsUserForm(pro_data) # Form has to be valid self.assertTrue(pro_form.is_valid()) pro_form.save() # Create second pro with a caps in email pro_data['email'] = pro_data['email'].upper() pro_form = FmsUserForm(pro_data) # Form has to be INVALID because the email is already existing self.assertFalse(pro_form.is_valid()) self.assertTrue(pro_form.errors)