def set_image(self, image, contentType=None, filename=None):
        if image and not INamedBlobImage.providedBy(image):
            if hasattr(image, 'data'):
                data = image.data
            elif hasattr(image, 'read'):
                data = image.read()
            else:
                data = image
            if hasattr(image, 'filename') and not filename:
                filename = unicode(image.filename)
            elif hasattr(image, 'name') and not filename:
                filename = image.name.split('/').pop()
            if hasattr(image, 'contentType') and not contentType:
                contentType = image.contentType
            elif hasattr(image, 'encoding') and not contentType:
                contentType = image.encoding
            image = NamedBlobImage(data, contentType, unicode(filename))

        if not image and IGraphicallyCustomized.providedBy(self.context):
            noLongerProvides(self.context, IGraphicallyCustomized)
            del IAnnotations(self.context)[self._annotation]
        if image and not IGraphicallyCustomized.providedBy(self.context):
            alsoProvides(self.context, IGraphicallyCustomized)
        if image:
            IAnnotations(
                self.context)[self._annotation] = PersistentDict()
            IAnnotations(
                self.context).get(
                self._annotation)['original'] = image
Beispiel #2
0
 def set_image(self, name=None):
     if not image and IGraphicallyCustomized.providedBy(self.context):
         noLongerProvides(self.context, IGraphicallyCustomized)
         del IAnnotations(self.context)[self._annotation]
     if image and not IGraphicallyCustomized.providedBy(self.context):
         alsoProvides(self.context, IGraphicallyCustomized)
     if image:
         IAnnotations(
             self.context)[self._annotation] = {}
         IAnnotations(
             self.context).get(
             self._annotation)['original'] = image