Back to index

plone3  3.1.7
Public Member Functions | Static Public Attributes
Marshall.namespaces.atns.Reference Class Reference

List of all members.

Public Member Functions

def resolve

Static Public Attributes

tuple index_map

Detailed Description

Definition at line 400 of file atns.py.


Member Function Documentation

def Marshall.namespaces.atns.Reference.resolve (   self,
  context 
)

Definition at line 412 of file atns.py.

00412 
00413     def resolve(self, context):
00414         uid = self.get('uid')
00415         if uid is not None:
00416             rt = getToolByName(context, atcfg.REFERENCE_CATALOG)
00417             return rt.lookupObject(uid)
00418         path = self.get('path')
00419         if path is not None:
00420             return context.restrictedTraverse(path, None)
00421         catalog = getToolByName(context, 'portal_catalog')
00422         params = [(k, v) for k, v in self.items() \
00423                   if k not in ('uid', 'path')]
00424         kw = [(self.index_map.get(k), v) for k, v in params]
00425         kw = dict(filter(lambda x: x[0] is not None and x, kw))
00426         res = catalog(**kw)
00427         if not res:
00428             return None
00429 
00430         # First step: Try to filter by brain metadata
00431         # *Usually* a metadata item will exist with the same name
00432         # as the index.
00433         verify = lambda obj: filter(None, [obj[k] == v for k, v in kw.items()])
00434         for r in res:
00435             # Shortest path: If a match is found, return immediately
00436             # instead of checking all of the results.
00437             if verify(r):
00438                 return r.getObject()
00439 
00440         # Second step: Try to get the real objects and look
00441         # into them. Should be *very* slow, so use with care.
00442         # We use __getitem__ to access the field raw data.
00443         verify = lambda obj: filter(None, [obj[k] == v for k, v in params])
00444         valid = filter(verify, [r.getObject() for r in res])
00445         if not valid:
00446             return None
00447         if len(valid) > 1:
00448             raise MarshallingException, ('Metadata reference does not '
00449                                          'uniquely identifies the reference.')
00450         return valid[0]

Member Data Documentation

Initial value:
dict([('title', 'Title'),
                      ('description', 'Description'),
                      ('creation_date', 'created'),
                      ('modification_data', 'modified'),
                      ('creators', 'Creator'),
                      ('subject', 'Subject'),
                      ('effectiveDate', 'effective'),
                      ('expirationDate', 'expires'),
                      ])

Definition at line 402 of file atns.py.


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