def thumbnail_exists(self, thumbnail_name): if self.remote_source: return False if utils.is_storage_local(self.source_storage): source_modtime = utils.get_modified_time(self.source_storage, self.name) else: source = self.get_source_cache() if not source: return False source_modtime = source.modified if not source_modtime: return False local_thumbnails = utils.is_storage_local(self.thumbnail_storage) if local_thumbnails: thumbnail_modtime = utils.get_modified_time(self.thumbnail_storage, thumbnail_name) if not thumbnail_modtime: return False return source_modtime <= thumbnail_modtime thumbnail = self.get_thumbnail_cache(thumbnail_name) if not thumbnail: return False thumbnail_modtime = thumbnail.modified return thumbnail
def generate_thumbnail(self, thumbnail_options): """ Return a ``ThumbnailFile`` containing a thumbnail image. The thumbnail image is generated using the ``thumbnail_options`` dictionary. """ if not utils.is_storage_local(self.source_storage): # Get a local copy of the source file tmp_image_f = StringIO() orig_f = urllib2.urlopen(self.source_storage.url(self.name)) tmp_image_f.write(orig_f.read()) tmp_image_f.seek(0) self.file = tmp_image_f image = engine.generate_source_image(self, thumbnail_options) thumbnail_image = engine.process_image(image, thumbnail_options) quality = thumbnail_options.get('quality', self.thumbnail_quality) filename = self.get_thumbnail_name(thumbnail_options, transparent=self.is_transparent(thumbnail_image)) data = engine.save_image(thumbnail_image, filename=filename, quality=quality).read() thumbnail = ThumbnailFile(filename, ContentFile(data), storage=self.thumbnail_storage) thumbnail.image = thumbnail_image thumbnail._committed = False return thumbnail
def thumbnail_exists(self, thumbnail_name): """ Calculate whether the thumbnail already exists and that the source is not newer than the thumbnail. If the source and thumbnail file storages are local, their file modification times are used. Otherwise the database cached modification times are used. """ if self.remote_source: return False if utils.is_storage_local(self.source_storage): source_modtime = utils.get_modified_time(self.source_storage, self.name) else: source = self.get_source_cache() if not source: return False source_modtime = source.modified if not source_modtime: return False local_thumbnails = utils.is_storage_local(self.thumbnail_storage) if local_thumbnails: thumbnail_modtime = utils.get_modified_time( self.thumbnail_storage, thumbnail_name) if not thumbnail_modtime: return False return source_modtime <= thumbnail_modtime thumbnail = self.get_thumbnail_cache(thumbnail_name) if not thumbnail: return False thumbnail_modtime = thumbnail.modified if thumbnail.modified and source_modtime <= thumbnail.modified: return thumbnail return False
def thumbnail_exists(self, thumbnail_name): """ Calculate whether the thumbnail already exists and that the source is not newer than the thumbnail. If the source and thumbnail file storages are local, their file modification times are used. Otherwise the database cached modification times are used. """ if self.remote_source: return False if utils.is_storage_local(self.source_storage): source_modtime = utils.get_modified_time( self.source_storage, self.name) else: source = self.get_source_cache() if not source: return False source_modtime = source.modified if not source_modtime: return False local_thumbnails = utils.is_storage_local(self.thumbnail_storage) if local_thumbnails: thumbnail_modtime = utils.get_modified_time( self.thumbnail_storage, thumbnail_name) if not thumbnail_modtime: return False return source_modtime <= thumbnail_modtime thumbnail = self.get_thumbnail_cache(thumbnail_name) if not thumbnail: return False thumbnail_modtime = thumbnail.modified if thumbnail.modified and source_modtime <= thumbnail.modified: return thumbnail return False