def user_create(request): profile = UserProfile(user=User()) form = UserForm(request.POST or None, instance=profile) if form.is_valid(): form.save() messages.success(request, _("Successfully created user.")) return redirect('evap.fsr.views.user_index') else: return render_to_response("fsr_user_form.html", dict(form=form), context_instance=RequestContext(request))
def user_edit(request, user_id): user = get_object_or_404(User, id=user_id) form = UserForm(request.POST or None, request.FILES or None, instance=UserProfile.get_for_user(user)) if form.is_valid(): form.save() messages.success(request, _("Successfully updated user.")) return redirect('evap.fsr.views.user_index') else: return render_to_response("fsr_user_form.html", dict(form=form, object=user), context_instance=RequestContext(request))
def test_user_form(self): """ Tests the UserForm with one valid and one invalid input dataset. """ userprofile = UserProfile.objects.get(pk=1) another_userprofile = UserProfile.objects.get(pk=2) data = {"username": "******", "email": "*****@*****.**"} form = UserForm(instance=userprofile, data=data) self.assertTrue(form.is_valid()) data = {"username": another_userprofile.user.username, "email": "[email protected]"} form = UserForm(instance=userprofile, data=data) self.assertFalse(form.is_valid())
def user_edit(request, user_id): user = get_object_or_404(User, id=user_id) form = UserForm(request.POST or None, request.FILES or None, instance=user.get_profile()) if form.is_valid(): form.save() messages.add_message(request, messages.INFO, _("Successfully updated user.")) if "filter" in request.GET: return custom_redirect('evap.fsr.views.user_index', filter=request.GET['filter']) else: return redirect('evap.fsr.views.user_index') else: return render_to_response("fsr_user_form.html", dict(form=form, object=user), context_instance=RequestContext(request))
def user_edit(request, user_id): user = get_object_or_404(User, id=user_id) form = UserForm(request.POST or None, request.FILES or None, instance=UserProfile.get_for_user(user)) if form.is_valid(): form.save() messages.add_message(request, messages.INFO, _("Successfully updated user.")) if "filter" in request.GET: return custom_redirect('evap.fsr.views.user_index', filter=request.GET['filter']) else: return redirect('evap.fsr.views.user_index') else: return render_to_response("fsr_user_form.html", dict(form=form, object=user), context_instance=RequestContext(request))
def user_create(request): profile = UserProfile(user=User()) form = UserForm(request.POST or None, instance=profile) if form.is_valid(): #profile.user.save() form.save() messages.add_message(request, messages.INFO, _("Successfully created user.")) if "filter" in request.GET: return custom_redirect('evap.fsr.views.user_index', filter=request.GET['filter']) else: return redirect('evap.fsr.views.user_index') else: return render_to_response("fsr_user_form.html", dict(form=form), context_instance=RequestContext(request))