def get_thumb(self, scale, key="image", direction="thumb"): """ Return data from plone scale or None""" #Make cache optional cachekey = (self.context.uid, scale, key) cached = thumb_cache.get(cachekey) if cached: return cached scales = get_image_scales() maxwidth, maxheight = scales[scale] blobs = IBlobs(self.context) if key in blobs: registry = get_current_registry() if blobs[key].mimetype in registry.settings[ 'supported_thumbnail_mimetypes']: with blobs[key].blob.open() as f: try: thumb_data, image_type, size = scaleImage( f, width=maxwidth, height=maxheight, direction=direction) except IOError: #FIXME: Logging? return thumb = Thumbnail(thumb_data, image_type=image_type, size=size) thumb_cache.put(cachekey, thumb) return thumb
def file_data(self, value): blob_file = IBlobs(self).create_from_formdata(self.blob_key, value) if blob_file: self.filename = blob_file.filename self.mimetype = blob_file.mimetype styles = {'video': 'film', 'image': 'picture'} main = self.mimetype.split('/')[0] self.icon = styles.get(main, 'file')
def file_data_response(context, request, disposition = 'inline'): res = Response( headerlist=[ ('Content-Disposition', '%s;filename="%s"' % ( disposition, context.filename.encode('ascii', 'ignore'))), ('Content-Type', str(context.mimetype)), ] ) #Should this be fault tolerant in some way? with IBlobs(context)['file'].blob.open() as f: res.body = f.read() return res
def image_data(self, value): IBlobs(self).create_from_formdata('image', value)
def image_data(self): blobs = IBlobs(self, None) if blobs: return blobs.formdata_dict('image')
def size(self): blobs = IBlobs(self) return self.blob_key in blobs and blobs[self.blob_key].size or u""
def file_data(self): blobs = IBlobs(self, None) if blobs: return blobs.formdata_dict(self.blob_key)
def image_data(self, value): IBlobs(self).create_from_formdata(self.blob_key, value)
def __call__(self): return {'has_image': 'image' in IBlobs(self.context)}
def image_data(self): blobs = IBlobs(self, None) if blobs: return blobs.formdata_dict(self.blob_key)