def wrapped_object(self): # Change KeyReference not to use unrestricted traverse. This # prevent unwanted Acquisition to get a different content that # expected if it is gone. if self.path is None: return self.object object = self.root for part in self.path.split('/')[1:]: object = object._getOb(part, _marker) if object is _marker: return None chain = aq_chain(object) # Try to ensure we have a request at the acquisition root # by using the one from getSite if not len(chain) or not isinstance(chain[-1], RequestContainer): site = getSite() site_chain = aq_chain(site) if (len(site_chain) and isinstance(site_chain[-1], RequestContainer)): req = site_chain[-1] new_obj = req # rebuld the chain with the request at the bottom for item in reversed(chain): new_obj = aq_base(item).__of__(new_obj) obj = new_obj return obj
def test_field_shown_and_default_values(self): """Import a Silva Find content that some search fields shown field default values. """ with Transaction(): importer = self.assertImportFile( 'test_import_default_values.silvaxml', ['/root/folder', '/root/folder/search']) self.assertEqual(importer.getProblems(), []) folder = self.root.folder self.assertTrue(verifyObject(IFolder, folder)) search = folder.search self.assertTrue(verifyObject(IFind, search)) self.assertItemsEqual(search.shownFields, ['fulltext', 'meta_type']) self.assertItemsEqual(search.shownResultsFields, [ 'breadcrumbs', 'date', 'icon', 'link', 'ranking', 'resultcount', 'textsnippet', 'thumbnail' ]) schema = search.getSearchSchema() data = getMultiAdapter((schema['fulltext'], search), ICriterionData) self.assertEqual(data.getValue(), u"silva rox") data = getMultiAdapter((schema['meta_type'], search), ICriterionData) self.assertEqual(data.getValue(), ['Silva Document', 'Silva Folder', 'Silva File']) data = getMultiAdapter((schema['path'], search), ICriterionData) self.assertEqual(data.getValue(), self.root.folder) self.assertEqual(aq_chain(data.getValue()), aq_chain(self.root.folder))
def test_ghost_folder_existing_rename(self): """Import a ghost folder with an ID of a already existing element. """ factory = self.root.manage_addProduct['Silva'] factory.manage_addIndexer('folder', 'Folder') self.assertFalse(interfaces.IFolder.providedBy(self.root.folder)) importer = self.assertImportFile( 'test_import_ghostfolder.silvaxml', ['/root/import_of_folder', '/root/import_of_folder/container', '/root/import_of_folder/container/indexer', '/root/import_of_folder/container/link', '/root/import_of_folder/ghost']) self.assertEqual(importer.getProblems(), []) self.assertFalse( interfaces.IFolder.providedBy(self.root.folder)) self.assertTrue( interfaces.IFolder.providedBy(self.root.import_of_folder)) self.assertItemsEqual( self.root.import_of_folder.objectIds(), ['container', 'ghost']) self.assertItemsEqual( self.root.import_of_folder.container.objectIds(), ['indexer', 'link']) folder = self.root.import_of_folder.ghost container = self.root.import_of_folder.container self.assertTrue(interfaces.IGhostFolder.providedBy(folder)) self.assertEqual(folder.get_haunted(), container) self.assertEqual(aq_chain(folder.get_haunted()), aq_chain(container)) self.assertItemsEqual(folder.objectIds(), container.objectIds())
def test_ghost_to_link(self): """Import a ghost to link. """ importer = self.assertImportZip('test_import_ghost.zip', [ '/root/folder', '/root/folder/public', '/root/folder/public/ghost_of_infrae', '/root/folder/infrae' ]) self.assertEqual(importer.getProblems(), []) self.assertItemsEqual(self.root.folder.objectIds(), ['public', 'infrae']) self.assertItemsEqual(self.root.folder.public.objectIds(), ['ghost_of_infrae']) link = self.root.folder.infrae ghost = self.root.folder.public.ghost_of_infrae self.assertTrue(interfaces.ILink.providedBy(link)) self.assertTrue(interfaces.IGhost.providedBy(ghost)) version = ghost.get_viewable() self.assertFalse(version is None) self.assertEqual(ghost.get_editable(), None) self.assertEqual(version.get_title(), u'Public site') self.assertEqual(link.get_title(), u'Public site') self.assertEqual(version.get_haunted(), link) self.assertEqual(aq_chain(version.get_haunted()), aq_chain(link)) get_metadata = self.metadata.getMetadata(version).get self.assertEqual(get_metadata('silva-extra', 'comment'), u'Public site')
def test_link_to_file_existing_rename(self): """Import a link to file in a folder that already exists. The imported folder should be done under a different name. """ factory = self.root.manage_addProduct['Silva'] factory.manage_addIndexer('folder', 'Folder') indexer = self.root.folder self.assertFalse(interfaces.IFolder.providedBy(self.root.folder)) importer = self.assertImportZip('test_import_link.zip', [ '/root/import_of_folder', '/root/import_of_folder/file', '/root/import_of_folder/index', '/root/import_of_folder/new', '/root/import_of_folder/new/link' ]) self.assertEqual(importer.getProblems(), []) self.assertTrue( interfaces.IFolder.providedBy(self.root.import_of_folder)) self.assertFalse(interfaces.IFolder.providedBy(self.root.folder)) self.assertEqual(indexer, self.root.folder) self.assertItemsEqual(self.root.import_of_folder.objectIds(), ['file', 'index', 'new']) self.assertItemsEqual(self.root.import_of_folder.new.objectIds(), ['link']) link = self.root.import_of_folder.new.link datafile = self.root.import_of_folder.file self.assertTrue(interfaces.ILink.providedBy(link)) self.assertTrue(interfaces.IFile.providedBy(datafile)) self.assertEqual(datafile.get_title(), u'Torvald file') version = link.get_editable() self.assertEqual(version.get_relative(), True) self.assertEqual(version.get_target(), datafile) self.assertEqual(aq_chain(version.get_target()), aq_chain(datafile))
def test_ghost_to_link_existing_rename(self): """Import a ghost to a link, in a folder is already existing. """ factory = self.root.manage_addProduct['Silva'] factory.manage_addIndexer('folder', 'Folder') self.assertFalse(interfaces.IFolder.providedBy(self.root.folder)) importer = self.assertImportZip('test_import_ghost.zip', [ '/root/import_of_folder', '/root/import_of_folder/public', '/root/import_of_folder/public/ghost_of_infrae', '/root/import_of_folder/infrae' ]) self.assertEqual(importer.getProblems(), []) # This didn't touch the existing folder self.assertFalse(interfaces.IFolder.providedBy(self.root.folder)) self.assertItemsEqual(self.root.import_of_folder.objectIds(), ['public', 'infrae']) self.assertItemsEqual(self.root.import_of_folder.public.objectIds(), ['ghost_of_infrae']) link = self.root.import_of_folder.infrae ghost = self.root.import_of_folder.public.ghost_of_infrae self.assertTrue(interfaces.ILink.providedBy(link)) self.assertTrue(interfaces.IGhost.providedBy(ghost)) version = ghost.get_viewable() self.assertFalse(version is None) self.assertEqual(ghost.get_editable(), None) self.assertEqual(version.get_title(), u'Public site') self.assertEqual(version.get_haunted(), link) self.assertEqual(aq_chain(version.get_haunted()), aq_chain(link))
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 trigger_mopage_refresh(obj, event): event_pages = filter(None, map(lambda parent: IEventPage(parent, None), aq_chain(obj))) if not event_pages: # We are not within an event page. # We only trigger when publishing an event page # or a child of an event page. return triggers = filter(None, map(lambda parent: IPublisherMopageTrigger(parent, None), aq_chain(obj))) if not triggers or not triggers[0].is_enabled(): return for events in event_pages: IMopageModificationDate(events).touch() from collective.taskqueue import taskqueue trigger_url = triggers[0].build_trigger_url() callback_path = '/'.join(getSite().getPhysicalPath() + ('taskqueue_events_trigger_mopage_refresh',)) taskqueue.add(callback_path, params={'target': trigger_url})
def test_ghost_to_link_existing_rename(self): """Import a ghost to a link, in a folder is already existing. """ factory = self.root.manage_addProduct['Silva'] factory.manage_addIndexer('folder', 'Folder') self.assertFalse(interfaces.IFolder.providedBy(self.root.folder)) importer = self.assertImportZip( 'test_import_ghost.zip', ['/root/import_of_folder', '/root/import_of_folder/public', '/root/import_of_folder/public/ghost_of_infrae', '/root/import_of_folder/infrae']) self.assertEqual(importer.getProblems(), []) # This didn't touch the existing folder self.assertFalse(interfaces.IFolder.providedBy(self.root.folder)) self.assertItemsEqual( self.root.import_of_folder.objectIds(), ['public', 'infrae']) self.assertItemsEqual( self.root.import_of_folder.public.objectIds(), ['ghost_of_infrae']) link = self.root.import_of_folder.infrae ghost = self.root.import_of_folder.public.ghost_of_infrae self.assertTrue(interfaces.ILink.providedBy(link)) self.assertTrue(interfaces.IGhost.providedBy(ghost)) version = ghost.get_viewable() self.assertFalse(version is None) self.assertEqual(ghost.get_editable(), None) self.assertEqual(version.get_title(), u'Public site') self.assertEqual(version.get_haunted(), link) self.assertEqual(aq_chain(version.get_haunted()), aq_chain(link))
def test_link_to_file_existing_replace(self): """Import a link to file in a folder that already exists. It replace the ids, it doesn't check if the types are the same. """ factory = self.root.manage_addProduct['Silva'] factory.manage_addIndexer('folder', 'Folder') self.assertFalse(interfaces.IFolder.providedBy(self.root.folder)) importer = self.assertImportZip('test_import_link.zip', [ '/root/folder', '/root/folder/file', '/root/folder/index', '/root/folder/new', '/root/folder/new/link' ], replace=True) self.assertEqual(importer.getProblems(), []) self.assertTrue(interfaces.IFolder.providedBy(self.root.folder)) self.assertItemsEqual(self.root.folder.objectIds(), ['file', 'index', 'new']) self.assertItemsEqual(self.root.folder.new.objectIds(), ['link']) link = self.root.folder.new.link datafile = self.root.folder.file self.assertTrue(interfaces.ILink.providedBy(link)) self.assertTrue(interfaces.IFile.providedBy(datafile)) self.assertEqual(datafile.get_title(), u'Torvald file') version = link.get_editable() self.assertEqual(version.get_relative(), True) self.assertEqual(version.get_target(), datafile) self.assertEqual(aq_chain(version.get_target()), aq_chain(datafile))
def test_ghost_to_link(self): """Import a ghost to link. """ importer = self.assertImportZip( 'test_import_ghost.zip', ['/root/folder', '/root/folder/public', '/root/folder/public/ghost_of_infrae', '/root/folder/infrae']) self.assertEqual(importer.getProblems(), []) self.assertItemsEqual( self.root.folder.objectIds(), ['public', 'infrae']) self.assertItemsEqual( self.root.folder.public.objectIds(), ['ghost_of_infrae']) link = self.root.folder.infrae ghost = self.root.folder.public.ghost_of_infrae self.assertTrue(interfaces.ILink.providedBy(link)) self.assertTrue(interfaces.IGhost.providedBy(ghost)) version = ghost.get_viewable() self.assertFalse(version is None) self.assertEqual(ghost.get_editable(), None) self.assertEqual(version.get_title(), u'Public site') self.assertEqual(link.get_title(), u'Public site') self.assertEqual(version.get_haunted(), link) self.assertEqual(aq_chain(version.get_haunted()), aq_chain(link)) get_metadata = self.metadata.getMetadata(version).get self.assertEqual( get_metadata('silva-extra', 'comment'), u'Public site')
def test_set_reference_target(self): """We create and use a reference, setting its target. """ # We no references at first self.assertEqual( list(self.service.get_references_to(self.root.publication)), []) self.assertEqual( list(self.service.get_references_from(self.root.folder)), []) reference = self.service.new_reference(self.root.folder, name=u'link') self.assertEqual(reference.target, None) reference.set_target(self.root.publication) self.assertEqual(reference.target, self.root.publication) self.assertEqual( aq_chain(reference.target), aq_chain(self.root.publication)) searched_reference = self.service.get_reference( self.root.folder, name=u'link') self.assertTrue(verifyObject(IReferenceValue, searched_reference)) self.assertEqual(searched_reference.target, self.root.publication) # We do have now self.assertEqual( list(self.service.get_references_to(self.root.publication)), [reference]) self.assertEqual( list(self.service.get_references_from(self.root.folder)), [reference])
def test_ghost_haunt_add_ghosts_for_ghosts(self): """Test modification: adding ghost to the target will create new ghosts in the ghost golder when it is haunted. """ factory = self.root.target.manage_addProduct['Silva'] factory.manage_addGhostFolder('ghost', None, haunted=self.root.folder) ghost = self.root.target.ghost factory = self.root.folder.manage_addProduct['Silva'] factory.manage_addGhost('notes', None, haunted=self.root.folder.document) IPublicationWorkflow(self.root.folder.notes).publish() self.assertFalse('notes' in ghost.objectIds()) self.assertTrue(ghost.haunt()) self.assertIn('notes', ghost.objectIds()) self.assertTrue(verifyObject(IGhost, ghost.notes)) version = ghost.notes.get_editable() self.assertIs(version, None) version = ghost.notes.get_viewable() self.assertIsNot(version, None) self.assertEqual(version.get_haunted(), self.root.folder.document) self.assertEqual(version.get_link_status(), None) self.assertEqual(aq_chain(version.get_haunted()), aq_chain(self.root.folder.document))
def test_ghost_haunt_convert_assets_to_ghost_assets(self): """Test update: old ghost folders might have copys of assets instead of ghost assets poiting to them. In this case, if you re-haunt the folder, they should be replaced with ghost assets. """ factory = self.root.target.manage_addProduct['Silva'] factory.manage_addGhostFolder('ghost', None, haunted=self.root.folder) ghost = self.root.target.ghost factory = self.root.folder.manage_addProduct['Silva'] factory.manage_addMockupAsset('data', 'Data set 1') factory = self.root.folder.publication.manage_addProduct['Silva'] factory.manage_addMockupAsset('results', 'Results set 1') factory.manage_addMockupAsset('analyze', 'Analyze set 1') # Add assets with the same id in the ghost folder. factory = ghost.manage_addProduct['Silva'] factory.manage_addMockupAsset('data', 'Data set 1') factory = ghost.publication.manage_addProduct['Silva'] factory.manage_addMockupAsset('results', 'Results set 1') factory.manage_addMockupNonPublishable('analyze', 'Analyze set 1') # We add a reference. It should be kept. service = getUtility(IReferenceService) reference = service.new_reference(self.root.folder, name=u"test") reference.set_target(ghost.data) self.assertTrue(verifyObject(IMockupAsset, ghost.data)) # Now if we rehaunt the folder, they should be replaced by ghost assets. self.assertTrue(ghost.haunt()) self.assertIn('data', ghost.objectIds()) self.assertTrue(verifyObject(IGhostAsset, ghost.data)) self.assertEqual( ghost.data.get_haunted(), self.root.folder.data) self.assertEqual( aq_chain(ghost.data.get_haunted()), aq_chain(self.root.folder.data)) # The reference should have been moved as well. references = list(service.get_references_to(ghost.data, name=u"test")) self.assertEqual(len(references), 1) self.assertEqual(references[0].source, self.root.folder) self.assertEqual(references[0].target, ghost.data) # Other content were changed properly as well. self.assertIn('publication', ghost.objectIds()) self.assertTrue(verifyObject(IGhostFolder, ghost.publication)) self.assertIn('results', ghost.publication.objectIds()) self.assertTrue(verifyObject(IGhostAsset, ghost.publication.results)) self.assertEqual( ghost.publication.results.get_haunted(), self.root.folder.publication.results) self.assertEqual( aq_chain(ghost.publication.results.get_haunted()), aq_chain(self.root.folder.publication.results)) # Analyze was not an asset, it didn't get replaced self.assertIn('analyze', ghost.publication.objectIds()) self.assertTrue(verifyObject(IMockupNonPublishable, ghost.publication.analyze))
def test_ghost_haunt_add_assets(self): """Test modifications: adding assets in the target creates new ghost assets in the ghost folder when it is haunted. """ factory = self.root.target.manage_addProduct['Silva'] factory.manage_addGhostFolder('ghost', None, haunted=self.root.folder) ghost = self.root.target.ghost factory = self.root.folder.manage_addProduct['Silva'] factory.manage_addMockupAsset('data', 'Data set 1') factory = self.root.folder.publication.manage_addProduct['Silva'] factory.manage_addMockupAsset('results', 'Results set 1') self.assertIn('publication', ghost.objectIds()) self.assertTrue(verifyObject(IGhostFolder, ghost.publication)) self.assertNotIn('data', ghost.objectIds()) self.assertNotIn('results', ghost.publication.objectIds()) self.assertTrue(ghost.haunt()) self.assertIn('data', ghost.objectIds()) self.assertTrue(verifyObject(IGhostAsset, ghost.data)) self.assertEqual(ghost.data.get_haunted(), self.root.folder.data) self.assertEqual(aq_chain(ghost.data.get_haunted()), aq_chain(self.root.folder.data)) self.assertIn('publication', ghost.objectIds()) self.assertTrue(verifyObject(IGhostFolder, ghost.publication)) self.assertIn('results', ghost.publication.objectIds()) self.assertTrue(verifyObject(IGhostAsset, ghost.publication.results)) self.assertEqual(ghost.publication.results.get_haunted(), self.root.folder.publication.results) self.assertEqual(aq_chain(ghost.publication.results.get_haunted()), aq_chain(self.root.folder.publication.results))
def test_ghost_haunt_remove_assets(self): """Test modifications: removing asssets in the target doesn't remove them automatically in the ghost folder, but this is done when the ghost folder is haunted. """ factory = self.root.folder.manage_addProduct['Silva'] factory.manage_addMockupAsset('data', 'Data set 1') factory.manage_addMockupAsset('export', 'Export set 1') factory = self.root.target.manage_addProduct['Silva'] factory.manage_addGhostFolder('ghost', None, haunted=self.root.folder) ghost = self.root.target.ghost self.assertIn('data', ghost.objectIds()) self.assertTrue(verifyObject(IGhostAsset, ghost.data)) self.assertEqual(ghost.data.get_haunted(), self.root.folder.data) self.assertEqual(aq_chain(ghost.data.get_haunted()), aq_chain(self.root.folder.data)) self.assertIn('export', ghost.objectIds()) self.assertTrue(verifyObject(IGhostAsset, ghost.export)) self.assertEqual(ghost.export.get_haunted(), self.root.folder.export) self.assertEqual(aq_chain(ghost.export.get_haunted()), aq_chain(self.root.folder.export)) with IContainerManager(self.root.folder).deleter() as deleter: deleter(self.root.folder.data) deleter(self.root.folder.export) # Ghost should have been auto-deleted self.assertNotIn('data', ghost.objectIds()) self.assertNotIn('export', ghost.objectIds()) # And they won't come back self.assertTrue(ghost.haunt()) self.assertNotIn('data', ghost.objectIds()) self.assertNotIn('export', ghost.objectIds())
def test_ghost_haunt_add_ghost_folders_for_ghost_folders(self): """Test modification: add a ghost folder in the target folder. When the ghost folder will be haunted, it will create a ghost folder with the same target as the ghosted ghost folder. """ factory = self.root.target.manage_addProduct['Silva'] factory.manage_addGhostFolder( 'ghost', None, haunted=self.root.folder) ghost = self.root.target.ghost factory = self.root.folder.manage_addProduct['Silva'] factory.manage_addGhostFolder( 'backup', None, haunted=self.root.folder.publication) self.assertNotIn('backup', ghost.objectIds()) self.assertTrue(ghost.haunt()) self.assertIn('backup', ghost.objectIds()) self.assertTrue(verifyObject(IGhostFolder, ghost.backup)) self.assertEqual(ghost.backup.get_link_status(), None) self.assertEqual( ghost.backup.get_haunted(), self.root.folder.publication) self.assertEqual( aq_chain(ghost.backup.get_haunted()), aq_chain(self.root.folder.publication)) # Content in this ghost folder have been ghosted self.assertIn('document', ghost.backup.objectIds()) self.assertTrue(verifyObject(IGhost, ghost.backup.document))
def test_copy_paste_contained_source(self): """Copy and paste a folder that contained a Silva which have references out of this folder. """ reference = self.service.new_reference( self.root.folder.contained, name=u'myname') reference.set_target(self.root.publication) # Copy/paste folder token = self.root.manage_copyObjects(['folder',]) self.root.publication.manage_pasteObjects(token) self.assertTrue('folder' in self.root.objectIds()) self.assertTrue('folder' in self.root.publication.objectIds()) # The reference should have been cloned cloned_reference = self.service.get_reference( self.root.publication.folder.contained, name=u'myname') self.assertTrue(verifyObject(IReferenceValue, cloned_reference)) self.assertEquals( cloned_reference.source, self.root.publication.folder.contained) self.assertEquals( aq_chain(cloned_reference.source), aq_chain(self.root.publication.folder.contained)) self.assertEquals( cloned_reference.target, self.root.publication) self.assertEquals( aq_chain(cloned_reference.target), aq_chain(self.root.publication)) self.assertEqual( len(list(self.service.get_references_to(self.root.publication))), 2)
def test_ghost_asset(self): """Import a ghost asset pointing to an image. """ importer = self.assertImportZip( 'test_import_ghost_asset.zip', ['/root/folder', '/root/folder/torvald', '/root/folder/ghost']) self.assertEqual(importer.getProblems(), []) self.assertItemsEqual( self.root.folder.objectIds(), ['torvald', 'ghost']) image = self.root.folder.torvald self.assertTrue(interfaces.IImage.providedBy(image)) self.assertEqual(image.get_web_format(), 'GIF') self.assertEqual(image.get_web_scale(), '200%') ghost = self.root.folder.ghost self.assertTrue(interfaces.IGhostAsset.providedBy(ghost)) self.assertEqual(ghost.get_haunted(), image) self.assertEqual(aq_chain(ghost.get_haunted()), aq_chain(image)) get_metadata = self.metadata.getMetadata(image).get self.assertEqual( get_metadata('silva-extra', 'comment'), u'Torvald public face.')
def test_ghost_haunt_add_ghosts_for_ghosts(self): """Test modification: adding ghost to the target will create new ghosts in the ghost golder when it is haunted. """ factory = self.root.target.manage_addProduct['Silva'] factory.manage_addGhostFolder('ghost', None, haunted=self.root.folder) ghost = self.root.target.ghost factory = self.root.folder.manage_addProduct['Silva'] factory.manage_addGhost( 'notes', None, haunted=self.root.folder.document) IPublicationWorkflow(self.root.folder.notes).publish() self.assertFalse('notes' in ghost.objectIds()) self.assertTrue(ghost.haunt()) self.assertIn('notes', ghost.objectIds()) self.assertTrue(verifyObject(IGhost, ghost.notes)) version = ghost.notes.get_editable() self.assertIs(version, None) version = ghost.notes.get_viewable() self.assertIsNot(version, None) self.assertEqual(version.get_haunted(), self.root.folder.document) self.assertEqual(version.get_link_status(), None) self.assertEqual( aq_chain(version.get_haunted()), aq_chain(self.root.folder.document))
def test_ghost_publication(self): """Test a Ghost Folder haunting to a Publication. """ factory = self.root.target.manage_addProduct['Silva'] factory.manage_addGhostFolder( 'ghost', None, haunted=self.root.folder.publication) ghost = self.root.target.ghost publication = self.root.folder.publication self.assertTrue(verifyObject(IGhostFolder, ghost)) self.assertEqual(ghost.get_link_status(), None) self.assertEqual(ghost.get_haunted(), publication) self.assertEqual(aq_chain(ghost.get_haunted()), aq_chain(publication)) # Content have been ghost with the same IDS self.assertEqual( ghost.objectIds(), ['document', 'folder']) # If you ask the publication on the ghost folder it will # return itself (and if done on a lower ghost folder ghost a # folder as well). self.assertEqual(ghost.get_publication(), ghost) self.assertEqual(ghost.folder.get_publication(), ghost)
def test_ghost_haunt_add_ghost_folders_for_ghost_folders(self): """Test modification: add a ghost folder in the target folder. When the ghost folder will be haunted, it will create a ghost folder with the same target as the ghosted ghost folder. """ factory = self.root.target.manage_addProduct['Silva'] factory.manage_addGhostFolder('ghost', None, haunted=self.root.folder) ghost = self.root.target.ghost factory = self.root.folder.manage_addProduct['Silva'] factory.manage_addGhostFolder('backup', None, haunted=self.root.folder.publication) self.assertNotIn('backup', ghost.objectIds()) self.assertTrue(ghost.haunt()) self.assertIn('backup', ghost.objectIds()) self.assertTrue(verifyObject(IGhostFolder, ghost.backup)) self.assertEqual(ghost.backup.get_link_status(), None) self.assertEqual(ghost.backup.get_haunted(), self.root.folder.publication) self.assertEqual(aq_chain(ghost.backup.get_haunted()), aq_chain(self.root.folder.publication)) # Content in this ghost folder have been ghosted self.assertIn('document', ghost.backup.objectIds()) self.assertTrue(verifyObject(IGhost, ghost.backup.document))
def test_ghost_folder_existing_rename(self): """Import a ghost folder with an ID of a already existing element. """ factory = self.root.manage_addProduct['Silva'] factory.manage_addIndexer('folder', 'Folder') self.assertFalse(interfaces.IFolder.providedBy(self.root.folder)) importer = self.assertImportFile('test_import_ghostfolder.silvaxml', [ '/root/import_of_folder', '/root/import_of_folder/container', '/root/import_of_folder/container/indexer', '/root/import_of_folder/container/link', '/root/import_of_folder/ghost' ]) self.assertEqual(importer.getProblems(), []) self.assertFalse(interfaces.IFolder.providedBy(self.root.folder)) self.assertTrue( interfaces.IFolder.providedBy(self.root.import_of_folder)) self.assertItemsEqual(self.root.import_of_folder.objectIds(), ['container', 'ghost']) self.assertItemsEqual(self.root.import_of_folder.container.objectIds(), ['indexer', 'link']) folder = self.root.import_of_folder.ghost container = self.root.import_of_folder.container self.assertTrue(interfaces.IGhostFolder.providedBy(folder)) self.assertEqual(folder.get_haunted(), container) self.assertEqual(aq_chain(folder.get_haunted()), aq_chain(container)) self.assertItemsEqual(folder.objectIds(), container.objectIds())
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 list_paths(self): '''''' self.connect() device = self.dmd.Devices.findDevice(self.options.device) if device is None: DEFAULTLOG.error("Device '{}' not found.".format( self.options.device)) return from Acquisition import aq_chain from Products.ZenRelations.RelationshipBase import RelationshipBase all_paths = set() included_paths = set() class_summary = collections.defaultdict(set) for component in device.getDeviceComponents(): for facet in component.get_facets(recurse_all=True): path = [] for obj in aq_chain(facet): if obj == component: break if isinstance(obj, RelationshipBase): path.insert(0, obj.id) all_paths.add(component.meta_type + ":" + "/".join(path) + ":" + facet.meta_type) for facet in component.get_facets(): path = [] for obj in aq_chain(facet): if obj == component: break if isinstance(obj, RelationshipBase): path.insert(0, obj.id) all_paths.add(component.meta_type + ":" + "/".join(path) + ":" + facet.meta_type) included_paths.add(component.meta_type + ":" + "/".join(path) + ":" + facet.meta_type) class_summary[component.meta_type].add(facet.meta_type) print "Paths\n-----\n" for path in sorted(all_paths): if path in included_paths: if "/" not in path: # normally all direct relationships are included print "DIRECT " + path else: # sometimes extra paths are pulled in due to extra_paths # configuration. print "EXTRA " + path else: print "EXCLUDE " + path print "\nClass Summary\n-------------\n" for source_class in sorted(class_summary.keys()): print "{} is reachable from {}".format( source_class, ", ".join(sorted(class_summary[source_class])))
def test_new_reference_link(self): """On input, a new link creates a new reference. """ version = self.root.document.get_editable() service = getUtility(IReferenceService) target_id = get_content_id(self.root.target) # By default the document as no reference self.assertEqual(list(service.get_references_from(version)), []) intern_format = self.transform( """ <p> <a class="link" href="javascript:void(0)" data-silva-reference="new" data-silva-target="%s">To Target</a> </p> """ % (target_id), ISaveEditorFilter) # After transformation a reference is created to target references = list(service.get_references_from(version)) self.assertEqual(len(references), 1) reference = references[0] self.assertEqual(reference.source, version) self.assertEqual(aq_chain(reference.source), aq_chain(version)) self.assertEqual(reference.target, self.root.target) self.assertEqual(aq_chain(reference.target), aq_chain(self.root.target)) self.assertEqual(len(reference.tags), 2) reference_name = reference.tags[1] self.assertEqual(reference.tags, [u'test link', reference_name]) # And the HTML is changed self.assertXMLEqual( intern_format, """ <p> <a class="link" reference="%s">To Target</a> </p> """ % (reference_name)) # Now we can rerender this for the editor extern_format = self.transform( intern_format, IInputEditorFilter) self.assertXMLEqual( extern_format, """ <p> <a class="link" data-silva-reference="%s" data-silva-target="%s" href="javascript:void(0)"> To Target</a> </p> """ % (reference_name, target_id))
def test_manual_aq_setting(self): ''' Test __of__ operator on an object that is not connected to an acquisition scheme ''' temp_document = ATDocument('temp_document') chain = aq_chain(temp_document) self.assertEquals(len(chain), 1) chain1 = aq_chain(temp_document.__of__(self.portal)) self.assertEquals(len(chain1), 4)
def test_link_to_file_existing_rename_twice(self): """Import a link to file in a folder that already exists two times. The imported folder should be done under a different name for each import. """ factory = self.root.manage_addProduct['Silva'] factory.manage_addIndexer('folder', 'Folder') self.assertFalse(interfaces.IFolder.providedBy(self.root.folder)) importer = self.assertImportZip( 'test_import_link.zip', ['/root/import_of_folder', '/root/import_of_folder/file', '/root/import_of_folder/index', '/root/import_of_folder/new', '/root/import_of_folder/new/link']) self.assertEqual(importer.getProblems(), []) self.assertTrue( interfaces.IFolder.providedBy(self.root.import_of_folder)) self.assertFalse(interfaces.IFolder.providedBy(self.root.folder)) importer = self.assertImportZip( 'test_import_link.zip', ['/root/import2_of_folder', '/root/import2_of_folder/file', '/root/import2_of_folder/index', '/root/import2_of_folder/new', '/root/import2_of_folder/new/link']) self.assertEqual(importer.getProblems(), []) self.assertTrue( interfaces.IFolder.providedBy(self.root.import2_of_folder)) self.assertFalse(interfaces.IFolder.providedBy(self.root.folder)) link = self.root.import_of_folder.new.link datafile = self.root.import_of_folder.file self.assertTrue(interfaces.ILink.providedBy(link)) self.assertTrue(interfaces.IFile.providedBy(datafile)) self.assertEqual(datafile.get_title(), u'Torvald file') version = link.get_editable() self.assertEqual(version.get_relative(), True) self.assertEqual(version.get_target(), datafile) self.assertEqual(aq_chain(version.get_target()), aq_chain(datafile)) link2 = self.root.import2_of_folder.new.link datafile2 = self.root.import2_of_folder.file self.assertTrue(interfaces.ILink.providedBy(link2)) self.assertTrue(interfaces.IFile.providedBy(datafile2)) self.assertEqual(datafile2.get_title(), u'Torvald file') version2 = link2.get_editable() self.assertEqual(version2.get_relative(), True) self.assertEqual(version2.get_target(), datafile2) self.assertEqual(aq_chain(version2.get_target()), aq_chain(datafile2))
def test_new_link_round_trip(self): """We create a new link which is a reference to a content in Silva, by transforming Kupu->Silva, and verify we get back our link in Kupu by transforming Silva->Kupu. """ service = component.getUtility(IReferenceService) target_id = get_content_id(self.root.folder) version = self.root.document.get_editable() # At first there is no references self.assertEqual(list(service.get_references_from(version)), []) self.assertEqual(list(service.get_references_to(self.root.folder)), []) html = TEST_LINK_HTML % ('new', target_id) # We convert our HTML with a new reference to Kupu node = self.transformer.to_source(targetobj=html, context=self.context) link = node.query_one('link') self.assertEqual(link.name(), 'link') self.failUnless(link.hasattr('reference')) reference_name = link.getattr('reference') result = node.asBytes('utf-8') self.assertEqual( result, '<link target="_blank" reference="%s" title="">My link</link>' % ( reference_name)) # We verify that the reference has been created. reference = service.get_reference(version, reference_name) self.assertEqual(reference.source, version) self.assertEqual(aq_chain(reference.source), aq_chain(version)) self.assertEqual(reference.target, self.root.folder) self.assertEqual(aq_chain(reference.target), aq_chain(self.root.folder)) self.assertEqual(reference.tags, [u"document link", reference_name]) self.assertEqual( list(service.get_references_to(self.root.folder)), [reference]) self.assertEqual( list(service.get_references_from(version)), [reference]) # We can get back the HTML with a reference name roundtrip = self.transformer.to_target( sourceobj=result, context=self.context).asBytes('utf-8') self.assertEqual( roundtrip, TEST_LINK_HTML % (reference_name, target_id)) # Our new reference has been kept self.assertEqual( list(service.get_references_to(self.root.folder)), [reference]) self.assertEqual( list(service.get_references_from(version)), [reference])
def test_link_to_file_update(self): """Import a link that is linked to a file. """ factory = self.root.manage_addProduct['Silva'] factory.manage_addFolder('folder', 'Existing folder') factory = self.root.folder.manage_addProduct['Silva'] factory.manage_addFolder('new', 'Existing new folder') factory = self.root.folder.new.manage_addProduct['Silva'] factory.manage_addLink('link', 'Link to Silva', url='http://silvacms.org') importer = self.assertImportZip( 'test_import_link.zip', ['/root/folder', '/root/folder/file', '/root/folder/index', '/root/folder/new', '/root/folder/new/link'], update=True) self.assertEqual(importer.getProblems(), []) self.assertItemsEqual( self.root.folder.objectIds(), ['file', 'index', 'new']) self.assertItemsEqual( self.root.folder.new.objectIds(), ['link']) link = self.root.folder.new.link datafile = self.root.folder.file self.assertTrue(interfaces.ILink.providedBy(link)) self.assertTrue(interfaces.IFile.providedBy(datafile)) self.assertEqual(datafile.get_title(), u'Torvald file') version = link.get_editable() self.assertFalse(version is None) self.assertEqual(link.get_viewable(), None) self.assertEqual(version.get_title(), u'Last file') self.assertEqual( DateTime('2004-04-23T16:13:39Z'), version.get_modification_datetime()) binding = self.metadata.getMetadata(version) self.assertEqual( binding.get('silva-extra', 'content_description'), u'Link to the lastest file.') self.assertEqual(version.get_relative(), True) self.assertEqual(version.get_target(), datafile) self.assertEqual(aq_chain(version.get_target()), aq_chain(datafile)) binding = self.metadata.getMetadata(datafile) self.assertEqual( binding.get('silva-extra', 'comment'), u'This file contains Torvald lastest whereabouts.')
def list_paths(self): '''''' self.connect() device = self.dmd.Devices.findDevice(self.options.device) if device is None: DEFAULTLOG.error("Device '{}' not found.".format(self.options.device)) return from Acquisition import aq_chain from Products.ZenRelations.RelationshipBase import RelationshipBase all_paths = set() included_paths = set() class_summary = collections.defaultdict(set) for component in device.getDeviceComponents(): for facet in component.get_facets(recurse_all=True): path = [] for obj in aq_chain(facet): if obj == component: break if isinstance(obj, RelationshipBase): path.insert(0, obj.id) all_paths.add(component.meta_type + ":" + "/".join(path) + ":" + facet.meta_type) for facet in component.get_facets(): path = [] for obj in aq_chain(facet): if obj == component: break if isinstance(obj, RelationshipBase): path.insert(0, obj.id) all_paths.add(component.meta_type + ":" + "/".join(path) + ":" + facet.meta_type) included_paths.add(component.meta_type + ":" + "/".join(path) + ":" + facet.meta_type) class_summary[component.meta_type].add(facet.meta_type) print "Paths\n-----\n" for path in sorted(all_paths): if path in included_paths: if "/" not in path: # normally all direct relationships are included print "DIRECT " + path else: # sometimes extra paths are pulled in due to extra_paths # configuration. print "EXTRA " + path else: print "EXCLUDE " + path print "\nClass Summary\n-------------\n" for source_class in sorted(class_summary.keys()): print "{} is reachable from {}".format(source_class, ", ".join(sorted(class_summary[source_class])))
def test_new_link_round_trip(self): """We create a new link which is a reference to a content in Silva, by transforming Kupu->Silva, and verify we get back our link in Kupu by transforming Silva->Kupu. """ service = component.getUtility(IReferenceService) target_id = get_content_id(self.root.folder) version = self.root.document.get_editable() # At first there is no references self.assertEqual(list(service.get_references_from(version)), []) self.assertEqual(list(service.get_references_to(self.root.folder)), []) html = TEST_LINK_HTML % ('new', target_id) # We convert our HTML with a new reference to Kupu node = self.transformer.to_source(targetobj=html, context=self.context) link = node.query_one('link') self.assertEqual(link.name(), 'link') self.failUnless(link.hasattr('reference')) reference_name = link.getattr('reference') result = node.asBytes('utf-8') self.assertEqual( result, '<link target="_blank" reference="%s" title="">My link</link>' % (reference_name)) # We verify that the reference has been created. reference = service.get_reference(version, reference_name) self.assertEqual(reference.source, version) self.assertEqual(aq_chain(reference.source), aq_chain(version)) self.assertEqual(reference.target, self.root.folder) self.assertEqual(aq_chain(reference.target), aq_chain(self.root.folder)) self.assertEqual(reference.tags, ["document link", reference_name]) self.assertEqual(list(service.get_references_to(self.root.folder)), [reference]) self.assertEqual(list(service.get_references_from(version)), [reference]) # We can get back the HTML with a reference name roundtrip = self.transformer.to_target( sourceobj=result, context=self.context).asBytes('utf-8') self.assertEqual(roundtrip, TEST_LINK_HTML % (reference_name, target_id)) # Our new reference has been kept self.assertEqual(list(service.get_references_to(self.root.folder)), [reference]) self.assertEqual(list(service.get_references_from(version)), [reference])
def test_data(self): search = self.root.search field = criterion.PathCriterionField() data = queryMultiAdapter((field, search), ICriterionData) self.assertTrue(verifyObject(ICriterionData, data)) self.assertRaises(AssertionError, data.setValue, u"What ?") data.setValue(get_content_id(self.root.folder)) self.assertEqual(data.getValue(), self.root.folder) self.assertEqual(aq_chain(data.getValue()), aq_chain(self.root.folder)) data.setValue(None) self.assertEqual(data.getValue(), None)
def test_ghost_reference(self): """Test the reference created by the ghost. """ factory = self.root.target.manage_addProduct['Silva'] factory.manage_addGhostFolder('ghost', None, haunted=self.root.folder) ghost = self.root.target.ghost folder = self.root.folder reference = getUtility(IReferenceService).get_reference(ghost, name="haunted") self.assertTrue(verifyObject(IReferenceValue, reference)) self.assertEqual(aq_chain(reference.target), aq_chain(folder)) self.assertEqual(aq_chain(reference.source), aq_chain(ghost))
def test_relative_link(self): """Test creating and accessing a relative link to an another content in Silva. """ factory = self.root.manage_addProduct['Silva'] factory.manage_addMockupVersionedContent('test', 'Test Content') factory.manage_addFolder('folder', 'Folder') factory.manage_addLink( 'infrae', 'Infrae', relative=True, target=self.root.test) IPublicationWorkflow(self.root.infrae).publish() link = self.root.infrae.get_viewable() self.assertEqual(link.get_relative(), True) self.assertEqual(link.get_target(), self.root.test) self.assertEqual( aq_chain(link.get_target()), aq_chain(self.root.test)) reference = getUtility(IReferenceService).get_reference( link, name=u"link") self.assertNotEqual(reference, None) self.assertEqual(reference.target, self.root.test) with self.layer.get_browser() as browser: browser.options.follow_redirect = False self.assertEqual(browser.open('/root/infrae'), 302) self.assertTrue('Last-Modified' in browser.headers) self.assertTrue('Location' in browser.headers) self.assertEqual( browser.headers['Location'], 'http://localhost/root/test') # If we move the document around, the link will still work token = self.root.manage_cutObjects(['test']) self.root.folder.manage_pasteObjects(token) with self.layer.get_browser() as browser: browser.options.follow_redirect = False self.assertEqual(browser.open('/root/infrae'), 302) self.assertTrue('Last-Modified' in browser.headers) self.assertTrue('Location' in browser.headers) self.assertEqual( browser.headers['Location'], 'http://localhost/root/folder/test') # If you set the target to 0 the reference should be gone link.set_target(0) reference = getUtility(IReferenceService).get_reference( link, name=u"link") self.assertEqual(reference, None)
def parent_container(context): if IAppsContainer.providedBy(context): return context context = getattr(context, 'context', context) for parent in aq_chain(context): if IAppsContainer.providedBy(parent): return parent
def get_workspace_user_ids(context): """ Walks up the Acquisition chain and collects all userids assigned to a role with the View permission. """ if not is_within_workspace(context): return [] users = set([]) allowed_roles_to_view = roles_of_permission(context, 'View') portal = api.portal.get() def is_valid_userid(*args): user, roles, role_type, name = args return role_type == u'user' and set(roles) & set(allowed_roles_to_view) for content in aq_chain(context): if aq_base(content) == aq_base(portal): break userroles = portal.acl_users._getLocalRolesForDisplay(content) users = users.union( set( map(itemgetter(0), filter(lambda args: is_valid_userid(*args), userroles)))) if getattr(aq_base(context), '__ac_local_roles_block__', None): break return list(users)
def get_quota_warning_type_to_show_in(context): private_folders = filter(IPrivateFolder.providedBy, aq_chain(context)) if not private_folders: return None private_folder, = private_folders return ISizeQuota(private_folder).exceeded_limit()
def background(self): context = aq_inner(self.context) p_properties = getToolByName(context, 'portal_properties') if hasattr(p_properties, 'folder_logo_properties'): catalog = getToolByName(context, 'portal_catalog') folder_logo_properties = getattr(p_properties, 'folder_logo_properties') flp = IFolderLogoProperties(folder_logo_properties) color = flp.background_color image_id = flp.background_image_id folders = [folder for folder in aq_chain(context) if IFolderish.providedBy(folder)] images = [] for folder in folders: path = '/'.join(folder.getPhysicalPath()) brains = catalog( path=dict(query=path, depth=1), id = image_id, object_provides = IATImage.__identifier__, ) if len(brains) != 0: images.append(brains[0]) if len(images) != 0: image_path = images[0].getPath() style = "background: %s url(%s) no-repeat;" % (color, image_path) else: style = "background: %s no-repeat;" % (color) return style
def _touchTree(parent): """Helper function to update the dirty flag of the first parent :py:obj:`IDirtyTreeRoot`. """ for parent in aq_chain(parent): if IDirtyTreeRoot.providedBy(parent): parent.dirty = True
def getAqChainForUserCommands(self): """ Setup the aq chain as appropriate for the execution of a UserCommand """ chain = aq_chain(self.getClassObject().primaryAq()) chain.insert(0, self) return chain
def list_objects(self): """Depth first search of the current context to calculate object sizes. Returns a sorted list of ContentObjects. """ to_visit = [self.context] visited = {} while to_visit: context = to_visit.pop() children = context.getChildNodes() if children: to_visit.extend(children) try: current_size = context.get_size() except AttributeError: current_size = 0 visited[context.absolute_url_path()] = ContentObject( title=context.absolute_url_path(), url=context.absolute_url(), size=current_size) for parent in aq_chain(context): try: parent_path = parent.absolute_url_path() except AttributeError: # Doesn't have a path -> no proper object we want to count. # We assume it's this view and we don't need to traverse # the aq_chain further up. break if parent_path in visited and not parent == context: visited[parent_path].size += current_size return sorted(visited.values())
def __init__(self, context, request): super(WebHelpers, self).__init__(context, request) for obj in aq_chain(aq_inner(context)): if IClientSector.providedBy(obj): self.sector = obj break self.debug_mode = Globals.DevelopmentMode
def get_chains(self): repository = [] chain = [] for obj in aq_chain(self.context): if INavigationRoot.providedBy(obj): break if IHideFromBreadcrumbs.providedBy(obj): continue if ISQLObjectWrapper.providedBy(obj): data = obj.get_breadcrumb() else: data = { 'absolute_url': obj.absolute_url(), 'title': obj.Title(), 'css_class': get_css_class(obj, type_icon_only=True) } if self.is_part_of_repo(obj): repository.append(data) else: chain.append(data) chain.reverse() return repository, chain
def testSetupContext_OneStep(self): self.createSqlData() root = model.BaseObject() context = self.build_tree_aq_chain(root, self.mod1.id) self.assertEqual(len(aq_chain(context)), 2) self.failUnless(aq_base(context) is self.mod1) self.failUnless(aq_base(aq_parent(context)) is root)
def getTags(self): try: selected_tags = self.tags except AttributeError: selected_tags = [] available_tags = {} for i in aq_chain(self.context): if IBlog.providedBy(i): for t in sorted(i.available_public_tags): available_tags[self.normalizer.normalize(t)] = t break if not available_tags and self.context.portal_type == 'Topic': for i in self.context.queryCatalog(): if i.public_tags: for t in i.public_tags: available_tags[self.normalizer.normalize(t)] = t item_tags = [] for t in selected_tags: normal_tag = self.normalizer.normalize(t) if available_tags.get(normal_tag): item_tags.append(available_tags.get(normal_tag)) return item_tags
def update(self): super(LogoViewlet, self).update() context = aq_inner(self.context) p_properties = getToolByName(context, 'portal_properties') if hasattr(p_properties, 'folder_logo_properties'): portal = self.portal_state.portal() bprops = portal.restrictedTraverse('base_properties', None) title = None folder_logo_properties = getattr(p_properties, 'folder_logo_properties') logo_id = IFolderLogoProperties(folder_logo_properties).logo_id context = aq_inner(self.context) catalog = getToolByName(context, 'portal_catalog') folders = [folder for folder in aq_chain(context) if IFolderish.providedBy(folder)] logos = [] for folder in folders: path = '/'.join(folder.getPhysicalPath()) brains = catalog( path=dict(query=path, depth=1), id = logo_id, object_provides = IATImage.__identifier__, ) if len(brains) != 0: logos.append(brains[0]) if len(logos) != 0: logoName = logo_id title = logos[0].Title portal = aq_parent(logos[0].getObject()) elif bprops is not None: logoName = bprops.logoName else: logoName = 'logo.jpg' self.logo_tag = portal.restrictedTraverse(logoName).tag() self.portal_title = title or self.portal_state.portal_title()
def update(self): super(LogoViewlet, self).update() context = aq_inner(self.context) registry = getUtility(IRegistry) portal = self.portal_state.portal() bprops = portal.restrictedTraverse('base_properties', None) title = None logo_id = registry.get('collective.folderlogo.logo_id', u'logo') context = aq_inner(self.context) catalog = getToolByName(context, 'portal_catalog') folders = [folder for folder in aq_chain(context) if IFolderish.providedBy(folder)] logos = [] for folder in folders: path = '/'.join(folder.getPhysicalPath()) brains = catalog( path=dict(query=path, depth=1), id=logo_id, object_provides=IATImage.__identifier__) if len(brains) != 0: logos.append(brains[0]) if len(logos) != 0: logoName = logo_id title = logos[0].Title portal = aq_parent(logos[0].getObject()) elif bprops is not None: logoName = bprops.logoName else: logoName = 'logo.jpg' self.logo_tag = portal.restrictedTraverse(str(logoName)).tag() self.portal_title = title or self.portal_state.portal_title()
def country(self): from euphorie.client.country import IClientCountry for obj in aq_chain(aq_inner(self.context)): if IClientCountry.providedBy(obj): return obj.id else: return None
def __call__(self): portal_workflow = getToolByName(self.context, 'portal_workflow', None) if portal_workflow is None: return False obj = aq_parent(self.event.object) if self.element.check_types: obtained = False for obj in aq_chain(obj): if getattr(obj, 'portal_type', None) in self.element.check_types: obtained = True break if not obtained: return False try: portal_workflow.doActionFor(obj, self.element.transition) except ConflictError as e: raise e except Exception as e: self.error(obj, str(e)) return False return True
def isMemberIdAllowed(self, id): if len(id) < 1 or id == 'Anonymous User': return 0 if not self._ALLOWED_MEMBER_ID_PATTERN.match(id): return 0 pas = getToolByName(self, 'acl_users') if IPluggableAuthService.providedBy(pas): results = pas.searchPrincipals(id=id, exact_match=True) if results: return 0 else: for parent in aq_chain(self): if hasattr(aq_base(parent), "acl_users"): parent = parent.acl_users if IPluggableAuthService.providedBy(parent): if parent.searchPrincipals(id=id, exact_match=True): return 0 # When email addresses are used as logins, we need to check # if there are any users with the requested login. props = getToolByName(self, 'portal_properties').site_properties if props.use_email_as_login: results = pas.searchUsers(name=id, exact_match=True) if results: return 0 else: membership = getToolByName(self, 'portal_membership') if membership.getMemberById(id) is not None: return 0 groups = getToolByName(self, 'portal_groups') if groups.getGroupById(id) is not None: return 0 return 1
def community_mode(self): context = aq_inner(self.context) for obj in aq_chain(context): if ICommunity.providedBy(obj): return True return False
def find_workspace(context): while hasattr(context, "context"): context = context.context for context in aq_chain(context): workspace = IWorkspace(context, None) if workspace is not None: return workspace
def get_subscription(self, user_id, folder, root=False): """Get the id of the storage selected by the subscriber on the folder @param user_id: str - user id @param folder: object @param root: return only root subscription of a recursive subscription @return storage, recursive: object, bool - IDigestStorage utility """ folder_uid = self._get_uid(folder) catalog = self._get_catalog() for storage_id, storage in self.get_storages(): # get direct subscription if ('member', user_id) in catalog.search( {self._get_key(storage_id): folder_uid}): return storage, False # search recursive subscriptions rec_storage_id = self._get_key(storage_id, True) for step in aq_chain(folder): step_uid = self._get_uid(step) if step_uid and catalog.search({rec_storage_id: step_uid}): return storage, True if root: # check only folder itself break return None, None
def render(self): # set up a reference to the original template filename = pkg_resources.resource_filename( pkg_resources.Requirement.parse('plone.app.layout'), 'plone/app/layout/viewlets/contentviews.pt') self.template_file = ViewPageTemplateFile(filename) # if we're looking at a mailing list, then show that immediately if IMailingList.providedBy(self.context): # Remove the disable border setting if it's set # or we won't get the proper content views on archives or posts try: del self.request.other['disable_border'] except KeyError: pass # and always enable it self.request.other['enable_border'] = True return self.template_file() # otherwise, check if we have a mailing list in the parents for obj in aq_chain(aq_inner(self.context)): if IMailingList.providedBy(obj): # show the content views in the mailing list's context viewlet = getMultiAdapter( (obj, self.request, self.__parent__, self.manager), name='plone.contentviews') viewlet.update() return viewlet.render() # we didn't have a mailing list in our chain, so return the default return self.template_file()