| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- import typing
- import collections.abc
- from .directory_image import directory_image
- from .product import product
- from .exception import not_ready_exception
- class product_response:
- def __init__(self, images: directory_image) -> None:
- self.__images = images
- @property
- def images(self) -> directory_image:
- return self.__images
- def single(self, target: product) -> dict:
- if not target.ready:
- raise not_ready_exception(target)
- covers = directory_image.server_path() + "/"
- return {
- "name": target.name,
- "description": target.description,
- "author": target.author,
- "image": covers + self.images.get_full_name(target),
- "thumbnail": covers + self.images.get_thumbnail_name(target),
- "stock_count": target.stock_count,
- "barcode": target.barcode
- }
- def collection(self, targets: typing.Iterable[product]) -> list:
- result = list()
- for count in targets:
- if not isinstance(count, product):
- raise TypeError("Product list must contain only products.")
- result.append(self.single(count))
- return result
|