Beispiel #1
0
 def _setup(self):
     deconstructed_storage = data['storage']
     if isinstance(deconstructed_storage, list):
         cls_name, args, kwargs = deconstructed_storage
         self._wrapped = get_module_class(cls_name)(*args, **kwargs)
     else:  # backward compatibility with previously stored cache entries
         self._wrapped = get_module_class(deconstructed_storage)()
Beispiel #2
0
    def setUp(self):
        self.backend = get_module_class(settings.THUMBNAIL_BACKEND)()
        self.engine = get_module_class(settings.THUMBNAIL_ENGINE)()
        self.kvstore = get_module_class(settings.THUMBNAIL_KVSTORE)()

        if not os.path.exists(settings.MEDIA_ROOT):
            os.makedirs(settings.MEDIA_ROOT)

        # portrait
        name = 'portrait.jpg'
        fn = pjoin(settings.MEDIA_ROOT, name)
        im = Image.new('L', (100, 200))
        im.paste(255, (0, 0, 100, 100))
        im.save(fn)
        self.portrait = ImageFile(
            Item.objects.get_or_create(image=name)[0].image)
        self.kvstore.delete(self.portrait)

        # landscape
        name = 'landscape.jpg'
        fn = pjoin(settings.MEDIA_ROOT, name)
        im = Image.new('L', (200, 100))
        im.paste(255, (0, 0, 100, 100))
        im.save(fn)
        self.landscape = ImageFile(
            Item.objects.get_or_create(image=name)[0].image)
        self.kvstore.delete(self.landscape)
Beispiel #3
0
    def setUp(self):
        self.backend = get_module_class(settings.THUMBNAIL_BACKEND)()
        self.engine = get_module_class(settings.THUMBNAIL_ENGINE)()
        self.kvstore = get_module_class(settings.THUMBNAIL_KVSTORE)()

        if not os.path.exists(settings.MEDIA_ROOT):
            os.makedirs(settings.MEDIA_ROOT)

        # portrait
        name = 'portrait.jpg'
        fn = pjoin(settings.MEDIA_ROOT, name)
        im = Image.new('L', (100, 200))
        im.paste(255, (0, 0, 100, 100))
        im.save(fn)
        self.portrait = ImageFile(Item.objects.get_or_create(image=name)[0].image)
        self.kvstore.delete(self.portrait)

        # landscape
        name = 'landscape.jpg'
        fn = pjoin(settings.MEDIA_ROOT, name)
        im = Image.new('L', (200, 100))
        im.paste(255, (0, 0, 100, 100))
        im.save(fn)
        self.landscape = ImageFile(Item.objects.get_or_create(image=name)[0].image)
        self.kvstore.delete(self.landscape)
Beispiel #4
0
    def setUp(self):
        self.BACKEND = get_module_class(settings.THUMBNAIL_BACKEND)()
        self.ENGINE = get_module_class(settings.THUMBNAIL_ENGINE)()
        self.KVSTORE = get_module_class(settings.THUMBNAIL_KVSTORE)()

        if not os.path.exists(settings.MEDIA_ROOT):
            os.makedirs(settings.MEDIA_ROOT)
            shutil.copytree(settings.DATA_ROOT, DATA_DIR)

        for dimension in self.IMAGE_DIMENSIONS:
            name = '%sx%s.jpg' % dimension
            self.create_image(name, dimension)
Beispiel #5
0
    def setUp(self):
        self.BACKEND = get_module_class(settings.THUMBNAIL_BACKEND)()
        self.ENGINE = get_module_class(settings.THUMBNAIL_ENGINE)()
        self.KVSTORE = get_module_class(settings.THUMBNAIL_KVSTORE)()

        if not os.path.exists(settings.MEDIA_ROOT):
            os.makedirs(settings.MEDIA_ROOT)
            shutil.copytree(settings.DATA_ROOT, DATA_DIR)

        for dimension in self.IMAGE_DIMENSIONS:
            name = '%sx%s.jpg' % dimension
            self.create_image(name, dimension)
Beispiel #6
0
 def setUp(self):
     self.backend = get_module_class(settings.THUMBNAIL_BACKEND)()
     self.engine = get_module_class(settings.THUMBNAIL_ENGINE)()
     self.kvstore = get_module_class(settings.THUMBNAIL_KVSTORE)()
     if not os.path.exists(settings.MEDIA_ROOT):
         os.makedirs(settings.MEDIA_ROOT)
     dims = [(500, 500), (100, 100)]
     for dim in dims:
         name = "%sx%s.jpg" % dim
         fn = pjoin(settings.MEDIA_ROOT, name)
         im = Image.new("L", dim)
         im.save(fn)
         Item.objects.get_or_create(image=name)
Beispiel #7
0
    def setUp(self):
        self.backend = get_module_class(settings.THUMBNAIL_BACKEND)()
        self.engine = get_module_class(settings.THUMBNAIL_ENGINE)()
        self.kvstore = get_module_class(settings.THUMBNAIL_KVSTORE)()

        if not os.path.exists(settings.MEDIA_ROOT):
            os.makedirs(settings.MEDIA_ROOT)
            shutil.copytree(settings.DATA_ROOT, DATA_DIR)

        dims = [(500, 500), (100, 100), (200, 100), ]

        for dim in dims:
            name = '%sx%s.jpg' % dim
            self.create_image(name, dim)
Beispiel #8
0
 def test_dummy_response(self):
     client = Client()
     response = client.get('/thumbnail-dummy/111x666/')
     engine = get_module_class(settings.THUMBNAIL_ENGINE)()
     image = engine.dummy_image(111, 666)
     raw_data = engine._get_raw_data(image, format_='PNG', quality=95)
     self.assertEqual(response.content, raw_data)
Beispiel #9
0
 def setUp(self):
     self.backend = get_module_class(settings.THUMBNAIL_BACKEND)()
     self.engine = get_module_class(settings.THUMBNAIL_ENGINE)()
     self.kvstore = get_module_class(settings.THUMBNAIL_KVSTORE)()
     if not os.path.exists(settings.MEDIA_ROOT):
         os.makedirs(settings.MEDIA_ROOT)
     dims = [
         (500, 500),
         (100, 100),
     ]
     for dim in dims:
         name = '%sx%s.jpg' % dim
         fn = pjoin(settings.MEDIA_ROOT, name)
         im = Image.new('L', dim)
         im.save(fn)
         Item.objects.get_or_create(image=name)
Beispiel #10
0
 def test_dummy_response(self):
     client = Client()
     response = client.get('/thumbnail-dummy/111x666/')
     engine = get_module_class(settings.THUMBNAIL_ENGINE)()
     image = engine.dummy_image(111, 666)
     raw_data = engine._get_raw_data(image, format_='PNG', quality=95)
     self.assertEqual(response.content, raw_data)
Beispiel #11
0
 def test_encode_utf8_filenames(self):
     storage = get_module_class('sorl.thumbnail.images.UrlStorage')()
     self.assertEqual(
         storage.normalize_url(
             'El jovencito emponzoñado de whisky, qué figura exhibe'),
         'El%20jovencito%20emponzoado%20de%20whisky%2C%20qu%20figura%20exhibe'
     )
Beispiel #12
0
 def setUp(self):
     self.backend = get_module_class(settings.THUMBNAIL_BACKEND)()
     self.org_settings = {}
     params = {"THUMBNAIL_DUMMY": True}
     for k, v in params.iteritems():
         self.org_settings[k] = getattr(settings, k)
         setattr(settings, k, v)
Beispiel #13
0
 def setUp(self):
     self.backend = get_module_class(settings.THUMBNAIL_BACKEND)()
     self.org_settings = {}
     params = {
         'THUMBNAIL_DUMMY': True,
     }
     for k, v in params.iteritems():
         self.org_settings[k] = getattr(settings, k)
         setattr(settings, k, v)
Beispiel #14
0
    def setUp(self):
        self.backend = get_module_class(settings.THUMBNAIL_BACKEND)()
        self.engine = get_module_class(settings.THUMBNAIL_ENGINE)()
        self.kvstore = get_module_class(settings.THUMBNAIL_KVSTORE)()

        if not os.path.exists(settings.MEDIA_ROOT):
            os.makedirs(settings.MEDIA_ROOT)
            shutil.copytree(settings.DATA_ROOT, DATA_DIR)

        dims = [
            (500, 500),
            (100, 100),
            (200, 100),
        ]

        for dim in dims:
            name = '%sx%s.jpg' % dim
            self.create_image(name, dim)
Beispiel #15
0
 def _setup(self):
     if not hasattr(thread_local_data, 'storage_cache'):
         thread_local_data.storage_cache = {}
     if data['storage'] in thread_local_data.storage_cache:
         self._wrapped = thread_local_data.storage_cache[
             data['storage']]
     else:
         storage_instance = get_module_class(data['storage'])()
         thread_local_data.storage_cache[
             data['storage']] = storage_instance
         self._wrapped = storage_instance
Beispiel #16
0
    def test_generates_same_path_with_any_storage_backend(self):
        # Given
        image = 'foo'
        geometry = '400x400'

        filesystem_thumbnail = get_thumbnail(image, geometry)

        with patch('sorl.thumbnail.base.ImageFile', DummyImageFile):
            with patch('sorl.thumbnail.default.storage',
                       new_callable=get_module_class(GOOGLE_STORAGE)):
                with patch('sorl.thumbnail.default.kvstore',
                           new_callable=DummyKVStore):
                    google_thumbnail = get_thumbnail(image, geometry)

        self.assertEqual(google_thumbnail.name, filesystem_thumbnail.name)
Beispiel #17
0
 def _setup(self):
     self._wrapped = get_module_class(settings.THUMBNAIL_BACKEND)()
Beispiel #18
0
 def _setup(self):
     self._wrapped = get_module_class(settings.THUMBNAIL_STORAGE)()
Beispiel #19
0
 def _setup(self):
     self._wrapped = get_module_class(data['storage'])()
Beispiel #20
0
 def setUp(self):
     self.BACKEND = get_module_class(settings.THUMBNAIL_BACKEND)()
Beispiel #21
0
 def setUp(self):
     self.ENGINE = get_module_class(settings.THUMBNAIL_ENGINE)()
Beispiel #22
0
# coding: utf-8

from django.conf import settings
from sorl.thumbnail.helpers import get_module_class

engines = [get_module_class(engine_path)
    for engine_path in settings.SORL_ENGINES]

EngineMixin = type('EngineMixin', tuple(engines), {})
Beispiel #23
0
 def _setup(self):
     self._wrapped = get_module_class(data['storage'])()
Beispiel #24
0
'''
support context switching of thumbnail engines. default = PIL
but hat does not work with PDF thumbnails.
Imagemagick works for PDF, but is very slow
'''

from sorl.thumbnail.helpers import get_module_class
from sorl.thumbnail import default
from contextlib import contextmanager

PDF_ENGINE = 'sorl.thumbnail.engines.convert_engine.Engine'
PIL_ENGINE = 'sorl.thumbnail.engines.pil_engine.Engine'

pil = get_module_class(PIL_ENGINE)()
pdf = get_module_class(PDF_ENGINE)()


@contextmanager
def engine(docname):
    ''' select appropriate thumbnail engine. Use Imagemagick for PDF, else use Pillow '''
    doc_engine = pdf if docname.lower().endswith('.pdf') else pil
    old_engine = default.engine
    default.engine = doc_engine
    yield doc_engine
    default.engine = old_engine
 def setUp(self):
     self.ENGINE = get_module_class(settings.THUMBNAIL_ENGINE)()
Beispiel #26
0
 def setUp(self):
     self.backend = get_module_class(settings.THUMBNAIL_BACKEND)()
Beispiel #27
0
 def test_encode_utf8_filenames(self):
     storage = get_module_class('sorl.thumbnail.images.UrlStorage')()
     self.assertEqual(
         storage.normalize_url('El jovencito emponzoñado de whisky, qué figura exhibe'),
         'El%20jovencito%20emponzoado%20de%20whisky%2C%20qu%20figura%20exhibe'
     )
Beispiel #28
0
 def _setup(self):
     self._wrapped = get_module_class(settings.THUMBNAIL_STORAGE)()
Beispiel #29
0
 def setUp(self):
     self.backend = get_module_class(settings.THUMBNAIL_BACKEND)()
     setattr(settings, "THUMBNAIL_DUMMY", True)
Beispiel #30
0
 def _setup(self):
     self._wrapped = get_module_class(settings.THUMBNAIL_BACKEND)()