def getPerfil(request): """ gets the UserProfile instance for a user, creates one if it does not exist """ try: perfil = request.user.get_profile() except: perfil = MeuUser(user=request.user) perfil.save() return perfil
def minha_conta(request,template_name="registration/minha_conta.html"): cidades_disponiveis = Localizacao.objects.filter(ativo=True) try: #nome = request.user.username #perfil = profile.getPerfil(request.username) up = MeuUser(username=request.user) nome = up.username print "teste1" except: print "erro" up = MeuUser(username=request.user) up.save() # if request.method == 'POST': # postdata = request.POST.copy() # #form = FormularioRegistro(postdata, instance=perfil) # form = FormularioRegistro(postdata, instance=up) # if form.is_valid(): #profile.setPerfil(request) # form.save() # print "salvou" # else: # up = MeuUser(username=request.user) # #perfil = profile.getPerfil(request) # form = FormularioRegistro(instance=up) # #print perfil # print "teste2" return render_to_response('registration/minha_conta.html', locals(), context_instance = RequestContext(request)) #@login_required #def pedido_info(request, template_name="registration/pedido_info.html"): # """ page containing a form that allows a customer to edit their billing and shipping information that # will be displayed in the order form next time they are logged in and go to check out """ # if request.method == 'POST': # postdata = request.POST.copy() # form = PerfilUsuarioForm(postdata) # if form.is_valid(): # profile.setPerfil(request) # url = urlresolvers.reverse('my_account') # return HttpResponseRedirect(url) # else: # user_profile = profile.getPerfil(request) # form = PerfilUsuarioForm(instance=user_profile) # page_title = 'Edit Order Information' # return render_to_response(template_name, locals(), context_instance=RequestContext(request))
def minha_conta(request, template_name="registration/minha_conta.html"): cidades_disponiveis = Localizacao.objects.filter(ativo=True) try: #nome = request.user.username #perfil = profile.getPerfil(request.username) up = MeuUser(username=request.user) nome = up.username print "teste1" except: print "erro" up = MeuUser(username=request.user) up.save() # if request.method == 'POST': # postdata = request.POST.copy() # #form = FormularioRegistro(postdata, instance=perfil) # form = FormularioRegistro(postdata, instance=up) # if form.is_valid(): #profile.setPerfil(request) # form.save() # print "salvou" # else: # up = MeuUser(username=request.user) # #perfil = profile.getPerfil(request) # form = FormularioRegistro(instance=up) # #print perfil # print "teste2" return render_to_response('registration/minha_conta.html', locals(), context_instance=RequestContext(request)) #@login_required #def pedido_info(request, template_name="registration/pedido_info.html"): # """ page containing a form that allows a customer to edit their billing and shipping information that # will be displayed in the order form next time they are logged in and go to check out """ # if request.method == 'POST': # postdata = request.POST.copy() # form = PerfilUsuarioForm(postdata) # if form.is_valid(): # profile.setPerfil(request) # url = urlresolvers.reverse('my_account') # return HttpResponseRedirect(url) # else: # user_profile = profile.getPerfil(request) # form = PerfilUsuarioForm(instance=user_profile) # page_title = 'Edit Order Information' # return render_to_response(template_name, locals(), context_instance=RequestContext(request))