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)
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, })
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})
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)
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})
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))
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})
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))
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})
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 })
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})
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())
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)
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()