Пример #1
0
def salvar(request, id=None):
    dados = {}

    form = ClienteForm(request.POST or None)
    formEndereco = EnderecoForm(request.POST or None)

    if form.is_valid() and formEndereco.is_valid():
        cliente = form.save(commit=False)

        if id not in (None, '0'):
            cliente.id = id
            cliente.data_cadastro = Cliente.objects.get(id=id).data_cadastro

        cliente.endereco = formEndereco.save()

        empresa = Funcionario.objects.get(usuario=request.user).empresa
        cliente.empresa = empresa
        cliente.ativo = True
        cliente.save()
        mensagem = 'Cliente salvo com sucesso!'
        return detalhe(request, cliente.id, mensagem)
    else:
        dados['form'] = form
        dados['formEndereco'] = formEndereco
        dados['erros'] = form.errors
        return render(request, template_novo, dados)
Пример #2
0
def cliente_cadastro(request):
    if request.method == 'POST':  # If the form has been submitted...
        form = ClienteForm(request.POST)  # A form bound to the POST data

        u = User()
        u.username = request.POST.get('cpf')
        u.password = request.POST.get('senha')
        u.nome = request.POST.get('nome')

        u.save()
        #u = User.Objects.all().order_by('-id')[:1]
        print "####"
        print u

        if form.is_valid():  # All validation rules pass
            form.instance.user = u
            form.save()
            print "######"
            print u
            print "######"
            #form.instance.user.add(u) #nne add
            #return HttpResponseRedirect('pagamento.html') # Redirect after POST
            return HttpResponse("Dados cadastrados com sucesso!")
            return HttpResponseRedirect('pagamento.html')
        else:
            return HttpResponse(form.errors)

    else:
        form = ClienteForm()  # An unbound form

    return render(request, 'cadastro.html', {
        'form': form,
    })
Пример #3
0
def buscarDNI(request):

    existe = "inicio"
    guardac = ""
    
    if "paraCliente" in request.POST:

        cliente = ClienteForm(request.POST)
        if cliente.is_valid(): # All validation rules pass
            try:
                cliente.save()
                guardac = cliente.cli_id
                return reservar(request, guardac)
            except:
                return HttpResponseRedirect('/buscarc/')
        else:
            print("no se guardo")
    else:
        cliente = ClienteForm()

    if "paraDNI" in request.POST:
        dni = request.POST['dni']
        try:
            existe = Cliente.objects.get(cli_dni=dni)
            guardac = existe.cli_id;
            return reservar(request, guardac)
        except Cliente.DoesNotExist:
            existe = None
    
    return render(request, 'commerce/Reserva/generarReserva.html', {'existe':existe,'cliente':cliente})
Пример #4
0
def create(request):
    form = ClienteForm(request.POST or None)

    if request.method == 'POST' and form.is_valid():
        form.save()
        return HttpResponseRedirect('/clientes/')

    context = RequestContext(request, {'form': form})
    return render_to_response('cliente/create.html', context)
Пример #5
0
def CadastraCliente(request):
	if request.method == 'POST':
		form = ClienteForm(request.POST)
		if form.is_valid():
			form.save()
			return redirect('cadastraVeiculo')
	else:
		form = ClienteForm()
	return render(request,"Parking/cadastracliente.html",{'form':form})
Пример #6
0
def new_cliente(request):
	if request.method=="POST":
		form=ClienteForm(request.POST)
		if form.is_valid():
			form.save()
			return HttpResponseRedirect('/new_venta/')
	else:
		form=ClienteForm()
	return render_to_response('cliente.html',{'cliente':form},context_instance = RequestContext(request))
Пример #7
0
def create(request):
	form = ClienteForm(request.POST or None)
	
	if request.method == 'POST' and form.is_valid():
		form.save()
		return HttpResponseRedirect('/clientes/')

	context = RequestContext(request, {'form': form})
	return render_to_response('cliente/create.html', context)
Пример #8
0
def fCliente(request):
    if request.method == 'POST':
        form = ClienteForm(request.POST) 
        if form.is_valid():
            form.save()
            return redirect('Clientes')
    else:
        form = ClienteForm() 
    return render(request,"form.html",{'form':form, 'contexto':CONTEXT_CLI})
Пример #9
0
def new_cliente(request):
    if request.method == "POST":
        form = ClienteForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/new_venta/')
    else:
        form = ClienteForm()
    return render_to_response('cliente.html', {'cliente': form},
                              context_instance=RequestContext(request))
Пример #10
0
def eCliente(request,id=None):
	obj = get_object_or_404(Cliente, pk=id)
	if request.method == 'POST':
		form = ClienteForm(request.POST, instance=obj) 
		if form.is_valid():
			form.save()
			return redirect('Clientes')
	else:	
		form = ClienteForm(instance=obj) 
	return render(request,"form.html",{'form':form})
Пример #11
0
def cadcliente(request):
    if request.method == 'POST':
      form = ClienteForm(request.POST)
    
      if form.is_valid():
          form.save()
          return redirect('cadcliente')
    else:
       form = ClienteForm()
    
    return render(request,'acesso/cadcliente.html',{'form' : form })
Пример #12
0
def AlteraCliente(request,codigo=None):
	objeto = get_object_or_404(cliente,pk=codigo)

	if request.method =='POST':
		form = ClienteForm(request.POST,instance=objeto)

		if form.is_valid():
			form.save()
			return redirect('listacliente')
		else:
			form = ClienteForm(instance=objeto)
			return render(request,"Parking/alteracliente.html",{'form':form})
Пример #13
0
def cadastro(request):    
    if request.method =='POST':
        form = ClienteForm(request.POST)
        if form.is_valid():
            cli = form.save()
            messages.success(request, 'O seu cadastro foi efetuado com sucesso')
            request.session["id_cliente"] = cli.id
            return redirect('/')
        else:
            messages.error(request, u'Existem erros de preenchimento no formulário.')
    else:
        form = ClienteForm()
    return render(request, 'clientes/cadastro.html', locals())
Пример #14
0
def update(request, id):
    cliente = Cliente.objects.get(pk=id)

    if request.method == 'POST':
        form = ClienteForm(request.POST, instance=cliente)

        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/clientes/')

    else:
        form = ClienteForm(instance=cliente)

    context = RequestContext(request, {'form': form, 'id': id})
    return render_to_response('cliente/update.html', context)
Пример #15
0
def update(request, id):
	cliente = Cliente.objects.get(pk=id)
	
	if request.method == 'POST':
		form = ClienteForm(request.POST, instance=cliente)

		if form.is_valid():
			form.save()
			return HttpResponseRedirect('/clientes/')

	else:
		form = ClienteForm(instance=cliente)
		
	context = RequestContext(request, {'form': form, 'id': id})
	return render_to_response('cliente/update.html', context)	
Пример #16
0
 def add_cliente(self,request):
     print request.POST
     if request.method == "POST" :
         form = ClienteForm(request.POST)
         if form.is_valid() :
             username = form.cleaned_data['username']
             password = form.cleaned_data['password_one']
             email = form.cleaned_data['email']
             u = User.objects.create_user(username=username, email=email,
                                          password=password)
             u.set_password(raw_password=password)
             u.is_active = True
             u.save()
             cli = Cliente(usuario=u)
             cli.save()
             return True,[username,password]
         #end if
         return False,form
     #end if
     return False,ClienteForm()