def test_email(self): #Test no repetir email form_data = self.form_data.copy() form_data['email'] = "*****@*****.**" form = UserCreateForm( data=form_data) self.assertEqual(form.is_valid(), False)
def test_password(self): #Password no coinciden form_data = self.form_data.copy() form_data['password1'] = "u1234" form = UserCreateForm( data=form_data) self.assertEqual(form.is_valid(), False)
def test_usuario(self): #Test usuario no repetir form_data = self.form_data.copy() form_data['username'] = "******" form = UserCreateForm( data=form_data) self.assertEqual(form.is_valid(), False)
def test_ok(self): #Test con data OK form_data = self.form_data.copy() form_data['username'] = '******' form_data['email'] = '*****@*****.**' form = UserCreateForm( data=form_data) self.assertEqual(form.is_valid(), True)
def newuser(request): if request.method == 'POST': formulario = UserCreateForm(request.POST) if formulario.is_valid: message1 = "Usuario registrado correctamente" formulario.save() formulario = UserCreateForm(); return render_to_response('usuarios/new_user.html',{'formulario':formulario,'message1':message1},context_instance = RequestContext(request)) else: formulario = UserCreateForm(); return render_to_response('usuarios/new_user.html',{'formulario':formulario},context_instance = RequestContext(request))
def registra(request): output = {} if request.method == 'POST': form_reg = UserCreateForm(data=request.POST) if form_reg.is_valid(): username = request.POST.get('username') email = request.POST.get('email') password = request.POST.get('password1') userDB = User.objects.create_user(username, email, password) userDB.save() access = authenticate(username=username, password=password) login(request, access) return HttpResponseRedirect('/usuario/escritorio/') else: output['errors'] = 'Ha ocurrido un error favor de revisar el formulario' else: form_reg = UserCreateForm() output['usuario_registra'] = form_reg return render(request, "usuarios/registra.html", output)
def newuser(request): if request.method == 'POST': formulario = UserCreateForm(request.POST) if formulario.is_valid: message1 = "Usuario registrado correctamente" formulario.save() formulario = UserCreateForm() return render_to_response('usuarios/new_user.html', { 'formulario': formulario, 'message1': message1 }, context_instance=RequestContext(request)) else: formulario = UserCreateForm() return render_to_response('usuarios/new_user.html', {'formulario': formulario}, context_instance=RequestContext(request))
def usuario_nuevo(request): if request.method == 'POST': formulario = UserCreateForm() if formulario.is_valid: formulario.save() formulario = UserCreateForm() return HttpResponseRedirect('/definir/usuarios/lista/') else: formulario_user = UserCreateForm() formulario_perfil = PerfilForm() message = "Si estan pasando" return render_to_response('usuarios/perfil.html', { 'formulario': formulario_perfil, 'formulario1': formulario_user, 'message': message }, context_instance=RequestContext(request))