Example #1
0
 def createImage(self, path, width=800, height=600, title=None):
     obj = self._createObject('Image', path, title=title)
     named_image = NamedImage()
     named_image.data = random_image(width, height)
     named_image.filename = u'test.jpg'
     named_image.contentType = u'image/jpg'
     obj.image = named_image
     obj.reindexObject()
Example #2
0
 def createNewsitem(self, path, title=None):
     obj = self._createObject('News Item', path, title=title)
     named_image = NamedImage()
     named_image.data = random_image(400, 200)
     named_image.filename = u'test.jpg'
     named_image.contentType = u'image/jpg'
     obj.image = named_image
     obj.reindexObject()
Example #3
0
 def createImage(self, path, width=800, height=600, title=None):
     obj = self._createObject('Image', path, title=title)
     named_image = NamedImage()
     named_image.data = random_image(width, height)
     named_image.filename = u'test.jpg'
     named_image.contentType = u'image/jpg'
     obj.image = named_image
     obj.reindexObject()
Example #4
0
 def createNewsitem(self, path, title=None):
     obj = self._createObject('News Item', path, title=title)
     named_image = NamedImage()
     named_image.data = random_image(400, 200)
     named_image.filename = u'test.jpg'
     named_image.contentType = u'image/jpg'
     obj.image = named_image
     obj.reindexObject()
Example #5
0
    def test_xml_image(self):

        from plone.namedfile import NamedImage

        img_data = open(os.path.join(os.path.dirname(__file__), 'sample.jpg'), 'rb').read()
        named_image = NamedImage()
        named_image.data = img_data
        named_image.filename = u'test.jpg'
        named_image.contentType = 'image/jpg'
        self.doc.xml_set('xml_image', named_image)

        named_image2 = self.doc.xml_get('xml_image')
        self.assertEqual(named_image2.data, img_data)
        self.assertEqual(named_image2.filename, u'test.jpg')
        self.assertEqual(named_image2.contentType, 'image/jpg')
Example #6
0
    def test_existing_content_tile_show_image(self):
        """
        """
        page_id = self.portal.invokeFactory('Document',
                                            'a-page',
                                            title=u'A page',
                                            description=u'A description',
                                            text=u'Hello World!')
        image_id = self.portal.invokeFactory('Image',
                                             'an-image',
                                             title=u'An Image',
                                             description=u'foo',
                                             image=NamedImage(
                                                 image(),
                                                 'image/png',
                                                 filename=u'color.png'))
        page_uuid = IUUID(self.portal[page_id])
        image_uuid = IUUID(self.portal[image_id])

        transaction.commit()
        self.unprivileged_browser.open(
            self.portalURL +
            '/@@plone.app.standardtiles.existingcontent/unique?content_uid=' +
            page_uuid + '&show_image=True')
        self.assertNotIn(u'<img src="', self.unprivileged_browser.contents)

        self.unprivileged_browser.open(
            self.portalURL +
            '/@@plone.app.standardtiles.existingcontent/unique?content_uid=' +
            image_uuid + '&show_image=True')

        self.assertIn(u'<img src="', self.unprivileged_browser.contents)
    def test_xml_image(self):

        from plone.namedfile import NamedImage

        img_data = open(os.path.join(os.path.dirname(__file__), 'sample.jpg'),
                        'rb').read()
        named_image = NamedImage()
        named_image.data = img_data
        named_image.filename = u'test.jpg'
        named_image.contentType = 'image/jpg'
        self.doc.xml_set('xml_image', named_image)

        named_image2 = self.doc.xml_get('xml_image')
        self.assertEqual(named_image2.data, img_data)
        self.assertEqual(named_image2.filename, u'test.jpg')
        self.assertEqual(named_image2.contentType, 'image/jpg')
Example #8
0
    def render(self, f, type = None):
        if f is None:
            return ''
        if type == 'TeX':
            return self.convertTo(
                'text/html',
                f.encode('utf-8'),
                mimetype='text/x-tex',
                encoding='utf-8',
            ).getData().decode('utf-8')
        if hasattr(f, 'output'):  # i.e. a RichTextField
            return f.output
        if hasattr(f, 'contentType'):  # i.e. a namedBlobFile
            if f.contentType.startswith('image/'):
                # Upgrade to a NamedImage
                f = NamedImage(f.data, f.contentType, f.filename)
                size = f.getImageSize()
                if size[0] <= 0:
                    return '<img class="mainfigure" src="%s" />' % (encodeDataUri(f.data, f.contentType))
                return '<img class="mainfigure" src="%s" width="%d" height="%d" />' % ((
                    encodeDataUri(f.data, f.contentType),
                ) + size)

            download_class = ''
            download_thing = ''
            if f.filename.endswith('.ggb'):
                # TODO: Should get plone to work it out
                f.contentType = 'application/vnd.geogebra.file'
                download_class = "geogebra_applet"
                download_thing = "applet"
            return '<a class="%s" download="%s" href="%s">%s</a>' % (
                download_class,
                f.filename,
                encodeDataUri(f.data, f.contentType),
                " ".join(("Click to download", download_thing)),
            )
        raise ValueError("Cannot interpret %s" % f)
    def test_image_tile(self):
        annotations = IAnnotations(self.page)
        annotations['plone.tiles.data.test'] = PersistentDict(
            {'image': NamedImage(image(), 'image/png', filename=u'color.png')})

        transaction.commit()

        self.browser.open(
            self.pageURL +
            '/@@plone.app.standardtiles.image/test?_authenticator={}'.format(
                createToken()))

        # Confirm pass CSRF protection on Plone 5
        try:
            self.browser.getControl(name='form.button.confirm').click()
        except LookupError:
            pass

        root = fromstring(self.browser.contents)
        nodes = root.xpath('//body//img')
        self.assertEqual(len(nodes), 1)