def test_haunt_image(self): """Create and test a Ghost Asset content type that haunt an image. """ with Transaction(): factory = self.root.manage_addProduct['Silva'] factory.manage_addGhostAsset('ghost', None, haunted=self.root.logo) self.assertIn('ghost', self.root.objectIds()) ghost = self.root._getOb('ghost') self.assertTrue(verifyObject(IGhostAsset, ghost)) self.assertIn(ghost, self.root.get_non_publishables()) self.assertEqual(ghost.get_link_status(), None) self.assertEqual(ghost.get_haunted(), self.root.logo) self.assertEqual(ghost.get_filename(), 'logo.png') self.assertEqual(ghost.get_mime_type(), 'image/png') self.assertTrue(IImageIncluable.providedBy(ghost)) self.assertEqual( ghost.get_file_size(), self.root.logo.get_file_size()) self.assertEqual( ghost.get_modification_datetime(), self.root.logo.get_modification_datetime()) self.assertEqual( aq_chain(ghost.get_haunted()), aq_chain(self.root.logo)) # Now edit an break the reference. ghost.set_haunted(0) self.assertIsInstance(ghost.get_link_status(), EmptyInvalidTarget) self.assertEqual(ghost.get_haunted(), None) self.assertEqual(ghost.get_filename(), 'ghost') self.assertEqual(ghost.get_file_size(), 0) self.assertEqual(ghost.get_mime_type(), 'application/octet-stream') self.assertFalse(IImageIncluable.providedBy(ghost))
def test_haunt_image(self): """Create and test a Ghost Asset content type that haunt an image. """ with Transaction(): factory = self.root.manage_addProduct['Silva'] factory.manage_addGhostAsset('ghost', None, haunted=self.root.logo) self.assertIn('ghost', self.root.objectIds()) ghost = self.root._getOb('ghost') self.assertTrue(verifyObject(IGhostAsset, ghost)) self.assertIn(ghost, self.root.get_non_publishables()) self.assertEqual(ghost.get_link_status(), None) self.assertEqual(ghost.get_haunted(), self.root.logo) self.assertEqual(ghost.get_filename(), 'logo.png') self.assertEqual(ghost.get_mime_type(), 'image/png') self.assertTrue(IImageIncluable.providedBy(ghost)) self.assertEqual(ghost.get_file_size(), self.root.logo.get_file_size()) self.assertEqual(ghost.get_modification_datetime(), self.root.logo.get_modification_datetime()) self.assertEqual(aq_chain(ghost.get_haunted()), aq_chain(self.root.logo)) # Now edit an break the reference. ghost.set_haunted(0) self.assertIsInstance(ghost.get_link_status(), EmptyInvalidTarget) self.assertEqual(ghost.get_haunted(), None) self.assertEqual(ghost.get_filename(), 'ghost') self.assertEqual(ghost.get_file_size(), 0) self.assertEqual(ghost.get_mime_type(), 'application/octet-stream') self.assertFalse(IImageIncluable.providedBy(ghost))
def _check_image(self, target): source = self.source if source is not None: is_image = IImage.providedBy(target) have_image = IImageIncluable.providedBy(source) if is_image and not have_image: alsoProvides(source, IImageIncluable) elif not is_image and have_image: noLongerProvides(source, IImageIncluable)
def test_haunt_file(self): """Create and test a Ghost Asset content type that haunt a file. """ with Transaction(): factory = self.root.manage_addProduct['Silva'] factory.manage_addGhostAsset('ghost', None, haunted=self.root.text) self.assertIn('ghost', self.root.objectIds()) ghost = self.root._getOb('ghost') self.assertTrue(verifyObject(IGhostAsset, ghost)) self.assertIn(ghost, self.root.get_non_publishables()) self.assertEqual(ghost.get_link_status(), None) self.assertEqual(ghost.get_haunted(), self.root.text) self.assertEqual(ghost.get_filename(), 'text') self.assertEqual(ghost.get_mime_type(), 'text/plain') self.assertFalse(IImageIncluable.providedBy(ghost))
def __call__(self, tree): for block in tree.xpath('//div[contains(@class, "image")]'): images = block.xpath('descendant::img') assert len(images) == 1, u"Invalid image construction" image = images[0] if 'resolution' in image.attrib: image.attrib['data-silva-resolution'] = image.attrib['resolution'] del image.attrib['resolution'] if 'reference' in image.attrib: name, reference = self.get_reference(image.attrib['reference']) if reference is not None: target_id = '0' url = './++static++/silva.core.editor/broken-link.jpg' if reference.target_id: target_id = str(reference.target_id) target = reference.target if IImageIncluable.providedBy(target): url = absoluteURL(target, self.request) image.attrib['data-silva-reference'] = name image.attrib['data-silva-target'] = target_id image.attrib['src'] = url del image.attrib['reference'] elif 'src' in image.attrib: image.attrib['data-silva-url'] = image.attrib['src']
def update(self): self.is_image = IImageIncluable.providedBy(self.context) self.filename = self.context.get_filename() self.mime_type = self.context.get_mime_type() self.download_url = self.context.get_download_url(preview=True, request=self.request)
def update(self): self.is_image = IImageIncluable.providedBy(self.context) self.filename = self.context.get_filename() self.mime_type = self.context.get_mime_type() self.download_url = self.context.get_download_url( preview=True, request=self.request)