コード例 #1
0
ファイル: images.py プロジェクト: madra/sorl-thumbnail
    def __init__(self, file_, storage=None):
        if not file_:
            raise ThumbnailError('File is empty.')

        # figure out name
        if hasattr(file_, 'name'):
            self.name = file_.name
        else:
            self.name = force_unicode(file_)

        # figure out storage
        if storage is not None:
            self.storage = storage
        elif hasattr(file_, 'storage'):
            self.storage = file_.storage
        elif url_pat.match(self.name):
            self.storage = UrlStorage()
        else:
            self.storage = default_storage

        if hasattr(self.storage, 'location'):
            location = self.storage.location
            if not self.storage.location.endswith("/"):
                location += "/"
            if self.name.startswith(location):
                self.name = self.name[len(location):]
コード例 #2
0
ファイル: images.py プロジェクト: seatme/sorl-thumbnail
def serialize_image_file(image_file):
    if image_file.size is None:
        raise ThumbnailError('Trying to serialize an ``ImageFile`` with a '
                             '``None`` size.')
    data = {
        'name': image_file.name,
        'storage': image_file.serialize_storage(),
        'size': image_file.size,
    }
    return simplejson.dumps(data)
コード例 #3
0
ファイル: images.py プロジェクト: seatme/sorl-thumbnail
 def __init__(self, file_, storage=None):
     if not file_:
         raise ThumbnailError('File is empty.')
     # figure out name
     if hasattr(file_, 'name'):
         self.name = file_.name
     else:
         self.name = force_unicode(file_)
     # figure out storage
     if storage is not None:
         self.storage = storage
     elif hasattr(file_, 'storage'):
         self.storage = file_.storage
     elif url_pat.match(self.name):
         self.storage = UrlStorage()
     else:
         self.storage = default_storage
コード例 #4
0
ファイル: base.py プロジェクト: Kokozzi/sorl-thumbnail
 def set(self, image_file, source=None):
     """
     Updates store for the `image_file`. Makes sure the `image_file` has a
     size set.
     """
     image_file.set_size() # make sure its got a size
     self._set(image_file.key, image_file)
     if source is not None:
         if not self.get(source):
             # make sure the source is in kvstore
             raise ThumbnailError('Cannot add thumbnails for source: `%s` '
                                  'that is not in kvstore.' % source.name)
             # Update the list of thumbnails for source.
         thumbnails = self._get(source.key, identity='thumbnails') or []
         thumbnails = set(thumbnails)
         thumbnails.add(image_file.key)
         self._set(source.key, list(thumbnails), identity='thumbnails')
コード例 #5
0
ファイル: images.py プロジェクト: joandlee/sorl-thumbnail
    def __init__(self, file_, storage=None):
        self.standard_storage = FileSystemStorage()
        
        if not file_:
            raise ThumbnailError('File is empty.')

        # figure out name
        if hasattr(file_, 'name'):
            self.name = file_.name
        else:
            self.name = force_str(file_)

        # TODO: Add a customizable naming method as a signal

        # Remove query args from names. Fixes cache and signature arguments
        # from third party services, like Amazon S3 and signature args.
        if settings.THUMBNAIL_REMOVE_URL_ARGS:
            self.name = self.name.split('?')[0]

        # Support for relative protocol urls
        if self.name.startswith('//'):
            self.name = 'http:' + self.name

        # figure out storage
        if storage is not None:
            self.storage = storage
        elif hasattr(file_, 'storage'):
            self.storage = file_.storage
        elif url_pat.match(self.name):
            self.storage = UrlStorage()
        else:
            self.storage = default_storage

        if hasattr(self.storage, 'location'):
            location = self.storage.location
            if not self.storage.location.endswith("/"):
                location += "/"
            if self.name.startswith(location):
                self.name = self.name[len(location):]