Ejemplo n.º 1
0
def create_cache(sizes, options):
    """
    Creates the cache for the given files
    """
    reset = options.get('reset', None)

    size_list = [size.strip(' ,') for size in sizes]

    if len(size_list) < 1:
        sizes = PhotoSize.objects.filter(pre_cache=True)
    else:
        sizes = PhotoSize.objects.filter(name__in=size_list)

    if not len(sizes):
        raise CommandError('No photo sizes were found.')

    print 'Caching photos, this may take a while...'

    for cls in ImageModel.__subclasses__():
        for photosize in sizes:
            print 'Cacheing %s size images' % photosize.name
            for obj in cls.objects.all():
                if reset:
                    obj.remove_size(photosize)
                obj.create_size(photosize)
def create_cache(sizes, options):
    """
    Creates the cache for the given files
    """
    reset = options.get('reset', None)

    size_list = [size.strip(' ,') for size in sizes]

    if len(size_list) < 1:
        sizes = PhotoSize.objects.filter(pre_cache=True)
    else:
        sizes = PhotoSize.objects.filter(name__in=size_list)

    if not len(sizes):
        raise CommandError('No photo sizes were found.')

    print 'Caching photos, this may take a while...'

    for cls in ImageModel.__subclasses__():
        for photosize in sizes:
            print 'Cacheing %s size images' % photosize.name
            for obj in cls.objects.all():
                if reset:
                    obj.remove_size(photosize)
                obj.create_size(photosize)
Ejemplo n.º 3
0
    def handle(self, *args, **options):
        sizes = options['sizes']

        if not sizes:
            photosizes = PhotoSize.objects.all()
        else:
            photosizes = PhotoSize.objects.filter(name__in=sizes)

        if not len(photosizes):
            raise CommandError('No photo sizes were found.')

        print('Flushing cache...')

        for cls in ImageModel.__subclasses__():
            for photosize in photosizes:
                print('Flushing %s size images' % photosize.name)
                for obj in cls.objects.all():
                    obj.remove_size(photosize)
Ejemplo n.º 4
0
def create_cache(sizes, options):
    """
    Clears the cache for the given files
    """
    size_list = [size.strip(' ,') for size in sizes]

    if len(size_list) < 1:
        sizes = PhotoSize.objects.all()
    else:
        sizes = PhotoSize.objects.filter(name__in=size_list)

    if not len(sizes):
        raise CommandError('No photo sizes were found.')

    print 'Flushing cache...'

    for cls in ImageModel.__subclasses__():
        for photosize in sizes:
            print 'Flushing %s size images' % photosize.name
            for obj in cls.objects.all():
                obj.remove_size(photosize)
Ejemplo n.º 5
0
def create_cache(sizes, options):
    """
    Clears the cache for the given files
    """
    size_list = [size.strip(' ,') for size in sizes]

    if len(size_list) < 1:
        sizes = PhotoSize.objects.all()
    else:
        sizes = PhotoSize.objects.filter(name__in=size_list)

    if not len(sizes):
        raise CommandError('No photo sizes were found.')

    print('Flushing cache...')

    for cls in ImageModel.__subclasses__():
        for photosize in sizes:
            print('Flushing %s size images' % photosize.name)
            for obj in cls.objects.all():
                obj.remove_size(photosize)
Ejemplo n.º 6
0
    def handle(self, *args, **options):
        reset = options['reset']
        sizes = options['sizes']

        if not sizes:
            photosizes = PhotoSize.objects.all()
        else:
            photosizes = PhotoSize.objects.filter(name__in=sizes)

        if not len(photosizes):
            raise CommandError('No photo sizes were found.')

        print('Caching photos, this may take a while...')

        for cls in ImageModel.__subclasses__():
            for photosize in photosizes:
                print('Cacheing %s size images' % photosize.name)
                for obj in cls.objects.all():
                    if reset:
                        obj.remove_size(photosize)
                    obj.create_size(photosize)
Ejemplo n.º 7
0
        im = self.resize_image(im, photosize)
    # Apply watermark if found
    if photosize.watermark is not None:
        im = photosize.watermark.post_process(im)
    # Apply effect if found
    if self.effect is not None:
        im = self.effect.post_process(im)
    elif photosize.effect is not None:
        im = photosize.effect.post_process(im)
    # Save file
    im_filename = getattr(self, "get_%s_filename" % photosize.name)()
    try:
        buffer = BytesIO()
        if im_format != 'JPEG' and not getattr(settings,
                                               'PHOTOLOGUE_FORCE_JPEG', False):
            im.save(buffer, im_format)
        else:
            im.save(buffer,
                    'JPEG',
                    quality=int(photosize.quality),
                    optimize=True)
        buffer_contents = ContentFile(buffer.getvalue())
        self.image.storage.save(im_filename, buffer_contents)
    except IOError as e:
        if self.image.storage.exists(im_filename):
            self.image.storage.delete(im_filename)
        raise e


ImageModel.add_to_class('create_size', create_size)