コード例 #1
0
    def __init__(self,
                 width=None,
                 height=None,
                 anchor=None,
                 crop=None,
                 upscale=None,
                 **kwargs):
        self.processors = [
            ThumbnailProcessor(width,
                               height,
                               anchor=anchor,
                               crop=crop,
                               upscale=upscale)
        ]

        source = kwargs.get('source')
        if not (source is not None and getattr(source, 'name', None)):
            random_image = get_random_image()
            media_root = os.path.abspath(django_settings.MEDIA_ROOT)
            static_root = os.path.abspath(django_settings.STATIC_ROOT)
            source = ImageCacheFile(self, name=random_image)
            source.name = source.file.name \
                .replace(media_root, '') \
                .replace(static_root, '')[1:]

            kwargs['source'] = source

        super(DummyThumbnail, self).__init__(**kwargs)