Exemplo n.º 1
0
 def get_data(self):
     data = {'_plone.uuid': self.data['uid']}
     if self.field_data.get('image'):
         im_data = self.field_data.get('image')
         if hasattr(im_data, 'read'):
             im_data = im_data.read()
         filename = self.field_data.get('image_filename')
         if not filename:
             filename = self.field_data['id']
         data['image'] = NamedBlobImage(data=decodeFileData(im_data),
                                        filename=toUnicode(filename))
         if not data['image'].contentType:
             data['image'].contentType = 'image/jpeg'
         data['imageCaption'] = self.field_data.get('imageCaption')
     return dict(id=self.field_data['id'],
                 type=self.data['portal_type'],
                 title=self.field_data['title'],
                 description=self.field_data['description'],
                 **data)
Exemplo n.º 2
0
    def ImportImage(self, node):
        """
        Import a base64 encoded image from an XML node.

        :param node: lxml.objectified XML node of image element
        :rtype: (:py:class:`NamedImage`, unicode) tuple
        """
        filename = attr_unicode(node, "filename")
        contentType = node.get("content-type", None)
        if not filename:
            basename = u"image%d.%%s" % random.randint(1, 2 ** 16)
            if contentType and "/" in contentType:
                filename = basename % contentType.split(u"/")[1]
            else:
                filename = basename % u"jpg"
        image = NamedBlobImage(data=node.text.decode("base64"), contentType=contentType, filename=filename)
        if image.contentType is None and image.filename:
            image.contentType = mimetypes.guess_type(image.filename)[0]
        return (image, attr_unicode(node, "caption"))
Exemplo n.º 3
0
    def ImportImage(self, node):
        """
        Import a base64 encoded image from an XML node.

        :param node: lxml.objectified XML node of image element
        :rtype: (:py:class:`NamedImage`, unicode) tuple
        """
        filename = attr_unicode(node, 'filename')
        contentType = node.get("content-type", None)
        if not filename:
            basename = u'image%d.%%s' % random.randint(1, 2**16)
            if contentType and '/' in contentType:
                filename = basename % contentType.split(u'/')[1]
            else:
                filename = basename % u'jpg'
        image = NamedBlobImage(data=node.text.decode("base64"),
                               contentType=contentType,
                               filename=filename)
        if image.contentType is None and image.filename:
            image.contentType = mimetypes.guess_type(image.filename)[0]
        return (image, attr_unicode(node, "caption"))
Exemplo n.º 4
0
    def ImportImage(self, node):
        """
        Import a base64 encoded image from an XML node.

        :param node: lxml.objectified XML node of image element
        :rtype: (:py:class:`NamedImage`, unicode) tuple
        """
        filename = attr_unicode(node, "filename")
        contentType = node.get("content-type", None)
        if not filename:
            basename = "image%d.%%s" % random.randint(1, 2**16)
            if contentType and "/" in contentType:
                filename = basename % contentType.split("/")[1]
            else:
                filename = basename % "jpg"
        image = NamedBlobImage(
            data=decodebytes(safe_bytes(str(node.text))),
            contentType=contentType,
            filename=filename,
        )
        if image.contentType is None and image.filename:
            image.contentType = mimetypes.guess_type(image.filename)[0]
        return (image, attr_unicode(node, "caption"))