def test_crud(self): with self.app_context(): address = "200 University Ave W, Waterloo, ON N2L 3G1" latitude = 43.4717512 longitude = -80.5459129 geo = "POINT({} {})".format(longitude, latitude) phone = "123456789" fax = "123456789" is_wheelchair_accessible = True is_accepting_new_patients = True start_hour = datetime.strptime( "08:00", '%H:%M').time() end_hour = datetime.strptime( "08:00", '%H:%M').time() address = AddressModel(address=address, latitude=latitude, longitude=longitude, geo=geo, phone=phone, fax=fax, is_wheelchair_accessible=is_wheelchair_accessible, is_accepting_new_patients=is_accepting_new_patients, start_hour=start_hour, end_hour=end_hour) self.assertIsNone(AddressModel.find_by_id( 1), "Found a user with address '1' before save_to_db") address.save_to_db() self.assertIsNotNone(AddressModel.find_by_id( 1), "Did not find a address with id '1' after save_to_db")
def get(self, address_id: int): """ This endpoint returns the requested image if exists. It will use JWT to retrieve user information and look for the image inside the user's folder. """ address = AddressModel.find_by_id(address_id) fulladdress = AddressModel.find_by_fulladdress() if not address: return {"message": gettext("user_not_found")}, 404 return fulladdress, 200
def get(self, account_id, idd): account = AccountModel.find_by_id(account_id) address = AddressModel.find_by_id(idd) if address is not None and account is not None: if address in account.addresses: return {'address': address.json()}, 200 return { 'message': "This account doesn't have an address with id [{}] ".format( idd) }, 409 return {'message': "Address with id [{}] Not found".format(idd)}, 404
def delete(self, account_id, idd): account = AccountModel.find_by_id(account_id) address = AddressModel.find_by_id(idd) if address is not None and account is not None: if address in account.addresses: address.delete_from_db() return {"Message": "Address deleted correctly"}, 200 return { 'message': "This account doesn't have an address with id [{}] ".format(id) }, 409 elif address is None: return { 'message': "Address with id [{}] Not found".format(id) }, 404
def json(self): articles_json = [article.json() for article in self.articles] card = CardModel.find_by_id(self.card_id) address = AddressModel.find_by_id(self.address_id) return { "id": self.id, "id_user": self.id_user, "date": self.date, "total": self.total, "shipping": self.shipping, "taxes": self.taxes, "state": self.state, "send_type": self.send_type, "card": card.json(), "address": address.json(), "articles": articles_json, }
def put(self, account_id, idd): account = AccountModel.find_by_id(account_id) address = AddressModel.find_by_id(idd) if address is not None and account is not None: if address not in account.addresses: return { 'message': "This account doesn't have an address with id [{}] ". format(idd) }, 409 elif address is None: return { 'message': "Address with id [{}] Not found".format(idd) }, 404 parser = reqparse.RequestParser() # define the input parameters need and its type parser.add_argument('label_name', type=str, required=True, help="This field cannot be left blanck") parser.add_argument('name', type=str, required=True, help="This field cannot be left blanck") parser.add_argument('surnames', type=str, required=True, help="This field cannot be left blanck") parser.add_argument('street', type=str, required=True, help="This field cannot be left blanck") parser.add_argument('number', type=int, required=True, help="This field cannot be left blanck") parser.add_argument('cp', type=str, required=True, help="This field cannot be left blanck") parser.add_argument('city', type=str, required=True, help="This field cannot be left blanck") parser.add_argument('province', type=str, required=True, help="This field cannot be left blanck") parser.add_argument('telf', type=int, required=True, help="This field cannot be left blanck") data = parser.parse_args() address.label_name = data['label_name'] address.name = data['name'] address.surnames = data['surnames'] address.street = data['street'] address.number = data['number'] address.cp = data['cp'] address.city = data['city'] address.province = data['province'] address.telf = data['telf'] address.save_to_db() return {"Message": "Address saved correctly"}, 200
def get(cls, _id): address = AddressModel.find_by_id(_id) if address: return address_schema.dump(address), 200 return {"message": ADDRESS_NOT_FOUND}, 404
def get(self,id): return AddressModel.find_by_id(id)
def delete_address(self, idd): address = AddressModel.find_by_id(idd) self.address.remove(address) db.session.add(self) db.session.commit() return 1
def _prepare_ticket_pdf(self, html_name, order: OrdersModel): html = open(email_templates[html_name]) card = CardModel.find_by_id(order.card_id) address = AddressModel.find_by_id(order.address_id) self.parser = BeautifulSoup(html, 'lxml') # Añadimos la fecha del pedido self._replace_content(self, "order_date", order.date) self._replace_content(self, "order_id", "Pedido " + str(date.today().strftime("%Y")) + "-" + str(order.id) + " QRL 02154") # Añadimos los productos con su respectiva cantidad y precio products = self._get_component(self, "products") all_products = self._get_component(self, "all_products") tmp = self._get_copy_children(self,"products") # 0: Quant x Book Title / 1: Price products.contents = [] all_products.contents = [] for art in order.articles: book_title = BookModel.find_by_id(art.book_id).name tmp_products = copy.copy(products) quant, price = copy.copy(tmp[0]), copy.copy(tmp[1]) self._replace_component_content(self, quant, str(art.quant) + " x " + book_title) self._replace_component_content(self, price, str(art.price) + "€") tmp_products.append(quant) tmp_products.append(price) all_products.append(tmp_products) # Añadimos el tipo de envio con su respectivo precio sending = self._get_children(self, "send_type") send_type, price = sending[0], sending[1] # 0: 1 x Envio / 1: Price envio = "1 x " if order.send_type == 1: envio += "Envío Estándard" elif order.send_type == 2: envio += "Envío Estándard Plus" else: envio += "Envío Ultra Express" self._replace_component_content(self, send_type, envio) self._replace_component_content(self, price, str(order.shipping) + "€") # Añadimos los impuestos self._replace_content(self, "taxes", str(order.taxes) + "€") # Añadimos el precio total totals = self._get_children(self, "totals") n_articles, t_price = totals[0], totals[1] # 0: Total n articles / 1: Total price self._replace_component_content(self, n_articles, "Total "+ str(len(order.articles)) + " artículo/s") self._replace_component_content(self, t_price, str(order.total) + "€") # Añadimos tambien el precio en pesetas self._replace_content(self, "pesetas", "En pesetas : " + str(round(order.total*166.386,2)) + " ptas") # Añadimos la dirección de envio direction = self._get_children(self, "dirección") name, street, cp, telf = direction[0], direction[1], direction[2], direction[3] self._replace_component_content(self, name, address.name + " " + address.surnames) self._replace_component_content(self, street, address.street + ", " + str(address.number)) self._replace_component_content(self, cp, str(address.cp) + ", " + address.province) self._replace_component_content(self, telf, "Tfno: " + str(address.telf)) # Añadimos la tarjeta con la que se realizó el pago self._replace_content(self, "vendor", card.payment_method + " **** **** **** " + str(card.number)[-4:]) # Generamos el pdf self.pdf = BytesIO() HTML(string=str(self.parser)).write_pdf(target=self.pdf) html.close()