Exemple #1
0
def _generate_product_image(product):
    image = generate_image(512, 512)
    sio = BytesIO()
    image.save(sio, format="JPEG", quality=75)
    filer_file = filer_image_from_data(
        request=None, path="ProductImages/Mock", file_name="%s.jpg" % product.sku, file_data=sio.getvalue(), sha1=True
    )
    media = ProductMedia.objects.create(product=product, kind=ProductMediaKind.IMAGE, file=filer_file)
    media.shops = Shop.objects.all()
    media.save()
    return media
 def _attach_image_from_name(self, product, image_name, shop_product):
     image_file = os.path.join(self.image_dir, image_name)
     if not os.path.isfile(image_file):
         print("Image file does not exist: %s" % image_file)
         return
     with open(image_file, "rb") as fp:
         data = fp.read()
     filer_file = filer_image_from_data(None, "WintergearProducts", image_name, data, sha1=True)
     assert filer_file
     image, _ = ProductMedia.objects.get_or_create(product=product, file=filer_file, kind=ProductMediaKind.IMAGE)
     image.shops.add(self.shop)
     product.primary_image = image
     shop_product.shop_primary_image = image
Exemple #3
0
def _generate_product_image(product):
    image = generate_image(512, 512)
    sio = BytesIO()
    image.save(sio, format="JPEG", quality=75)
    filer_file = filer_image_from_data(request=None,
                                       path="ProductImages/Mock",
                                       file_name="%s.jpg" % product.sku,
                                       file_data=sio.getvalue(),
                                       sha1=True)
    media = ProductMedia.objects.create(product=product,
                                        kind=ProductMediaKind.IMAGE,
                                        file=filer_file)
    media.shops = Shop.objects.all()
    media.save()
    return media
 def _attach_image_from_name(self, product, image_name, shop_product):
     image_file = os.path.join(self.image_dir, image_name)
     if not os.path.isfile(image_file):
         print("Image file does not exist: %s" % image_file)
         return
     with open(image_file, "rb") as fp:
         data = fp.read()
     filer_file = filer_image_from_data(None,
                                        "WintergearProducts",
                                        image_name,
                                        data,
                                        sha1=True)
     assert filer_file
     image, _ = ProductMedia.objects.get_or_create(
         product=product, file=filer_file, kind=ProductMediaKind.IMAGE)
     image.shops.add(self.shop)
     product.primary_image = image
     shop_product.shop_primary_image = image