Back to index

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

List of all members.

Public Member Functions

def register
def unregister
def queryUid
def getUid
def setUid
def queryBrain
def getBrain
def getObject
def queryObject
def unrestrictedQueryBrain
def unrestrictedGetBrain
def unrestrictedGetObject
def unrestrictedQueryObject

Static Public Attributes

string id = 'portal_uidhandler'
tuple manage_options
string alternative_id = "portal_standard_uidhandler"
string meta_type = 'Unique Id Handler Tool'
 UID_ATTRIBUTE_NAME = UID_ATTRIBUTE_NAME
 UniqueIdError = UniqueIdError
tuple security = ClassSecurityInfo()
tuple manage_queryObject = PageTemplateFile('queryUID.pt', _wwwdir)

Private Member Functions

def _reindexObject
def _setUid
def _queryBrain
def _getBrain

Static Private Attributes

 __doc__ = __doc__
tuple __implements__

Detailed Description

Definition at line 49 of file UniqueIdHandlerTool.py.


Member Function Documentation

def CMFUid.UniqueIdHandlerTool.UniqueIdHandlerTool._getBrain (   self,
  uid,
  queryBrainMethod 
) [private]

Definition at line 207 of file UniqueIdHandlerTool.py.

00207 
00208     def _getBrain(self, uid, queryBrainMethod):
00209         brain = queryBrainMethod(uid, default=None)
00210         if brain is None:
00211             raise UniqueIdError, "No object found with '%s' as uid." % uid
00212         return brain

Here is the caller graph for this function:

def CMFUid.UniqueIdHandlerTool.UniqueIdHandlerTool._queryBrain (   self,
  uid,
  searchMethodName,
  default = None 
) [private]
This helper method does the "hard work" of querying the catalog
   and interpreting the results.

Definition at line 171 of file UniqueIdHandlerTool.py.

00171 
00172     def _queryBrain(self, uid, searchMethodName, default=None):
00173         """This helper method does the "hard work" of querying the catalog
00174            and interpreting the results.
00175         """
00176         # XXX: this method violates the rules for tools/utilities:
00177         # it depends on a non-utility tool
00178         if uid is None:
00179             return default
00180 
00181         # convert the uid to the right format
00182         generator = getUtility(IUniqueIdGenerator)
00183         uid = generator.convert(uid)
00184 
00185         catalog = getToolByName(self, 'portal_catalog')
00186         searchMethod = getattr(catalog, searchMethodName)
00187         result = searchMethod({self.UID_ATTRIBUTE_NAME: uid})
00188         len_result = len(result)
00189 
00190         # return None if no object found with this uid
00191         if len_result == 0:
00192             return default
00193 
00194         # print a message to the log  if more than one object has
00195         # the same uid (uups!)
00196         if len_result > 1:
00197             logging.getLogger('CMFUid').error(
00198                 "ASSERT: %d objects have %r as uid!!!", len_result, uid)
00199 
00200         return result[0]

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 78 of file UniqueIdHandlerTool.py.

00078 
00079     def _reindexObject(self, obj):
00080         # XXX: this method violates the rules for tools/utilities:
00081         # it depends on a non-utility tool
00082         # add uid index and colums to catalog if not yet done
00083         UID_ATTRIBUTE_NAME = self.UID_ATTRIBUTE_NAME
00084         catalog = getToolByName(obj, 'portal_catalog')
00085         if UID_ATTRIBUTE_NAME not in catalog.indexes():
00086             catalog.addIndex(UID_ATTRIBUTE_NAME, 'FieldIndex')
00087             catalog.addColumn(UID_ATTRIBUTE_NAME)
00088 
00089         # reindex
00090         catalog.reindexObject(obj, idxs=[UID_ATTRIBUTE_NAME])

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFUid.UniqueIdHandlerTool.UniqueIdHandlerTool._setUid (   self,
  obj,
  uid 
) [private]
Attaches a unique id to the object and does reindexing.

Definition at line 91 of file UniqueIdHandlerTool.py.

00091 
00092     def _setUid(self, obj, uid):
00093         """Attaches a unique id to the object and does reindexing.
00094         """
00095         # attach a unique id annotation to the object
00096         anno_tool = getUtility(IUniqueIdAnnotationManagement)
00097         annotation = anno_tool(obj, self.UID_ATTRIBUTE_NAME)
00098         annotation.setUid(uid)
00099 
00100         # reindex the object
00101         self._reindexObject(obj)

Here is the call graph for this function:

Here is the caller graph for this function:

See IUniqueIdBrainQuery.

Definition at line 214 of file UniqueIdHandlerTool.py.

00214 
00215     def getBrain(self, uid):
00216         """See IUniqueIdBrainQuery.
00217         """
00218         return self._getBrain(uid, self.queryBrain)

Here is the call graph for this function:

Here is the caller graph for this function:

See IUniqueIdQuery.

Definition at line 220 of file UniqueIdHandlerTool.py.

00220 
00221     def getObject(self, uid):
00222         """See IUniqueIdQuery.
00223         """
00224         return self.getBrain(uid).getObject()

Here is the call graph for this function:

Here is the caller graph for this function:

See IUniqueIdQuery.

Definition at line 143 of file UniqueIdHandlerTool.py.

00143 
00144     def getUid(self, obj):
00145         """See IUniqueIdQuery.
00146         """
00147         uid = self.queryUid(obj, None)
00148         if uid is None:
00149             raise UniqueIdError, "No unique id available on '%s'" % obj
00150         return uid

Here is the call graph for this function:

def CMFUid.UniqueIdHandlerTool.UniqueIdHandlerTool.queryBrain (   self,
  uid,
  default = None 
)
See IUniqueIdBrainQuery.

Definition at line 202 of file UniqueIdHandlerTool.py.

00202 
00203     def queryBrain(self, uid, default=None):
00204         """See IUniqueIdBrainQuery.
00205         """
00206         return self._queryBrain(uid, 'searchResults', default)

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFUid.UniqueIdHandlerTool.UniqueIdHandlerTool.queryObject (   self,
  uid,
  default = None 
)
See IUniqueIdQuery.

Definition at line 226 of file UniqueIdHandlerTool.py.

00226 
00227     def queryObject(self, uid, default=None):
00228         """See IUniqueIdQuery.
00229         """
00230         try:
00231             return self.getObject(uid)
00232         except UniqueIdError:
00233             return default

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFUid.UniqueIdHandlerTool.UniqueIdHandlerTool.queryUid (   self,
  obj,
  default = None 
)
See IUniqueIdQuery.

Definition at line 129 of file UniqueIdHandlerTool.py.

00129 
00130     def queryUid(self, obj, default=None):
00131         """See IUniqueIdQuery.
00132         """
00133         uid = getattr(aq_base(obj), self.UID_ATTRIBUTE_NAME, None)
00134         # If 'obj' is a content object the 'uid' attribute is usually a
00135         # callable object. If 'obj' is a catalog brain the uid attribute
00136         # is non callable and possibly equals the 'Missing.MV' value.
00137         if uid is Missing.MV or uid is None:
00138             return default
00139         if callable(uid):
00140             return uid()
00141         return uid

Here is the caller graph for this function:

See IUniqueIdSet.

Definition at line 103 of file UniqueIdHandlerTool.py.

00103 
00104     def register(self, obj):
00105         """See IUniqueIdSet.
00106         """
00107         uid = self.queryUid(obj, default=None)
00108         if uid is None:
00109             # generate a new unique id and set it
00110             generator = getUtility(IUniqueIdGenerator)
00111             uid = generator()
00112             self._setUid(obj, uid)
00113 
00114         return uid

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFUid.UniqueIdHandlerTool.UniqueIdHandlerTool.setUid (   self,
  obj,
  uid,
  check_uniqueness = True 
)
See IUniqueIdSet.

Definition at line 152 of file UniqueIdHandlerTool.py.

00152 
00153     def setUid(self, obj, uid, check_uniqueness=True):
00154         """See IUniqueIdSet.
00155         """
00156         # None is the only value a unique id shall never have!
00157         if uid is None:
00158             raise UniqueIdError, "It's forbidden to set a unique id to 'None'."
00159 
00160         # check for uniqueness if enabled
00161         if check_uniqueness:
00162             result = self.queryObject(uid)
00163             if result is not None and result != obj:
00164                 if callable(uid):
00165                     uid = uid()
00166                 raise UniqueIdError, \
00167                       "The unique id '%s' is already in use" % uid
00168 
00169         # everything is ok: set it!
00170         self._setUid(obj, uid)

Here is the call graph for this function:

See IUniqueIdSet.

Definition at line 116 of file UniqueIdHandlerTool.py.

00116 
00117     def unregister(self, obj):
00118         """See IUniqueIdSet.
00119         """
00120         UID_ATTRIBUTE_NAME = self.UID_ATTRIBUTE_NAME
00121         if getattr(aq_base(obj), UID_ATTRIBUTE_NAME, None) is None:
00122             raise UniqueIdError, \
00123                   "No unique id available to be unregistered on '%s'" % obj
00124 
00125         # delete the uid and reindex
00126         delattr(obj, UID_ATTRIBUTE_NAME)
00127         self._reindexObject(obj)

Here is the call graph for this function:

Here is the caller graph for this function:

See IUniqueIdUnrestrictedQuery.

Definition at line 241 of file UniqueIdHandlerTool.py.

00241 
00242     def unrestrictedGetBrain(self, uid):
00243         """See IUniqueIdUnrestrictedQuery.
00244         """
00245         return self._getBrain(uid, self.unrestrictedQueryBrain)

Here is the call graph for this function:

Here is the caller graph for this function:

See IUniqueIdUnrestrictedQuery.

Definition at line 247 of file UniqueIdHandlerTool.py.

00247 
00248     def unrestrictedGetObject(self, uid):
00249         """See IUniqueIdUnrestrictedQuery.
00250         """
00251         return self.unrestrictedGetBrain(uid).getObject()

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFUid.UniqueIdHandlerTool.UniqueIdHandlerTool.unrestrictedQueryBrain (   self,
  uid,
  default = None 
)
See IUniqueIdUnrestrictedQuery.

Definition at line 235 of file UniqueIdHandlerTool.py.

00235 
00236     def unrestrictedQueryBrain(self, uid, default=None):
00237         """See IUniqueIdUnrestrictedQuery.
00238         """
00239         return self._queryBrain(uid, 'unrestrictedSearchResults', default)

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFUid.UniqueIdHandlerTool.UniqueIdHandlerTool.unrestrictedQueryObject (   self,
  uid,
  default = None 
)
See IUniqueIdUnrestrictedQuery.

Definition at line 253 of file UniqueIdHandlerTool.py.

00253 
00254     def unrestrictedQueryObject(self, uid, default=None):
00255         """See IUniqueIdUnrestrictedQuery.
00256         """
00257         try:
00258             return self.unrestrictedGetObject(uid)
00259         except UniqueIdError:
00260             return default

Here is the call graph for this function:


Member Data Documentation

Definition at line 51 of file UniqueIdHandlerTool.py.

Initial value:
(
        SimpleItem.__implements__,
    )

Definition at line 55 of file UniqueIdHandlerTool.py.

string CMFUid.UniqueIdHandlerTool.UniqueIdHandlerTool.alternative_id = "portal_standard_uidhandler" [static]

Definition at line 66 of file UniqueIdHandlerTool.py.

string CMFUid.UniqueIdHandlerTool.UniqueIdHandlerTool.id = 'portal_uidhandler' [static]

Definition at line 59 of file UniqueIdHandlerTool.py.

Initial value:
( ({'label': 'Query',
                         'action': 'manage_queryObject'},)
                     + SimpleItem.manage_options
                     )

Definition at line 61 of file UniqueIdHandlerTool.py.

tuple CMFUid.UniqueIdHandlerTool.UniqueIdHandlerTool.manage_queryObject = PageTemplateFile('queryUID.pt', _wwwdir) [static]

Definition at line 262 of file UniqueIdHandlerTool.py.

string CMFUid.UniqueIdHandlerTool.UniqueIdHandlerTool.meta_type = 'Unique Id Handler Tool' [static]

Definition at line 67 of file UniqueIdHandlerTool.py.

tuple CMFUid.UniqueIdHandlerTool.UniqueIdHandlerTool.security = ClassSecurityInfo() [static]

Definition at line 76 of file UniqueIdHandlerTool.py.

Definition at line 71 of file UniqueIdHandlerTool.py.

Definition at line 74 of file UniqueIdHandlerTool.py.


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