def post(self): id = self.get_argument("id-contacto", "") name = self.get_argument("name", "") address = self.get_argument("address", "") town = self.get_argument("town", "") city = self.get_argument("city", "") zip_code = self.get_argument("zip_code", "") telephone = self.get_argument("telephone", "") contacto = Contact() res_contact = contacto.InitById(id) if "success" in res_contact: datos = res_contact["success"] contacto.initialize(datos) contacto.name = name contacto.address = address contacto.town = town contacto.city = city contacto.zip_code = zip_code contacto.telephone = telephone ciudad = City() res_city = ciudad.getNameById(city) if "success" in res_city: contacto.Edit() self.write(json_util.dumps(res_city))
def test_insert_order(self): user = User() user.name = 'Yi Chun' user.email = '*****@*****.**' user.user_type = 'Visita' user.Save() contact = Contact() contact.user_id = user.id contact.name = 'Casa' contact.telephone = '123456' contact.email = '*****@*****.**' contact.user_id = user.id contact.address = 'some address' contact.lastname = 'lin' contact.city = 1 contact.zip_code = '734628347632' contact.additional_info = 'skjahjdahk' contact.town = 'sadjahsdkjah' contact.rut = '35172617356' contact.Save() # create a new user instance order = Order() order.date = datetime.now(pytz.timezone('Chile/Continental')).isoformat() order.type = Order.TIPO_WEB order.subtotal = 20000 order.shipping = 2000 order.tax = 0 order.total = 22000 order.items_quantity = 1 order.products_quantity = 1 order.user_id = user.id order.billing_id = contact.id order.shipping_id = contact.id order.payment_type = 1 order.voucher = "image.png" order.state = Order.ESTADO_PENDIENTE res = order.Save() print order.date self.assertTrue('success' in res)
def post(self): name = self.get_argument("name", "") lastname = self.get_argument("lastname", "") email = self.get_argument("email", "") rut = self.get_argument("rut", "") address = self.get_argument("address", "") town = self.get_argument("town", "") city = self.get_argument("city_id", "") zip_code = self.get_argument("zip_code", "") additional_info = self.get_argument("additional_info", "") telephone = self.get_argument("telephone", "") if self.current_user: user_id = self.current_user["id"] contacto = Contact() contacto.name = name contacto.lastname = lastname contacto.email = email contacto.rut = rut contacto.address = address contacto.town = town contacto.city = city contacto.zip_code = zip_code contacto.additional_info = additional_info contacto.telephone = telephone contacto.user_id = user_id response = contacto.Save() if "success" in response: id = response["success"] res_contact = contacto.InitById(id) if "success" in res_contact: datos = res_contact["success"] self.write( self.render_string("profile/nuevafila.html", id=id, contacto=datos))
def post(self): if self.current_user: costo_despacho = int(self.get_argument("shipping_price", 0)) user_id = self.current_user["id"] nombre = self.get_argument("name", self.current_user["name"]) apellido = self.get_argument("lastname", self.current_user["lastname"]) email = self.get_argument("email", self.current_user["email"]) direccion = self.get_argument("address", "") ciudad = self.get_argument("city_id", "") codigo_postal = self.get_argument("zip_code", "") informacion_adicional = self.get_argument("additional_info", "") telefono = self.get_argument("telephone", "") id_contacto = self.get_argument("contact_id", "") misma_direccion = self.get_argument("same_address", "") comuna = self.get_argument("town", "") rut = self.get_argument("rut", "") shipping_type = self.get_argument("shipping_type", 1) post_office_id = self.get_argument("post_office_id", "") cart = Cart() cart.user_id = user_id lista = cart.GetCartByUserId() if len(lista) <= 0: self.render("beauty_error.html", message="Carro está vacío") if misma_direccion != "on": contact = Contact() contact.name = nombre contact.lastname = apellido contact.telephone = telefono contact.email = email contact.address = direccion contact.city = ciudad contact.zip_code = codigo_postal contact.user_id = user_id contact.additional_info = informacion_adicional contact.town = comuna contact.rut = rut operacion = "" if id_contacto != "": contact.id = id_contacto response_obj = contact.Edit() operacion = "editar" else: response_obj = contact.Save() operacion = "guardar" if "error" in response_obj: self.render("beauty_error.html", message="Error al {} contacto {}".format( operacion, response_obj["error"])) else: suma = 0 for l in lista: c = Cart() c.InitById(l["id"]) c.billing_id = contact.id c.billing_info = contact.additional_info c.Edit() suma += l["subtotal"] # self.render("store/checkout-2.html",contactos=contactos,data=lista,suma=suma,selected_address=direccion) if self.current_user['type_id'] == User().getUserTypeID( UserType.EMPRESA): self.render("wholesaler/checkout-4.html", data=lista, suma=suma, iva=iva) else: self.render("store/checkout-3.html", data=lista, suma=suma, costo_despacho=costo_despacho, shipping_type=shipping_type, post_office_id=post_office_id) else: contact = Contact() cart = Cart() cart.user_id = user_id lista = cart.GetCartByUserId() billing_info = '' suma = 0 try: billing_info = contact.getAdditionalInfo( c.shipping_id)['success'] except: pass for l in lista: c = Cart() c.InitById(l["id"]) c.billing_info = billing_info c.billing_id = c.shipping_id c.Edit() suma += l["subtotal"] if self.current_user['type_id'] == User().getUserTypeID( UserType.EMPRESA): self.render("wholesaler/checkout-4.html", data=lista, suma=suma, iva=iva) else: self.render("store/checkout-3.html", data=lista, suma=suma, costo_despacho=costo_despacho, shipping_type=shipping_type, post_office_id=post_office_id) else: self.redirect("/auth/login")
def get(self): if self.current_user: user_id = self.current_user["id"] nombre = self.get_argument("name", self.current_user["name"]) apellido = self.get_argument("lastname", self.current_user["lastname"]) email = self.get_argument("email", self.current_user["email"]) direccion = self.get_argument("address", "") ciudad = self.get_argument("city_id", "") codigo_postal = self.get_argument("zip_code", "") informacion_adicional = self.get_argument("additional_info", "") telefono = self.get_argument("telephone", "") id_contacto = self.get_argument("contact_id", "") comuna = self.get_argument("town", "") rut = self.get_argument("rut", "") shipping_type = self.get_argument("shipping_type", "") post_office_id = self.get_argument("post_office_id", "") shipping_type_id = 1 cart = Cart() cart.user_id = user_id lista = cart.GetCartByUserId() if len(lista) <= 0: self.render("beauty_error.html", message="Carro está vacío") contact = Contact() contact.name = nombre contact.lastname = apellido contact.telephone = telefono contact.email = email contact.address = direccion if shipping_type == "chilexpress": po = PostOffice() po.InitById(post_office_id) post_office_name = po.name contact.address = "Oficina {}".format(post_office_name) contact.city = ciudad contact.zip_code = codigo_postal contact.user_id = user_id contact.additional_info = informacion_adicional contact.town = comuna contact.rut = rut operacion = "" if id_contacto != "": contact.id = id_contacto response_obj = contact.Edit() operacion = "editar" else: response_obj = contact.Save() operacion = "guardar" if "error" in response_obj: self.render("beauty_error.html", message="Error al {} contacto {}".format( operacion, response_obj["error"])) else: items = 0 suma = 0 for l in lista: c = Cart() response_obj = c.InitById(l["id"]) if "success" in response_obj: c.shipping_id = contact.id c.shipping_info = contact.additional_info c.Edit() else: print response_obj["error"] suma += l["subtotal"] items += l["quantity"] contactos = [] cities = [] response_obj = contact.ListByUserId(user_id) city = City() res_city = city.List() if "success" in response_obj: contactos = json_util.loads(response_obj["success"]) if "success" in res_city: cities = res_city["success"] c = Cellar() res_cellar_id = c.GetWebCellar() web_cellar_id = cellar_id if "success" in res_cellar_id: web_cellar_id = res_cellar_id["success"] res_web_cellar = c.InitById(web_cellar_id) if "success" in res_web_cellar: if shipping_type != "chilexpress": cellar_city_id = c.city_id shipping = Shipping() shipping.from_city_id = int(cellar_city_id) shipping.to_city_id = int(ciudad) res = shipping.GetGianiPrice() if "error" in res: self.render( "beauty_error.html", message="Error al calcular costo de despacho, {}" .format(res["error"])) else: shipping_type_id = 2 shipping = Shipping() shipping.post_office_id = post_office_id res = shipping.GetPriceByPostOfficeId() if "error" in res: self.render( "beauty_error.html", message= "Error al calcular costo de despacho de Chilexpress, {}" .format(res["error"])) else: if shipping.charge_type == 1: costo_despacho = shipping.price * items else: costo_despacho = shipping.price self.render("store/checkout-2.html", contactos=contactos, data=lista, suma=suma, selected_address=direccion, cities=cities, costo_despacho=costo_despacho, shipping_type=shipping_type_id, post_office_id=post_office_id) else: self.redirect("/auth/login")
def post(self): nombre = self.get_argument("name", "") giro = self.get_argument("bussiness", "") rut = self.get_argument("rut", "") email = self.get_argument("email", "") direccion = self.get_argument("address", "") region = self.get_argument("state", "") provincia = self.get_argument("city", "") comuna = self.get_argument("town", "") clave = self.get_argument("password", "") rep_clave = self.get_argument("re-password", "") rut = re.sub(r'\.+|-+', "", rut).lower() if nombre.strip() == "": self.write( json_util.dumps({ "state": 0, "message": "Debe ingresar nombre" })) return elif giro.strip() == "": self.write( json_util.dumps({ "state": 0, "message": "Debe ingresar giro" })) return elif rut.strip() == "": self.write( json_util.dumps({ "state": 0, "message": "Debe ingresar rut" })) return elif not valida(rut): self.write( json_util.dumps({ "state": 0, "message": "Rut ingresado no es válido" })) return elif email.strip() == "": self.write( json_util.dumps({ "state": 0, "message": "Debe ingresar email" })) return elif not isEmailValid(email): self.write( json_util.dumps({ "state": 0, "message": "Email ingresado no es válido" })) return elif direccion.strip( ) == "" or region == "" or provincia == "" or comuna == "": self.write( json_util.dumps({ "state": 0, "message": "Debe ingresar su dirección completa" })) return elif clave.strip() == "": self.write( json_util.dumps({ "state": 0, "message": "Debe ingresar clave" })) return elif rep_clave.strip() != clave.strip(): self.write( json_util.dumps({ "state": 0, "message": "Las claves ingresadas no coinciden" })) return user = User() user.name = nombre user.password = clave user.email = email user.user_type = UserType.EMPRESA user.bussiness = giro user.rut = rut user.status = User.PENDIENTE res_save = user.Save() user_id = None if "error" in res_save: # self.write(json_util.dumps(res_save)) # return self.write( json_util.dumps({ "state": 0, "message": "error de registro {}".format(res_save["error"]) })) return else: user_id = res_save["success"] city_id = None city = City() res_city = city.getIdByName(comuna) if "success" in res_city: city_id = res_city["success"] contact = Contact() contact.town = "{}, {}".format(comuna.encode("utf-8"), region.encode("utf-8")) contact.address = direccion contact.user_id = user_id contact.city = city_id try: html = self.generateMail("registro_mayorista.html", name=nombre.encode('utf-8'), bussiness=giro.encode('utf-8'), email=email.encode('utf-8'), address=direccion.encode('utf-8'), state=region.encode('utf-8'), city=provincia.encode('utf-8'), town=comuna.encode('utf-8'), rut=rut, url_local=url_local) sg = sendgrid.SendGridClient(sendgrid_user, sendgrid_pass) mensaje = sendgrid.Mail() mensaje.set_from("{nombre} <{mail}>".format(nombre=nombre, mail=email)) mensaje.add_to(to_giani) mensaje.set_subject("Registro Mayorista GDF") mensaje.set_html(html) status, msg = sg.send(mensaje) # print status except Exception, e: print str(e) try: html = self.generateMail("registro_mayorista_cliente.html", name=nombre.encode('utf-8')) sg = sendgrid.SendGridClient(sendgrid_user, sendgrid_pass) mensaje = sendgrid.Mail() mensaje.set_from("{nombre} <{mail}>".format( nombre='Giani Da Firenze', mail=email_giani)) mensaje.add_to(email) mensaje.set_subject("Registro Mayorista GDF") mensaje.set_html(html) status, msg = sg.send(mensaje) # print msg except Exception, e: print str(e)