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()
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()
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')
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)