コード例 #1
0
def editar_usuario(request, pk, template_name='usuarios/listar_usuarios.html'):
    u = get_object_or_404(User, pk=pk)
    form = UserForm(request.POST or None, instance=u)
    if request.method == 'POST':
        form.save()
        return redirect('listar_usuarios')
    return render(request, template_name, {'u': u})
コード例 #2
0
ファイル: views.py プロジェクト: RojasJ10/topleague
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))
コード例 #3
0
 def test_usuario_form_nombre_invalido_mensaje(self):
     self.data['username'] = '******'
     form = UserForm(self.data)
     self.assertEqual(form.errors['username'], [
         'El nombre de usuario no sigue el formato' +
         ' solicitado, favor de verificarlo.'
     ])
コード例 #4
0
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))
コード例 #5
0
ファイル: views.py プロジェクト: RojasJ10/topleague
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))
コード例 #6
0
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
        })
コード例 #7
0
def index(request):
    auth_form = AuthenticationForm()
    reg_form = UserForm()
    posts = Post.objects.all()
    argumentos = {
        'title': 'Inicio',
        'auth_form': auth_form,
        'reg_form': reg_form,
        'posts': posts
    }
    return render(request,
                  "base.html",
                  argumentos,
                  context_instance=RequestContext(request))
コード例 #8
0
 def test_usuario_form_email_invalido(self):
     self.data['email'] = 'jasg15_@hotmail'
     form = UserForm(self.data)
     self.assertFalse(form.is_valid())
コード例 #9
0
 def test_usuario_form_password_re_formato_invalido(self):
     self.data['password_re'] = 'jorgeasg'
     form = UserForm(self.data)
     self.assertFalse(form.is_valid())
コード例 #10
0
 def test_usuario_form_password_re_con_espacios(self):
     self.data['password_re'] = 'Jorge123@ '
     form = UserForm(self.data)
     self.assertFalse(form.is_valid())
コード例 #11
0
 def test_usuario_form_password_re_requerido(self):
     self.data['password_re'] = ''
     form = UserForm(self.data)
     self.assertFalse(form.is_valid())
コード例 #12
0
 def test_usuario_form_password_invalido_mensaje(self):
     self.data['password'] = '******'
     form = UserForm(self.data)
     self.assertEqual(form.errors['password'], [PASSWORD_INCORRECTO])
コード例 #13
0
 def test_usuario_form_password_invalido(self):
     self.data['password'] = '******'
     form = UserForm(self.data)
     self.assertFalse(form.is_valid())
コード例 #14
0
 def test_usuario_form_email_invalido_mensaje(self):
     self.data['email'] = 'jasg15_@hotmail'
     form = UserForm(self.data)
     self.assertEqual(form.errors['email'],
                      ['Favor de ingresar un formato de correo válido.'])
コード例 #15
0
 def test_usuario_form_email_vacio_mensaje(self):
     self.data['email'] = ''
     form = UserForm(self.data)
     self.assertEqual(form.errors['email'],
                      ['El correo es requerido, favor de completarlo.'])
コード例 #16
0
 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())
コード例 #17
0
 def test_usuario_form_nombre_vacio_mensaje(self):
     self.data['username'] = ''
     form = UserForm(self.data)
     self.assertEqual(
         form.errors['username'],
         ['El nombre de usuario es requerido, favor de completarlo.'])
コード例 #18
0
 def test_usuario_form_nombre_vacio(self):
     self.data['username'] = ''
     form = UserForm(self.data)
     self.assertFalse(form.is_valid())
コード例 #19
0
 def test_usuario_form_valido(self):
     form = UserForm(self.data)
     self.assertTrue(form.is_valid())
コード例 #20
0
 def test_usuario_form_password_re_min_caracteres(self):
     self.data['password_re'] = 'jor'
     form = UserForm(self.data)
     self.assertFalse(form.is_valid())
コード例 #21
0
 def test_usuario_form_password_re_max_caracteres_mensaje(self):
     self.data['password_re'] = 'jorgeasg' * 7
     form = UserForm(self.data)
     self.assertEqual(form.errors['password_re'], [PASSWORD_INCORRECTO])