Back to index

plone3  3.1.7
references.py
Go to the documentation of this file.
00001 from Products.Archetypes.ReferenceEngine import Reference
00002 from Products.Archetypes.exceptions import ReferenceException
00003 
00004 class HoldingReference(Reference):
00005     def beforeTargetDeleteInformSource(self):
00006         raise ReferenceException, ("Can't delete target, "
00007                                    "its held by %s" %
00008                                    self.getSourceObject().absolute_url())
00009 
00010 class CascadeReference(Reference):
00011     def beforeSourceDeleteInformTarget(self):
00012         tObj = self.getTargetObject()
00013         parent = tObj.aq_parent
00014         parent._delObject(tObj.id)
00015 
00016 
00017 FOLDERISH_REFERENCE="at_folder_reference"
00018 class FolderishReference(Reference):
00019     """Used by reference folder under the covers of the folderish API"""
00020 
00021     def __init__(self, id, sid, tid,
00022                  relationship=FOLDERISH_REFERENCE, **kwargs):
00023         Reference.__init__(self, id, sid, tid, relationship, **kwargs)
00024 
00025     def beforeSourceDeleteInformTarget(self):
00026         # The idea is that a reference folder would be
00027         # incrementing the reference count on its children
00028         # but not actually, placefully contain the object.
00029         # if the count is not 1 (meaning the last reference)
00030         # then we reject the delete
00031         if len(self.getTargetObject().getBRefs(FOLDERISH_REFERENCE)) != 1:
00032             raise ReferenceException, ("Can't delete target, "
00033                                        "its held by %s" %
00034                                        self.getSourceObject().absolute_url())