Exemple #1
0
 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
Exemple #2
0
 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')
Exemple #3
0
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
Exemple #4
0
 def image_data(self, value):
     IBlobs(self).create_from_formdata('image', value)
Exemple #5
0
 def image_data(self):
     blobs = IBlobs(self, None)
     if blobs:
         return blobs.formdata_dict('image')
Exemple #6
0
 def size(self):
     blobs = IBlobs(self)
     return self.blob_key in blobs and blobs[self.blob_key].size or u""
Exemple #7
0
 def file_data(self):
     blobs = IBlobs(self, None)
     if blobs:
         return blobs.formdata_dict(self.blob_key)
Exemple #8
0
 def image_data(self, value):
     IBlobs(self).create_from_formdata(self.blob_key, value)
Exemple #9
0
 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)