def afterRetrieveModifier(self, obj, repo_clone, preserve=()): # check if the modifier is called with a valid working copy if obj is None: return [], [], {} if ( ( HAVE_Z3_IFACE and IReferenceable.providedBy(obj) or not HAVE_Z3_IFACE and IReferenceable.isImplementedBy(obj) ) and hasattr(aq_base(obj), REFERENCE_ANNOTATION) and hasattr(aq_base(repo_clone), REFERENCE_ANNOTATION) ): # Remove AT references that no longer exists in the retrived version orig_refs_container = getattr(aq_base(obj), REFERENCE_ANNOTATION) repo_clone_refs_container = getattr(aq_base(repo_clone), REFERENCE_ANNOTATION) ref_objs = orig_refs_container.objectValues() repo_clone_ref_ids = repo_clone_refs_container.objectIds() reference_catalog = getToolByName(obj, "reference_catalog") if reference_catalog: for ref in ref_objs: if ref.getId() not in repo_clone_ref_ids: reference_catalog.deleteReference(ref.sourceUID, ref.targetUID, ref.relationship) return [], [], {}
def test_implements(self): if self.dummy is not None: self.assertFalse(IReferenceable.providedBy(self.dummy)) self.assertFalse(IExtensibleMetadata.providedBy(self.dummy)) self.assertFalse(self.dummy.isReferenceable) self.assertTrue(IBaseContent.providedBy(self.dummy)) self.assertTrue(IATTopicCriterion.providedBy(self.dummy)) self.assertTrue(verifyObject(IBaseContent, self.dummy)) self.assertTrue(verifyObject(IATTopicCriterion, self.dummy))
def test_implements(self): if self.dummy is not None: self.failIf(IReferenceable.providedBy(self.dummy)) self.failIf(IExtensibleMetadata.providedBy(self.dummy)) self.failIf(self.dummy.isReferenceable) self.failUnless(IBaseContent.providedBy(self.dummy)) self.failUnless(IATTopicCriterion.providedBy(self.dummy)) self.failUnless(verifyObject(IBaseContent, self.dummy)) self.failUnless(verifyObject(IATTopicCriterion, self.dummy))
def test_implements(self): if self.dummy is not None: self.assertFalse(IReferenceable.providedBy(self.dummy)) self.assertFalse(IExtensibleMetadata.providedBy(self.dummy)) self.assertFalse(self.dummy.isReferenceable) self.assertTrue(IBaseContent.providedBy(self.dummy)) self.assertTrue(IATTopicCriterion.providedBy(self.dummy)) self.assertTrue(verifyObject(IBaseContent, self.dummy)) self.assertTrue(verifyObject(IATTopicCriterion, self.dummy))
def afterRetrieveModifier(self, obj, repo_clone, preserve=()): # check if the modifier is called with a valid working copy if obj is None: return [], [], {} if (HAVE_Z3_IFACE and IReferenceable.providedBy(obj) or not HAVE_Z3_IFACE and IReferenceable.isImplementedBy(obj)) \ and hasattr(aq_base(obj), REFERENCE_ANNOTATION): #Preserve AT references orig_refs_container = getattr(aq_base(obj), REFERENCE_ANNOTATION) setattr(repo_clone, REFERENCE_ANNOTATION, orig_refs_container) return [], [], {}
def _fixupATReferences(self, obj): """Reindex AT reference data, and delete reference implementations when the target doesn't exist anymore. Deletion of references is done at the end of the recursiveRetrieve operation to avoid deleting refs to targets that will be retrieved later in the recursiveRetrive. It doesn't call refcatalog.deleteReference as that method uses brains to retrieve reference implementations. If the target doesn't exist, brains for references pointing to it do not exist either. This manually calls reference.delHook to let it finalize correctly but traps ReferenceException eventually emitted in the process and forces the deletion, because leaving the reference impl. there will leave refcatalog in an incosistent state. """ if ( HAVE_Z3_IFACE and IReferenceable.providedBy(obj) or not HAVE_Z3_IFACE and IReferenceable.isImplementedBy(obj) ) and hasattr(obj, REFERENCES_CONTAINER_NAME): # Delete refs if their target doesn't exists anymore ref_folder = getattr(obj, REFERENCES_CONTAINER_NAME) uid_catalog = getToolByName(self, "uid_catalog") ref_catalog = getToolByName(self, "reference_catalog") ref_objs = ref_folder.objectValues() for ref in ref_objs: if not uid_catalog(UID=ref.targetUID): try: # at's _deleteReference passes the catalog # itself, the source and target obj... i'm # going to emulate it as much as i can ref.delHook(ref_catalog, obj, None) except ReferenceException: pass ref_folder.manage_delObjects(ref.getId()) # then reindex references container = aq_parent(aq_inner(obj)) obj._updateCatalog(container)
def _fixupATReferences(self, obj): """Reindex AT reference data, and delete reference implementations when the target doesn't exist anymore. Deletion of references is done at the end of the recursiveRetrieve operation to avoid deleting refs to targets that will be retrieved later in the recursiveRetrive. It doesn't call refcatalog.deleteReference as that method uses brains to retrieve reference implementations. If the target doesn't exist, brains for references pointing to it do not exist either. This manually calls reference.delHook to let it finalize correctly but traps ReferenceException eventually emitted in the process and forces the deletion, because leaving the reference impl. there will leave refcatalog in an incosistent state. """ if (HAVE_Z3_IFACE and IReferenceable.providedBy(obj) or not HAVE_Z3_IFACE and IReferenceable.isImplementedBy(obj)) and hasattr( obj, REFERENCES_CONTAINER_NAME): # Delete refs if their target doesn't exists anymore ref_folder = getattr(obj, REFERENCES_CONTAINER_NAME) uid_catalog = getToolByName(self, "uid_catalog") ref_catalog = getToolByName(self, "reference_catalog") ref_objs = ref_folder.objectValues() for ref in ref_objs: if not uid_catalog(UID=ref.targetUID): try: # at's _deleteReference passes the catalog # itself, the source and target obj... i'm # going to emulate it as much as i can ref.delHook(ref_catalog, obj, None) except ReferenceException: pass ref_folder.manage_delObjects(ref.getId()) # then reindex references container = aq_parent(aq_inner(obj)) obj._updateCatalog(container)
def is_referenceable(obj): """Find out if this object (AT or DX) is referenceable. Return True if a obj can be referenced using the reference_catalog used by Archetypes-Relations and Linkintegrity. Relations using the relation_catalog (zc.relation.interfaces.ICatalog) are not covered by this test! """ is_referenceable = False if IReferenceable.providedBy(obj) or \ safe_hasattr(aq_base(obj), 'isReferenceable'): is_referenceable = True else: try: # This most likely the case when plone.app.referenceablebehavior # is enabled. obj = IReferenceable(obj) is_referenceable = True except TypeError: is_referenceable = False return is_referenceable
def is_referenceable(obj): """Find out if this object (AT or DX) is referenceable. Return True if a obj can be referenced using the reference_catalog used by Archetypes-Relations and Linkintegrity. Relations using the relation_catalog (zc.relation.interfaces.ICatalog) are not covered by this test! """ is_referenceable = False if IReferenceable.providedBy(obj) or \ safe_hasattr(aq_base(obj), 'isReferenceable'): is_referenceable = True else: try: # This most likely the case when plone.app.referenceablebehavior # is enabled. obj = IReferenceable(obj) is_referenceable = True except TypeError: is_referenceable = False return is_referenceable
def _catalogReferencesFor(self, obj, path): if IReferenceable.providedBy(obj): obj._catalogRefs(self)
def isReferenceable(self, object): return (IReferenceable.providedBy(object) or shasattr(object, 'isReferenceable'))
def test_doesImplementAT(self): self.assertTrue(IBaseContent.providedBy(self._ATCT)) self.assertTrue(IReferenceable.providedBy(self._ATCT)) self.assertTrue(verifyObject(IBaseContent, self._ATCT)) self.assertTrue(verifyObject(IReferenceable, self._ATCT))
def test_doesImplementAT(self): self.failUnless(IBaseContent.providedBy(self._ATCT)) self.failUnless(IReferenceable.providedBy(self._ATCT)) self.failUnless(verifyObject(IBaseContent, self._ATCT)) self.failUnless(verifyObject(IReferenceable, self._ATCT))
def test_doesImplementAT(self): self.assertTrue(IBaseContent.providedBy(self._ATCT)) self.assertTrue(IReferenceable.providedBy(self._ATCT)) self.assertTrue(verifyObject(IBaseContent, self._ATCT)) self.assertTrue(verifyObject(IReferenceable, self._ATCT))
def test_doesImplementAT(self): self.failUnless(IBaseContent.providedBy(self._ATCT)) self.failUnless(IReferenceable.providedBy(self._ATCT)) self.failUnless(verifyObject(IBaseContent, self._ATCT)) self.failUnless(verifyObject(IReferenceable, self._ATCT))