def registro(request): registered = False if request.method == "POST": user_form = UserForm(data=request.POST) profile_form = InfoExtraUsuarioForm(data=request.POST) if user_form.is_valid() and profile_form.is_valid(): user = user_form.save() user.set_password(user.password) user.save() profile = profile_form.save(commit=False) profile.user = user profile.save() registered = True else: print(user_form.errors, profile_form.errors) else: user_form = UserForm() profile_form = InfoExtraUsuarioForm() return render( request, 'usuarios/registro.html', { 'user_form': user_form, 'profile_form': profile_form, 'registered': registered })
def editar_perfil(request): if request.method == 'POST': user_form = UserForm(request.POST, instance=request.user) if user_form.is_valid(): user_form.save() return HttpResponseRedirect('/privado') else: user_form = UserForm(instance=request.user) return render_to_response('editar_perfil.html', { 'user_form': user_form }, context_instance=RequestContext(request))
def editar_perfil(request): if request.method == 'POST': user_form = UserForm(request.POST, instance=request.user) if user_form.is_valid(): user_form.save() return HttpResponseRedirect('/privado') else: user_form = UserForm(instance=request.user) return render_to_response('editar_perfil.html', {'user_form': user_form}, context_instance=RequestContext(request))
def modificar_datos_usuario(request): if request.method == "GET": user_form = UserForm(instance=request.user) return render_to_response('usuarios/modificar_datos_usuario.html', { 'user_form': user_form }, context_instance=RequestContext(request)) else: u= request.user user_form = UserForm(request.POST, instance=request.user) if user_form.is_valid(): u.first_name=user_form.cleaned_data['first_name'] u.last_name=user_form.cleaned_data['last_name'] u.email=user_form.cleaned_data['email'] u.dni = user_form.cleaned_data['dni'] u.save() messages.success(request,"Perfil Actualizado Exitosamente") return render_to_response('usuarios/modificar_datos_usuario.html', { 'user_form': user_form }, context_instance=RequestContext(request)) else: user_form = UserForm(instance=request.user) return render_to_response('usuarios/modificar_datos_usuario.html', { 'user_form': user_form}, context_instance=RequestContext(request))
def test_usuario_form_password_re_formato_invalido(self): self.data['password_re'] = 'jorgeasg' form = UserForm(self.data) self.assertFalse(form.is_valid())
def test_usuario_form_password_re_con_espacios(self): self.data['password_re'] = 'Jorge123@ ' form = UserForm(self.data) self.assertFalse(form.is_valid())
def test_usuario_form_password_re_requerido(self): self.data['password_re'] = '' form = UserForm(self.data) self.assertFalse(form.is_valid())
def test_usuario_form_password_invalido(self): self.data['password'] = '******' form = UserForm(self.data) self.assertFalse(form.is_valid())
def test_usuario_form_email_invalido(self): self.data['email'] = 'jasg15_@hotmail' form = UserForm(self.data) self.assertFalse(form.is_valid())
def test_usuario_form_nombre_vacio(self): self.data['username'] = '' form = UserForm(self.data) self.assertFalse(form.is_valid())
def test_usuario_form_valido(self): form = UserForm(self.data) self.assertTrue(form.is_valid())
def test_usuario_form_password_re_min_caracteres(self): self.data['password_re'] = 'jor' form = UserForm(self.data) self.assertFalse(form.is_valid())
def test_usuario_form_password_re_diferente_a_password(self): self.data['password'] = '******' self.data['password_re'] = 'Inventors124@' form = UserForm(self.data) self.assertFalse(form.is_valid())