Exemplo n.º 1
0
    def save_image(self, name, line_number):

        try:
            storage = self.storage
            if 'http' in name and ': in name':
                file, message = urlretrieve(name)

            else:
                file = os.path.join(BASE_IMAGE_PATH, name)
            #image = PILImage.open(file)


            new_name, name_jpg, name_ext = generate_filenames(self.storage, name)

            #file_io = io.BytesIO()

            #image = image.convert('RGB')

            #image.save(file_io, 'jpeg')
            #image.save(file_io)
            f = open(file, 'rb')
            storage.save(name_ext, f)
            name = os.path.split(name_jpg)[-1]

            #save_thumbs(storage, thumb_settings, image, upload_to, name):
            save_thumbs(self.storage, settings.PRODUCT_THUMB_SETTINGS, file, '', name)

            self.images.append(name)
        except:
            self.errors[line_number].append('Ошибка при загрузке изображения {0}'.format(name))
            return None

        return 'discount_product/' + name_ext
Exemplo n.º 2
0
    def save_image(self, name, line_number):

        try:
            storage = self.storage
            if 'http' in name and ': in name':
                file, message = urlretrieve(name)

            else:
                file = os.path.join(BASE_IMAGE_PATH, name)
            #image = PILImage.open(file)

            new_name, name_jpg, name_ext = generate_filenames(
                self.storage, name)

            #file_io = io.BytesIO()

            #image = image.convert('RGB')

            #image.save(file_io, 'jpeg')
            #image.save(file_io)
            f = open(file, 'rb')
            storage.save(name_ext, f)
            name = os.path.split(name_jpg)[-1]

            #save_thumbs(storage, thumb_settings, image, upload_to, name):
            save_thumbs(self.storage, settings.PRODUCT_THUMB_SETTINGS, file,
                        '', name)

            self.images.append(name)
        except:
            self.errors[line_number].append(
                'Ошибка при загрузке изображения {0}'.format(name))
            return None

        return 'discount_product/' + name_ext
Exemplo n.º 3
0
    execute_from_command_line(sys.argv)

from discount import models
from multi_image_upload.models import save_thumbs
from django.conf import settings
from django.core.files.storage import FileSystemStorage
import os

save_path = os.path.join(settings.MEDIA_ROOT)
storage = FileSystemStorage(save_path)

for shop in models.Shop.objects.all():
    try:
        path = shop.image.path
        name = os.path.split(path)[-1]
        save_thumbs(storage, settings.SHOP_THUMB_SETTINGS, path,
                    'discount_shop', name)
    except:
        print('shop error', shop.pk)
        pass

for product in models.Product.objects.all():
    for image in product.images.all():
        try:
            path = image.image.path
            name = os.path.split(path)[-1]
            save_thumbs(storage, settings.PRODUCT_THUMB_SETTINGS, path,
                        'discount_product', name)
        except:
            print('product error', product.pk)
            pass
Exemplo n.º 4
0
from discount import models
from multi_image_upload.models import save_thumbs
from django.conf import settings
from django.core.files.storage import FileSystemStorage
import os


save_path = os.path.join(settings.MEDIA_ROOT)
storage = FileSystemStorage(save_path)

for shop in models.Shop.objects.all():
    try:
        path = shop.image.path
        name = os.path.split(path)[-1]
        save_thumbs(storage, settings.SHOP_THUMB_SETTINGS, path, 'discount_shop',  name)
    except:
        print('shop error', shop.pk)
        pass

for product in models.Product.objects.all():
    for image in product.images.all():
        try:
            path = image.image.path
            name = os.path.split(path)[-1]
            save_thumbs(storage, settings.PRODUCT_THUMB_SETTINGS, path, 'discount_product',  name)
        except:
            print('product error', product.pk)
            pass