Exemplo n.º 1
0
 def get_placeholder_image(self):
     storage_class = get_storage_class(settings.STATICFILES_STORAGE)
     storage = storage_class()
     placeholder = storage.open(settings.PLACEHOLDER_PATH)
     image = ImageFile(placeholder)
     image.storage = storage
     return image
Exemplo n.º 2
0
 def get_placeholder_image(self):
     storage_class = get_storage_class(settings.STATICFILES_STORAGE)
     storage = storage_class()
     placeholder = storage.open(settings.PLACEHOLDER_PATH)
     image = ImageFile(placeholder)
     image.storage = storage
     return image
Exemplo n.º 3
0
def mail_open_request(request, mail):
    MailOpen.objects.create(mail=mail)

    storage_class = get_storage_class(settings.STATICFILES_STORAGE)
    storage = storage_class()
    image = ImageFile(storage.open("images/FFFFFF-1.png"))
    image.storage = storage

    return HttpResponse(image, content_type="image/png")
Exemplo n.º 4
0
    def get_placeholder_image(self):
        if not hasattr(self.__class__, '_PlaceholderImageMixin__placeholder_image_cache'):
            path = finders.find(self.PLACEHOLDER_IMAGE_PATH)
            if path:
                location, file_name = os.path.split(path)
                fs = FileSystemStorage(location=location)
                image = ImageFile(fs.open(file_name))
                image.storage = fs
                self.__class__.__placeholder_image_cache = image
            else:
                self.__class__.__placeholder_image_cache = None

        return self.__class__.__placeholder_image_cache
Exemplo n.º 5
0
        def _render(self, context):
            storage = SafeStaticFilesStorage()
            file_ = self.file_.resolve(context)
            absolute_path = finders.find(file_)
            try:
                file_ = ImageFile(staticfiles_storage.open(file_))
            except:
                file_ = ImageFile(open(absolute_path))
            file_.storage = storage
            geometry = self.geometry.resolve(context)
            options = {}
            for key, expr in self.options:
                noresolve = {'True': True, 'False': False, 'None': None}
                value = noresolve.get(text_type(expr), expr.resolve(context))
                if key == 'options':
                    options.update(value)
                else:
                    options[key] = value

            thumbnail = get_thumbnail(file_, geometry, **options)

            if not thumbnail or (isinstance(thumbnail, DummyImageFile)
                                 and self.nodelist_empty):
                if self.nodelist_empty:
                    return self.nodelist_empty.render(context)
                else:
                    return ''

            if self.as_var:
                context.push()
                context[self.as_var] = thumbnail
                output = self.nodelist_file.render(context)
                context.pop()
            else:
                output = thumbnail.url

            return output
Exemplo n.º 6
0
        def _render(self, context):
            storage = SafeStaticFilesStorage()
            file_ = self.file_.resolve(context)
            absolute_path = finders.find(file_)
            try:
                file_ = ImageFile(staticfiles_storage.open(file_))
            except:
                file_ = ImageFile(open(absolute_path))
            file_.storage = storage
            geometry = self.geometry.resolve(context)
            options = {}
            for key, expr in self.options:
                noresolve = {'True': True, 'False': False, 'None': None}
                value = noresolve.get(text_type(expr), expr.resolve(context))
                if key == 'options':
                    options.update(value)
                else:
                    options[key] = value

            thumbnail = get_thumbnail(file_, geometry, **options)

            if not thumbnail or (isinstance(thumbnail, DummyImageFile) and self.nodelist_empty):
                if self.nodelist_empty:
                    return self.nodelist_empty.render(context)
                else:
                    return ''

            if self.as_var:
                context.push()
                context[self.as_var] = thumbnail
                output = self.nodelist_file.render(context)
                context.pop()
            else:
                output = thumbnail.url

            return output
Exemplo n.º 7
0
def static_image(url):
    storage_class = get_storage_class(settings.STATICFILES_STORAGE)
    storage = storage_class()
    image = ImageFile(storage.open(url))
    image.storage = storage
    return image, image.url
Exemplo n.º 8
0
def get_static_image_file(path):
    storage_class = get_storage_class(settings.STATICFILES_STORAGE)
    storage = storage_class()
    image = ImageFile(storage.open(path))
    image.storage = storage
    return image
Exemplo n.º 9
0
def static_image(url):
    storage_class = get_storage_class(settings.STATICFILES_STORAGE)
    storage = storage_class()
    image = ImageFile(storage.open(url))
    image.storage = storage
    return image, image.url