예제 #1
0
def new_cliente(request):
    if request.method == 'POST':
        form = ClienteForm(request.POST)
        formpedido = PedidoForm(request.POST)
        if formpedido.is_valid() and form.is_valid():
            cinit = form.cleaned_data['cinit']
            if Cliente.objects.filter(cinit=cinit):
                cliente = Cliente.objects.get(cinit=cinit)
                cliente.razon = form.cleaned_data['razon']
                cliente.telefono = form.cleaned_data['telefono']
                cliente.celular = form.cleaned_data['celular']
                cliente.save()
                admin_log_change(request, cliente, 'Cliente Modificado')
            else:
                cliente = form.save()
                admin_log_addition(request, cliente, 'Cliente Registrado')
            pedido = formpedido.save(commit=False)
            pedido.cliente = cliente
            pedido.save()
            admin_log_addition(request, pedido, 'Pedido Regisrado')
            sms = 'Pedido Registrado Satisfactoriamente'
            messages.success(request, sms)
            return HttpResponseRedirect(
                reverse(new_list_moviles, args={
                    pedido.id,
                }))
    else:
        form = ClienteForm()
        formpedido = PedidoForm()
    return render(request, 'pedidos/new_cliente.html', {
        'form': form,
        'formpedido': formpedido,
    })
예제 #2
0
def deactivate_cliente(request, cliente_id):
    cliente = get_object_or_404(Cliente, pk=cliente_id)
    cliente.estado = False
    cliente.save()
    admin_log_change(request, cliente, 'Cliente Desactivado')
    messages.error(request, 'Cliente %s Desactivado' % cliente.razon, 'danger')
    return HttpResponseRedirect(reverse(index_clientes))
예제 #3
0
def activate_cliente(request, cliente_id):
    cliente = get_object_or_404(Cliente, pk=cliente_id)
    cliente.estado = True
    cliente.save()
    admin_log_change(request, cliente, 'Cliente Activado')
    messages.success(request, 'Cliente %s Activado' % cliente.razon)
    return HttpResponseRedirect(reverse(index_clientes))
예제 #4
0
def conductor_update(request, user_id):
    user = get_object_or_404(User, pk=user_id)
    perfil = Perfil.objects.get(user=user)
    conductor = Conductor.objects.get(user=user)
    if request.method == 'POST':
        form = ConductorForm(request.POST, instance=conductor)
        formperfil = PerfilForm(request.POST, instance=perfil)
        formuser = UserForm(request.POST, instance=user)
        if form.is_valid() and formperfil.is_valid() and formuser.is_valid():
            formuser.save()
            perfil = formperfil.save()
            conductor = form.save()
            messages.warning(request, 'Conductor Modificado Correctamente')
            admin_log_change(request, perfil, 'Perfil Conductor Modificado')
            admin_log_change(request, conductor, 'Conductor Modificado')
            return HttpResponseRedirect(reverse(conductor_index))
    else:
        form = ConductorForm(instance=conductor)
        formperfil = PerfilForm(instance=perfil)
        formuser = UserForm(instance=user)
    return render(request, 'conductores/update.html', {
        'formperfil': formperfil,
        'formuser': formuser,
        'form': form,
    })
예제 #5
0
def update_cliente(request, cliente_id):
    cliente = get_object_or_404(Cliente, pk=cliente_id)
    if request.method == 'POST':
        form = ClienteForm(request.POST, instance=cliente)
        if form.is_valid():
            cliente = form.save()
            admin_log_change(request, cliente, 'Cliente Modificado')
            messages.warning(request, 'Cliente %s Modificado Correctamete')
            return HttpResponseRedirect(reverse(index_clientes))
    else:
        form = ClienteForm(instance=cliente)
    return render(request, 'clientes/update.html', {
        'form': form,
    })
예제 #6
0
def update_information(request):
    if request.method == 'POST':
        form = UserForm(request.POST, instance=request.user)
        formperfil = PerfilForm(request.POST, instance=request.user.perfil)
        if form.is_valid() and formperfil.is_valid():
            user = form.save()
            perfil = formperfil.save(commit=False)
            perfil.user = user
            perfil.save()
            admin_log_change(request, user, 'Datos modificados')
            admin_log_addition(request, perfil, 'Perfil modificado')
            messages.info(request, 'Perfil Modificado Correctamente')
            return HttpResponseRedirect(reverse(user_index))
    else:
        form = UserForm(instance=request.user)
        formperfil = PerfilForm(instance=request.user.perfil)
    return render(request, 'users/complete_information.html', {
        'form': form,
        'formperfil': formperfil,
    })