Back to index

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

List of all members.

Public Member Functions

def __init__
def addReference
 Public API.
def deleteReference
def deleteReferences
def getReferences
def getBackReferences
def hasRelationshipTo
def getRelationships
def getBackRelationships
def isReferenceable
def reference_url
def lookupObject
def registerObject
 UID register/unregister.
def unregisterObject
def __nonzero__
def manage_catalogFoundItems
def manage_rebuildCatalog

Static Public Attributes

 id = REFERENCE_CATALOG
tuple security = ClassSecurityInfo()
tuple manage_catalogFind = DTMLFile('catalogFind', _catalog_dtml)
 manage_options = ZCatalog.manage_options

Private Member Functions

def _objectByUUID
 Private/Internal.
def _queryFor
def _uidFor
def _getUUIDFor
def _deleteReference
def _resolveBrains
def _makeName
def _catalogReferencesFor
def _catalogReferences

Private Attributes

 _catalog

Detailed Description

Reference catalog

Definition at line 293 of file ReferenceEngine.py.


Constructor & Destructor Documentation

def Archetypes.ReferenceEngine.ReferenceCatalog.__init__ (   self,
  id,
  title = '',
  vocab_id = None,
  container = None 
)
We hook up the brains now

Definition at line 310 of file ReferenceEngine.py.

00310 
00311     def __init__(self, id, title='', vocab_id=None, container=None):
00312         """We hook up the brains now"""
00313         ZCatalog.__init__(self, id, title, vocab_id, container)
00314         self._catalog = ReferenceBaseCatalog()

Here is the caller graph for this function:


Member Function Documentation

Definition at line 553 of file ReferenceEngine.py.

00553 
00554     def __nonzero__(self):
00555         return 1

def Archetypes.ReferenceEngine.ReferenceCatalog._catalogReferences (   self,
  root = None,
  kw 
) [private]
catalogs all references, where the optional parameter 'root'
   can be used to specify the tree that has to be searched for references 

Definition at line 560 of file ReferenceEngine.py.

00560 
00561     def _catalogReferences(self,root=None,**kw):
00562         ''' catalogs all references, where the optional parameter 'root'
00563            can be used to specify the tree that has to be searched for references '''
00564 
00565         if not root:
00566             root=getToolByName(self,'portal_url').getPortalObject()
00567 
00568         path = '/'.join(root.getPhysicalPath())
00569 
00570         results = self.ZopeFindAndApply(root,
00571                                         search_sub=1,
00572                                         apply_func=self._catalogReferencesFor,
00573                                         apply_path=path,**kw)
00574 
00575 

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.ReferenceEngine.ReferenceCatalog._catalogReferencesFor (   self,
  obj,
  path 
) [private]

Definition at line 556 of file ReferenceEngine.py.

00556 
00557     def _catalogReferencesFor(self,obj,path):
00558         if IReferenceable.isImplementedBy(obj):
00559             obj._catalogRefs(self)

Here is the caller graph for this function:

def Archetypes.ReferenceEngine.ReferenceCatalog._deleteReference (   self,
  referenceObject 
) [private]

Definition at line 527 of file ReferenceEngine.py.

00527 
00528     def _deleteReference(self, referenceObject):
00529         try:
00530             sobj = referenceObject.getSourceObject()
00531             referenceObject.delHook(self, sobj,
00532                                     referenceObject.getTargetObject())
00533         except ReferenceException:
00534             pass
00535         else:
00536             annotation = sobj._getReferenceAnnotations()
00537             try:
00538                 annotation._delObject(referenceObject.UID())
00539             except (AttributeError, KeyError):
00540                 pass

Here is the caller graph for this function:

def Archetypes.ReferenceEngine.ReferenceCatalog._getUUIDFor (   self,
  object 
) [private]
generate and attach a new uid to the object returning it

Definition at line 520 of file ReferenceEngine.py.

00520 
00521     def _getUUIDFor(self, object):
00522         """generate and attach a new uid to the object returning it"""
00523         uuid = make_uuid(object.getId())
00524         setattr(object, UUID_ATTR, uuid)
00525 
00526         return uuid

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.ReferenceEngine.ReferenceCatalog._makeName (   self,
  args 
) [private]
get a uuid

Definition at line 548 of file ReferenceEngine.py.

00548 
00549     def _makeName(self, *args):
00550         """get a uuid"""
00551         name = make_uuid(*args)
00552         return name

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.ReferenceEngine.ReferenceCatalog._objectByUUID (   self,
  uuid 
) [private]

Private/Internal.

Definition at line 467 of file ReferenceEngine.py.

00467 
00468     def _objectByUUID(self, uuid):
00469         tool = getToolByName(self, UID_CATALOG)
00470         brains = tool(UID=uuid)
00471         for brain in brains:
00472             obj = brain.getObject()
00473             if obj is not None:
00474                 return obj
00475         else:
00476             return None

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.ReferenceEngine.ReferenceCatalog._queryFor (   self,
  sid = None,
  tid = None,
  relationship = None,
  targetId = None,
  merge = 1 
) [private]
query reference catalog for object matching the info we are
given, returns brains

Note: targetId is the actual id of the target object, not its UID

Definition at line 478 of file ReferenceEngine.py.

00478 
00479                   targetId=None, merge=1):
00480         """query reference catalog for object matching the info we are
00481         given, returns brains
00482 
00483         Note: targetId is the actual id of the target object, not its UID
00484         """
00485 
00486         query = {}
00487         if sid: query['sourceUID'] = sid
00488         if tid: query['targetUID'] = tid
00489         if relationship: query['relationship'] = relationship
00490         if targetId: query['targetId'] = targetId
00491         brains = self.searchResults(query, merge=merge)
00492 
00493         return brains
00494 

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.ReferenceEngine.ReferenceCatalog._resolveBrains (   self,
  brains 
) [private]

Definition at line 541 of file ReferenceEngine.py.

00541 
00542     def _resolveBrains(self, brains):
00543         objects = []
00544         if brains:
00545             objects = [b.getObject() for b in brains]
00546             objects = [b for b in objects if b]
00547         return objects

Here is the caller graph for this function:

def Archetypes.ReferenceEngine.ReferenceCatalog._uidFor (   self,
  obj 
) [private]

Definition at line 495 of file ReferenceEngine.py.

00495 
00496     def _uidFor(self, obj):
00497         # We should really check for the interface but I have an idea
00498         # about simple annotated objects I want to play out
00499         if type(obj) not in STRING_TYPES:
00500             uobject = aq_base(obj)
00501             if not self.isReferenceable(uobject):
00502                 raise ReferenceException, "%r not referenceable" % uobject
00503 
00504             # shasattr() doesn't work here
00505             if not getattr(aq_base(uobject), UUID_ATTR, None):
00506                 uuid = self._getUUIDFor(uobject)
00507             else:
00508                 uuid = getattr(uobject, UUID_ATTR)
00509         else:
00510             uuid = obj
00511             obj = None
00512             #and we look up the object
00513             uid_catalog = getToolByName(self, UID_CATALOG)
00514             brains = uid_catalog(UID=uuid)
00515             for brain in brains:
00516                 res = brain.getObject()
00517                 if res is not None:
00518                     obj = res
00519         return uuid, obj

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.ReferenceEngine.ReferenceCatalog.addReference (   self,
  source,
  target,
  relationship = None,
  referenceClass = None,
  updateReferences = True,
  kwargs 
)

Public API.

Definition at line 318 of file ReferenceEngine.py.

00318 
00319                      referenceClass=None, updateReferences=True, **kwargs):
00320         sID, sobj = self._uidFor(source)
00321         if not sID or sobj is None:
00322             raise ReferenceException('Invalid source UID')
00323 
00324         tID, tobj = self._uidFor(target)
00325         if not tID or tobj is None:
00326             raise ReferenceException('Invalid target UID')
00327 
00328         if updateReferences:
00329             objects = self._resolveBrains(
00330                 self._queryFor(sID, tID, relationship))
00331             if objects:
00332                 #we want to update the existing reference
00333                 existing = objects[0]
00334                 if existing:
00335                     # We can't del off self, we now need to remove it
00336                     # from the source objects annotation, which we have
00337                     annotation = sobj._getReferenceAnnotations()
00338                     annotation._delObject(existing.id)
00339 
00340 
00341         rID = self._makeName(sID, tID)
00342         if not referenceClass:
00343             referenceClass = Reference
00344 
00345         annotation = sobj._getReferenceAnnotations()
00346 
00347         referenceObject = referenceClass(rID, sID, tID, relationship,
00348                                          **kwargs)
00349         # Must be wrapped into annotation context, or else
00350         # it will get indexed *twice*, one time with the wrong path.
00351         referenceObject = referenceObject.__of__(annotation)
00352         try:
00353             referenceObject.addHook(self, sobj, tobj)
00354         except ReferenceException:
00355             pass
00356         else:
00357             # This should call manage_afterAdd
00358             annotation._setObject(rID, referenceObject)
00359             return referenceObject

Here is the call graph for this function:

def Archetypes.ReferenceEngine.ReferenceCatalog.deleteReference (   self,
  source,
  target,
  relationship = None 
)

Definition at line 360 of file ReferenceEngine.py.

00360 
00361     def deleteReference(self, source, target, relationship=None):
00362         sID, sobj = self._uidFor(source)
00363         tID, tobj = self._uidFor(target)
00364 
00365         objects = self._resolveBrains(self._queryFor(sID, tID, relationship))
00366         if objects:
00367             self._deleteReference(objects[0])

Here is the call graph for this function:

def Archetypes.ReferenceEngine.ReferenceCatalog.deleteReferences (   self,
  object,
  relationship = None 
)
delete all the references held by an object

Definition at line 368 of file ReferenceEngine.py.

00368 
00369     def deleteReferences(self, object, relationship=None):
00370         """delete all the references held by an object"""
00371         for b in self.getReferences(object, relationship):
00372             self._deleteReference(b)
00373 
00374         for b in self.getBackReferences(object, relationship):
00375             self._deleteReference(b)

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.ReferenceEngine.ReferenceCatalog.getBackReferences (   self,
  object,
  relationship = None,
  targetObject = None 
)
return a collection of reference objects

Definition at line 387 of file ReferenceEngine.py.

00387 
00388     def getBackReferences(self, object, relationship=None, targetObject=None):
00389         """return a collection of reference objects"""
00390         # Back refs would be anything that target this object
00391         sID, sobj = self._uidFor(object)
00392         if targetObject:
00393             tID, tobj = self._uidFor(targetObject)
00394         else:
00395             tID, tobj = None,None
00396 
00397         brains = self._queryFor(tid=sID, relationship=relationship, sid=tID)
00398         return self._resolveBrains(brains)

Here is the call graph for this function:

Here is the caller graph for this function:

Get all relationship types this object has FROM other objects

Definition at line 422 of file ReferenceEngine.py.

00422 
00423     def getBackRelationships(self, object):
00424         """
00425         Get all relationship types this object has FROM other objects
00426         """
00427         sID, sobj = self._uidFor(object)
00428         brains = self._queryFor(tid=sID)
00429         res = {}
00430         for b in brains:
00431             res[b.relationship]=1
00432 
00433         return res.keys()
00434 

Here is the call graph for this function:

def Archetypes.ReferenceEngine.ReferenceCatalog.getReferences (   self,
  object,
  relationship = None,
  targetObject = None 
)
return a collection of reference objects

Definition at line 376 of file ReferenceEngine.py.

00376 
00377     def getReferences(self, object, relationship=None, targetObject=None):
00378         """return a collection of reference objects"""
00379         sID, sobj = self._uidFor(object)
00380         if targetObject:
00381             tID, tobj = self._uidFor(targetObject)
00382         else:
00383             tID, tobj = None,None
00384             
00385         brains = self._queryFor(sid=sID, relationship=relationship, tid=tID)
00386         return self._resolveBrains(brains)

Here is the call graph for this function:

Here is the caller graph for this function:

Get all relationship types this object has TO other objects

Definition at line 410 of file ReferenceEngine.py.

00410 
00411     def getRelationships(self, object):
00412         """
00413         Get all relationship types this object has TO other objects
00414         """
00415         sID, sobj = self._uidFor(object)
00416         brains = self._queryFor(sid=sID)
00417         res = {}
00418         for brain in brains:
00419             res[brain.relationship] = 1
00420 
00421         return res.keys()

Here is the call graph for this function:

def Archetypes.ReferenceEngine.ReferenceCatalog.hasRelationshipTo (   self,
  source,
  target,
  relationship 
)

Definition at line 399 of file ReferenceEngine.py.

00399 
00400     def hasRelationshipTo(self, source, target, relationship):
00401         sID, sobj = self._uidFor(source)
00402         tID, tobj = self._uidFor(target)
00403 
00404         brains = self._queryFor(sID, tID, relationship)
00405         for brain in brains:
00406             obj = brain.getObject()
00407             if obj is not None:
00408                 return True
00409         return False

Here is the call graph for this function:

Definition at line 435 of file ReferenceEngine.py.

00435 
00436     def isReferenceable(self, object):
00437         return (IReferenceable.isImplementedBy(object) or
00438                 shasattr(object, 'isReferenceable'))

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.ReferenceEngine.ReferenceCatalog.lookupObject (   self,
  uuid,
  REQUEST = None 
)
Lookup an object by its uuid

Definition at line 444 of file ReferenceEngine.py.

00444 
00445     def lookupObject(self, uuid, REQUEST=None):
00446         """Lookup an object by its uuid"""
00447         obj = self._objectByUUID(uuid)
00448         if REQUEST:
00449             return REQUEST.RESPONSE.redirect(obj.absolute_url())
00450         else:
00451             return obj

Here is the call graph for this function:

def Archetypes.ReferenceEngine.ReferenceCatalog.manage_catalogFoundItems (   self,
  REQUEST,
  RESPONSE,
  URL2,
  URL1,
  obj_metatypes = None,
  obj_ids = None,
  obj_searchterm = None,
  obj_expr = None,
  obj_mtime = None,
  obj_mspec = None,
  obj_roles = None,
  obj_permission = None 
)
Find object according to search criteria and Catalog them

Definition at line 581 of file ReferenceEngine.py.

00581 
00582                                  obj_permission=None):
00583 
00584         """ Find object according to search criteria and Catalog them
00585         """
00586 
00587 
00588         elapse = time.time()
00589         c_elapse = time.clock()
00590 
00591         words = 0
00592         obj = REQUEST.PARENTS[1]
00593 
00594         self._catalogReferences(obj,obj_metatypes=obj_metatypes,
00595                                  obj_ids=obj_ids, obj_searchterm=obj_searchterm,
00596                                  obj_expr=obj_expr, obj_mtime=obj_mtime,
00597                                  obj_mspec=obj_mspec, obj_roles=obj_roles,
00598                                  obj_permission=obj_permission)
00599 
00600         elapse = time.time() - elapse
00601         c_elapse = time.clock() - c_elapse
00602 
00603         RESPONSE.redirect(
00604             URL1 +
00605             '/manage_catalogView?manage_tabs_message=' +
00606             urllib.quote('Catalog Updated\n'
00607                          'Total time: %s\n'
00608                          'Total CPU time: %s'
00609                          % (`elapse`, `c_elapse`))
00610             )

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.ReferenceEngine.ReferenceCatalog.manage_rebuildCatalog (   self,
  REQUEST = None,
  RESPONSE = None 
)

Definition at line 612 of file ReferenceEngine.py.

00612 
00613     def manage_rebuildCatalog(self, REQUEST=None, RESPONSE=None):
00614         """
00615         """
00616         elapse = time.time()
00617         c_elapse = time.clock()
00618 
00619         atool = getToolByName(self, TOOL_NAME)
00620         obj = aq_parent(self)
00621         if not REQUEST:
00622             REQUEST = self.REQUEST
00623 
00624         # build a list of archetype meta types
00625         mt = tuple([typ['meta_type'] for typ in atool.listRegisteredTypes()])
00626 
00627         # clear the catalog
00628         self.manage_catalogClear()
00629 
00630         # find and catalog objects
00631         self._catalogReferences(obj,
00632                                 obj_metatypes=mt,
00633                                 REQUEST=REQUEST)
00634 
00635         elapse = time.time() - elapse
00636         c_elapse = time.clock() - c_elapse
00637 
00638         if RESPONSE:
00639             RESPONSE.redirect(
00640             REQUEST.URL1 +
00641             '/manage_catalogView?manage_tabs_message=' +
00642             urllib.quote('Catalog Rebuilded\n'
00643                          'Total time: %s\n'
00644                          'Total CPU time: %s'
00645                          % (`elapse`, `c_elapse`))
00646             )
00647 
00648 InitializeClass(ReferenceCatalog)
00649 

Here is the call graph for this function:

return a url to an object that will resolve by reference

Definition at line 439 of file ReferenceEngine.py.

00439 
00440     def reference_url(self, object):
00441         """return a url to an object that will resolve by reference"""
00442         sID, sobj = self._uidFor(object)
00443         return "%s/lookupObject?uuid=%s" % (self.absolute_url(), sID)

Here is the call graph for this function:

UID register/unregister.

Definition at line 455 of file ReferenceEngine.py.

00455 
00456     def registerObject(self, object):
00457         self._uidFor(object)

Here is the call graph for this function:

Definition at line 459 of file ReferenceEngine.py.

00459 
00460     def unregisterObject(self, object):
00461         self.deleteReferences(object)
00462         uc = getToolByName(self, UID_CATALOG)
00463         uc.uncatalog_object(object._getURL())
00464 

Here is the call graph for this function:


Member Data Documentation

Definition at line 313 of file ReferenceEngine.py.

Archetypes.ReferenceEngine.ReferenceCatalog.id = REFERENCE_CATALOG [static]

Definition at line 297 of file ReferenceEngine.py.

Definition at line 301 of file ReferenceEngine.py.

Definition at line 302 of file ReferenceEngine.py.

tuple Archetypes.ReferenceEngine.ReferenceCatalog.security = ClassSecurityInfo() [static]

Definition at line 298 of file ReferenceEngine.py.


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