Back to index

plone3  3.1.7
Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes
Archetypes.Referenceable.Referenceable Class Reference
Inheritance diagram for Archetypes.Referenceable.Referenceable:
Inheritance graph
[legend]
Collaboration diagram for Archetypes.Referenceable.Referenceable:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def reference_url
def hasRelationshipTo
def addReference
def deleteReference
def deleteReferences
def getRelationships
def getBRelationships
def getRefs
def getBRefs
def getReferenceImpl
def getBackReferenceImpl
def UID
def manage_afterAdd
 OFS Hooks.
def manage_afterClone
def manage_beforeDelete
def getReferenceMap
def getReferencePng

Static Public Attributes

int isReferenceable = 1
tuple security = ClassSecurityInfo()
 getReferences = getRefs
 getBackReferences = getBRefs

Private Member Functions

def _getURL
def _register
def _unregister
def _getReferenceAnnotations
def _delReferenceAnnotations
def _setUID
def _updateCatalog
def _catalogUID
 Catalog Helper methods.
def _uncatalogUID
def _catalogRefs
def _uncatalogRefs
def _getCopy
def _notifyOfCopyTo
def _referenceApply

Private Attributes

 _v_cp_refs
 _v_is_cp

Static Private Attributes

tuple __implements__ = (DEPRECATED,)

Detailed Description

A Mix-in for Referenceable objects 

Definition at line 35 of file Referenceable.py.


Member Function Documentation

def Archetypes.Referenceable.Referenceable._catalogRefs (   self,
  aq,
  uc = None,
  rc = None 
) [private]

Definition at line 313 of file Referenceable.py.

00313 
00314     def _catalogRefs(self, aq, uc=None, rc=None):
00315         annotations = self._getReferenceAnnotations()
00316         if annotations:
00317             if not uc:
00318                 uc = getToolByName(aq, config.UID_CATALOG)
00319             if not rc:
00320                 rc = getToolByName(aq, config.REFERENCE_CATALOG)
00321             for ref in annotations.objectValues():
00322                 url = getRelURL(uc, ref.getPhysicalPath())
00323                 uc.catalog_object(ref, url)
00324                 rc.catalog_object(ref, url)
00325                 ref._catalogRefs(uc, uc, rc)

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.Referenceable.Referenceable._catalogUID (   self,
  aq,
  uc = None 
) [private]

Catalog Helper methods.

Definition at line 296 of file Referenceable.py.

00296 
00297     def _catalogUID(self, aq, uc=None):
00298         if not uc:
00299             uc = getToolByName(aq, config.UID_CATALOG)
00300         url = self._getURL()
00301         uc.catalog_object(self, url)

Here is the call graph for this function:

Here is the caller graph for this function:

Removes annotation from self

Definition at line 143 of file Referenceable.py.

00143 
00144     def _delReferenceAnnotations(self):
00145         """Removes annotation from self
00146         """
00147         if getattr(aq_base(self), config.REFERENCE_ANNOTATION, None):
00148             delattr(self, config.REFERENCE_ANNOTATION)

Here is the caller graph for this function:

def Archetypes.Referenceable.Referenceable._getCopy (   self,
  container 
) [private]

Definition at line 345 of file Referenceable.py.

00345 
00346     def _getCopy(self, container):
00347         # We only set the '_v_is_cp' flag here if it was already set.
00348         #
00349         # _getCopy gets called after _notifyOfCopyTo, which should set
00350         # _v_cp_refs appropriatedly.
00351         #
00352         # _getCopy is also called from WebDAV MOVE (though not from
00353         # 'manage_pasteObjects')
00354         is_cp_flag = getattr(self, '_v_is_cp', None)
00355         cp_refs_flag = getattr(self, '_v_cp_refs', None)
00356         ob = CopySource._getCopy(self, container)
00357         if is_cp_flag:
00358             setattr(ob, '_v_is_cp', is_cp_flag)
00359         if cp_refs_flag:
00360             setattr(ob, '_v_cp_refs', cp_refs_flag)
00361         return ob

given an object extract the bag of references for which it
is the source

Definition at line 134 of file Referenceable.py.

00134 
00135     def _getReferenceAnnotations(self):
00136         """given an object extract the bag of references for which it
00137         is the source"""
00138         if not getattr(aq_base(self), config.REFERENCE_ANNOTATION, None):
00139             setattr(self, config.REFERENCE_ANNOTATION,
00140                     Folder(config.REFERENCE_ANNOTATION))
00141 
00142         return getattr(self, config.REFERENCE_ANNOTATION).__of__(self)

Here is the caller graph for this function:

the url used as the relative path based uid in the catalogs

Definition at line 87 of file Referenceable.py.

00087 
00088     def _getURL(self):
00089         """the url used as the relative path based uid in the catalogs"""
00090         return getRelURL(self, self.getPhysicalPath())

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.Referenceable.Referenceable._notifyOfCopyTo (   self,
  container,
  op = 0 
) [private]
keep reference info internally when op == 1 (move)
because in those cases we need to keep refs

Definition at line 362 of file Referenceable.py.

00362 
00363     def _notifyOfCopyTo(self, container, op=0):
00364         """keep reference info internally when op == 1 (move)
00365         because in those cases we need to keep refs"""
00366         # This isn't really safe for concurrent usage, but the
00367         # worse case is not that bad and could be fixed with a reindex
00368         # on the archetype tool
00369         if op==1:
00370             self._v_cp_refs = 1
00371             self._v_is_cp = 0
00372         if op==0:
00373             self._v_cp_refs = 0
00374             self._v_is_cp = 1

def Archetypes.Referenceable.Referenceable._referenceApply (   self,
  methodName,
  args,
  kwargs 
) [private]

Definition at line 376 of file Referenceable.py.

00376 
00377     def _referenceApply(self, methodName, *args, **kwargs):
00378         # We always apply commands to our reference children
00379         # and if we are folderish we need to get those too
00380         # where as references are concerned
00381         children = []
00382         if shasattr(self, 'objectValues'):
00383             # Only apply to objects that subclass
00384             # from Referenceable, and only apply the
00385             # method from Referenceable. Otherwise manage_* will get
00386             # called multiple times.
00387             nc = lambda obj: isinstance(obj, Referenceable)
00388             children.extend(filter(nc, self.objectValues()))
00389         children.extend(self._getReferenceAnnotations().objectValues())
00390         if children:
00391             for child in children:
00392                 if shasattr(Referenceable, methodName):
00393                     method = getattr(Referenceable, methodName)
00394                     method(*((child,) + args), **kwargs)

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.Referenceable.Referenceable._register (   self,
  reference_manager = None 
) [private]
register with the archetype tool for a unique id

Definition at line 119 of file Referenceable.py.

00119 
00120     def _register(self, reference_manager=None):
00121         """register with the archetype tool for a unique id"""
00122         if self.UID() is not None:
00123             return
00124 
00125         if reference_manager is None:
00126             reference_manager = getToolByName(self, config.REFERENCE_CATALOG)
00127         reference_manager.registerObject(self)
00128 

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.Referenceable.Referenceable._setUID (   self,
  uid 
) [private]

Definition at line 152 of file Referenceable.py.

00152 
00153     def _setUID(self, uid):
00154         old_uid = self.UID()
00155         if old_uid is None:
00156             # Nothing to be done.
00157             return
00158         # Update forward references
00159         fw_refs = self.getReferenceImpl()
00160         for ref in fw_refs:
00161             assert ref.sourceUID == old_uid
00162             ref.sourceUID = uid
00163             item = ref
00164             container = aq_parent(aq_inner(ref))
00165             # We call manage_afterAdd to inform the
00166             # reference catalog about changes.
00167             ref.manage_afterAdd(item, container)
00168         # Update back references
00169         back_refs = self.getBackReferenceImpl()
00170         for ref in back_refs:
00171             assert ref.targetUID == old_uid
00172             ref.targetUID = uid
00173             item = ref
00174             container = aq_parent(aq_inner(ref))
00175             # We call manage_afterAdd to inform the
00176             # reference catalog about changes.
00177             ref.manage_afterAdd(item, container)
00178         setattr(self, config.UUID_ATTR, uid)
00179         item = self
00180         container = aq_parent(aq_inner(item))
00181         # We call manage_afterAdd to inform the
00182         # reference catalog about changes.
00183         self.manage_afterAdd(item, container)

Here is the call graph for this function:

def Archetypes.Referenceable.Referenceable._uncatalogRefs (   self,
  aq,
  uc = None,
  rc = None 
) [private]

Definition at line 326 of file Referenceable.py.

00326 
00327     def _uncatalogRefs(self, aq, uc=None, rc=None):
00328         annotations = self._getReferenceAnnotations()
00329         if annotations:
00330             if not uc:
00331                 uc = getToolByName(self, config.UID_CATALOG)
00332             if not rc:
00333                 rc = getToolByName(self, config.REFERENCE_CATALOG)
00334             for ref in annotations.objectValues():
00335                 url = getRelURL(uc, ref.getPhysicalPath())
00336                 # XXX This is an ugly workaround. This method shouldn't be
00337                 # called twice for an object in the first place, so we don't
00338                 # have to check if it is still cataloged. 
00339                 uc_rid = uc.getrid(url)
00340                 if uc_rid is not None:
00341                     uc.uncatalog_object(url)
00342                 rc_rid = rc.getrid(url)
00343                 if rc_rid is not None:
00344                     rc.uncatalog_object(url)

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.Referenceable.Referenceable._uncatalogUID (   self,
  aq,
  uc = None 
) [private]

Definition at line 302 of file Referenceable.py.

00302 
00303     def _uncatalogUID(self, aq, uc=None):
00304         if not uc:
00305             uc = getToolByName(self, config.UID_CATALOG)
00306         url = self._getURL()
00307         # XXX This is an ugly workaround. This method shouldn't be called
00308         # twice for an object in the first place, so we don't have to check
00309         # if it is still cataloged. 
00310         rid = uc.getrid(url)
00311         if rid is not None:
00312             uc.uncatalog_object(url)

Here is the call graph for this function:

Here is the caller graph for this function:

unregister with the archetype tool, remove all references

Definition at line 129 of file Referenceable.py.

00129 
00130     def _unregister(self):
00131         """unregister with the archetype tool, remove all references"""
00132         reference_manager = getToolByName(self, config.REFERENCE_CATALOG)
00133         reference_manager.unregisterObject(self)

Here is the call graph for this function:

def Archetypes.Referenceable.Referenceable._updateCatalog (   self,
  container 
) [private]
Update catalog after copy, rename ...

Definition at line 184 of file Referenceable.py.

00184 
00185     def _updateCatalog(self, container):
00186         """Update catalog after copy, rename ...
00187         """
00188         # the UID index needs to be updated for any annotations we
00189         # carry
00190         try:
00191             uc = getToolByName(container, config.UID_CATALOG)
00192         except AttributeError:
00193             # TODO when trying to rename or copy a whole site than
00194             # container is the object "under" the portal so we can
00195             # NEVER ever find the catalog which is bad ...
00196             container = aq_parent(self)
00197             uc = getToolByName(container, config.UID_CATALOG)
00198 
00199         rc = getToolByName(uc, config.REFERENCE_CATALOG)
00200 
00201         self._catalogUID(container, uc=uc)
00202         self._catalogRefs(container, uc=uc, rc=rc)

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.Referenceable.Referenceable.addReference (   self,
  object,
  relationship = None,
  referenceClass = None,
  updateReferences = True,
  kwargs 
)

Definition at line 54 of file Referenceable.py.

00054 
00055                      updateReferences=True, **kwargs):
00056         tool = getToolByName(self, config.REFERENCE_CATALOG)
00057         return tool.addReference(self, object, relationship, referenceClass,
00058                                  updateReferences, **kwargs)

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.Referenceable.Referenceable.deleteReference (   self,
  target,
  relationship = None 
)

Definition at line 59 of file Referenceable.py.

00059 
00060     def deleteReference(self, target, relationship=None):
00061         tool = getToolByName(self, config.REFERENCE_CATALOG)
00062         return tool.deleteReference(self, target, relationship)

Here is the call graph for this function:

def Archetypes.Referenceable.Referenceable.deleteReferences (   self,
  relationship = None 
)

Definition at line 63 of file Referenceable.py.

00063 
00064     def deleteReferences(self, relationship=None):
00065         tool = getToolByName(self, config.REFERENCE_CATALOG)
00066         return tool.deleteReferences(self, relationship)

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.Referenceable.Referenceable.getBackReferenceImpl (   self,
  relationship = None,
  targetObject = None 
)
get all the back reference objects for this object

Definition at line 111 of file Referenceable.py.

00111 
00112     def getBackReferenceImpl(self, relationship=None, targetObject=None):
00113         """get all the back reference objects for this object"""
00114         tool = getToolByName(self, config.REFERENCE_CATALOG)
00115         refs = tool.getBackReferences(self, relationship, targetObject=targetObject)
00116         if refs:
00117             return refs
00118         return []

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.Referenceable.Referenceable.getBRefs (   self,
  relationship = None,
  targetObject = None 
)
get all the back referenced objects for this object

Definition at line 91 of file Referenceable.py.

00091 
00092     def getBRefs(self, relationship=None, targetObject=None):
00093         """get all the back referenced objects for this object"""
00094         tool = getToolByName(self, config.REFERENCE_CATALOG)
00095         refs = tool.getBackReferences(self, relationship, targetObject=targetObject)
00096         if refs:
00097             return [ref.getSourceObject() for ref in refs]
00098         return []

Here is the call graph for this function:

What kinds of relationships does this object have from others

Definition at line 72 of file Referenceable.py.

00072 
00073     def getBRelationships(self):
00074         """
00075         What kinds of relationships does this object have from others
00076         """
00077         tool = getToolByName(self, config.REFERENCE_CATALOG)
00078         return tool.getBackRelationships(self)

Here is the call graph for this function:

def Archetypes.Referenceable.Referenceable.getReferenceImpl (   self,
  relationship = None,
  targetObject = None 
)
get all the reference objects for this object    

Definition at line 103 of file Referenceable.py.

00103 
00104     def getReferenceImpl(self, relationship=None, targetObject=None):
00105         """get all the reference objects for this object    """
00106         tool = getToolByName(self, config.REFERENCE_CATALOG)
00107         refs = tool.getReferences(self, relationship, targetObject=targetObject)
00108         if refs:
00109             return refs
00110         return []

Here is the call graph for this function:

Here is the caller graph for this function:

The client side map for this objects references

Definition at line 397 of file Referenceable.py.

00397 
00398     def getReferenceMap(self):
00399         """The client side map for this objects references"""
00400         return get_cmapx(self)

Here is the call graph for this function:

def Archetypes.Referenceable.Referenceable.getReferencePng (   self,
  REQUEST = None 
)
A png of the references for this object

Definition at line 402 of file Referenceable.py.

00402 
00403     def getReferencePng(self, REQUEST=None):
00404         """A png of the references for this object"""
00405         if REQUEST:
00406             REQUEST.RESPONSE.setHeader('content-type', 'image/png')
00407         return get_png(self)
00408 
00409 InitializeClass(Referenceable)

Here is the call graph for this function:

def Archetypes.Referenceable.Referenceable.getRefs (   self,
  relationship = None,
  targetObject = None 
)
get all the referenced objects for this object

Definition at line 79 of file Referenceable.py.

00079 
00080     def getRefs(self, relationship=None, targetObject=None):
00081         """get all the referenced objects for this object"""
00082         tool = getToolByName(self, config.REFERENCE_CATALOG)
00083         refs = tool.getReferences(self, relationship, targetObject=targetObject)
00084         if refs:
00085             return [ref.getTargetObject() for ref in refs]
00086         return []

Here is the call graph for this function:

What kinds of relationships does this object have

Definition at line 67 of file Referenceable.py.

00067 
00068     def getRelationships(self):
00069         """What kinds of relationships does this object have"""
00070         tool = getToolByName(self, config.REFERENCE_CATALOG)
00071         return tool.getRelationships(self)

Here is the call graph for this function:

def Archetypes.Referenceable.Referenceable.hasRelationshipTo (   self,
  target,
  relationship = None 
)

Definition at line 49 of file Referenceable.py.

00049 
00050     def hasRelationshipTo(self, target, relationship=None):
00051         tool = getToolByName(self, config.REFERENCE_CATALOG)
00052         return tool.hasRelationshipTo(self, target, relationship)

Here is the call graph for this function:

def Archetypes.Referenceable.Referenceable.manage_afterAdd (   self,
  item,
  container 
)

OFS Hooks.

Get a UID
(Called when the object is created or moved.)

Definition at line 204 of file Referenceable.py.

00204 
00205     def manage_afterAdd(self, item, container):
00206         """
00207         Get a UID
00208         (Called when the object is created or moved.)
00209         """
00210         isCopy = getattr(item, '_v_is_cp', None)
00211         # Before copying we take a copy of the references that are to be copied 
00212         # on the new copy
00213         rfields=self.Schema().filterFields(type="reference", keepReferencesOnCopy=1) 
00214         rrefs={}
00215         if isCopy:
00216             # If the object is a copy of a existing object we
00217             # want to renew the UID, and drop all existing references
00218             # on the newly-created copy.
00219             for r in rfields:
00220                 rrefs[r.getName()]=r.get(self)
00221             setattr(self, config.UUID_ATTR, None)
00222             self._delReferenceAnnotations()
00223 
00224         ct = getToolByName(container, config.REFERENCE_CATALOG, None)
00225         self._register(reference_manager=ct)
00226         self._updateCatalog(container)
00227         self._referenceApply('manage_afterAdd', item, container)
00228         # copy the references 
00229         if isCopy:
00230             for r in rfields:
00231                 r.set(self,rrefs[r.getName()])
00232                  

Here is the call graph for this function:

Here is the caller graph for this function:

Get a new UID (effectivly dropping reference)
(Called when the object is cloned.)

Definition at line 233 of file Referenceable.py.

00233 
00234     def manage_afterClone(self, item):
00235         """
00236         Get a new UID (effectivly dropping reference)
00237         (Called when the object is cloned.)
00238         """
00239         uc = getToolByName(self, config.UID_CATALOG)
00240 
00241         isCopy = getattr(item, '_v_is_cp', None)
00242         if isCopy:
00243             # if isCopy is True, manage_afterAdd should have assigned a
00244             # UID already.  Don't mess with UID anymore.
00245             return
00246 
00247         # TODO Should we ever get here after the isCopy flag addition??
00248         # If the object has no UID or the UID already exists, then
00249         # we should get a new one
00250         if (not shasattr(self,config.UUID_ATTR) or
00251             len(uc(UID=self.UID()))):
00252             setattr(self, config.UUID_ATTR, None)
00253 
00254         self._register()
00255         self._updateCatalog(self)

Here is the call graph for this function:

def Archetypes.Referenceable.Referenceable.manage_beforeDelete (   self,
  item,
  container 
)
Remove self from the catalog.
(Called when the object is deleted or moved.)

Definition at line 256 of file Referenceable.py.

00256 
00257     def manage_beforeDelete(self, item, container):
00258         """
00259         Remove self from the catalog.
00260         (Called when the object is deleted or moved.)
00261         """
00262 
00263         # Change this to be "item", this is the root of this recursive
00264         # chain and it will be flagged in the correct mode
00265         storeRefs = getattr(item, '_v_cp_refs', None)
00266         if storeRefs is None:
00267             # The object is really going away, we want to remove
00268             # its references
00269             rc = getToolByName(self, config.REFERENCE_CATALOG)
00270             references = rc.getReferences(self)
00271             back_references = rc.getBackReferences(self)
00272             try:
00273                 #First check the 'delete cascade' case
00274                 if references:
00275                     for ref in references:
00276                         ref.beforeSourceDeleteInformTarget()
00277                 #Then check the 'holding/ref count' case
00278                 if back_references:
00279                     for ref in back_references:
00280                         ref.beforeTargetDeleteInformSource()
00281                 # If nothing prevented it, remove all the refs
00282                 self.deleteReferences()
00283             except ReferenceException, E:
00284                 raise BeforeDeleteException(E)
00285 
00286         self._referenceApply('manage_beforeDelete', item, container)
00287 
00288         # Track the UUID
00289         # The object has either gone away, moved or is being
00290         # renamed, we still need to remove all UID/child refs
00291         self._uncatalogUID(container)
00292         self._uncatalogRefs(container)
00293 
00294 

Here is the call graph for this function:

like absoluteURL, but return a link to the object with this UID

Definition at line 44 of file Referenceable.py.

00044 
00045     def reference_url(self):
00046         """like absoluteURL, but return a link to the object with this UID"""
00047         tool = getToolByName(self, config.REFERENCE_CATALOG)
00048         return tool.reference_url(self)

Here is the call graph for this function:

Definition at line 149 of file Referenceable.py.

00149 
00150     def UID(self):
00151         return getattr(self, config.UUID_ATTR, None)

Here is the caller graph for this function:


Member Data Documentation

tuple Archetypes.Referenceable.Referenceable.__implements__ = (DEPRECATED,) [static, private]

Definition at line 39 of file Referenceable.py.

Definition at line 369 of file Referenceable.py.

Definition at line 370 of file Referenceable.py.

Definition at line 101 of file Referenceable.py.

Definition at line 100 of file Referenceable.py.

Definition at line 37 of file Referenceable.py.

tuple Archetypes.Referenceable.Referenceable.security = ClassSecurityInfo() [static]

Definition at line 41 of file Referenceable.py.


The documentation for this class was generated from the following file: