source: WAeUP_SRP/branches/joachim-event-branch/PatchCPSSchemasVocabulariesTool.py @ 1892

Last change on this file since 1892 was 1351, checked in by joachim, 18 years ago

add missing LOCAL_VOCABULARY_CONTAINER_ID

  • Property svn:keywords set to Id
File size: 1.3 KB
Line 
1from Products.CPSSchemas.VocabulariesTool import LOCAL_VOCABULARY_CONTAINER_ID
2def getVocabularyFor(self, context, voc_id):
3    """Returns vocabulary for given context."""
4
5    def hasLocalVocContainer(context):
6        if getattr(context, 'hasObject', None) is None:
7            return False
8        return context.hasObject(LOCAL_VOCABULARY_CONTAINER_ID)
9
10    def getLocalVocContainer(context):
11        return context._getOb(LOCAL_VOCABULARY_CONTAINER_ID, None)
12
13    getParentNode = lambda node: getattr(getattr(node, 'aq_inner', None),
14                                         'aq_parent', None)
15
16    if not hasLocalVocContainer(context):
17        parent = getParentNode(context)
18        while parent is not None:
19            if hasLocalVocContainer(parent):
20                return getLocalVocContainer(parent).getVocabulary(voc_id)
21            parent = getParentNode(parent)
22        # no local vocabulary container found for given context
23        globvoc = self._getOb(voc_id, None)
24        if globvoc is None:
25            raise KeyError, 'No vocabulary by id %s' % voc_id
26        return globvoc
27    else:
28        return getLocalVocContainer(context).getVocabulary(voc_id)
29from Products.CPSSchemas.VocabulariesTool import VocabulariesTool
30VocabulariesTool.getVocabularyFor = getVocabularyFor
Note: See TracBrowser for help on using the repository browser.