handle absence of thesaurus

This commit is contained in:
Frédéric Péters 2013-04-14 17:33:36 +02:00
parent b695a187cf
commit da58a1a6c2
2 changed files with 8 additions and 1 deletions

View File

@ -46,5 +46,8 @@ class ImportJson(BrowserView):
def get_thesaurus_object(context):
catalog = getToolByName(context, 'portal_catalog')
thesaurus = catalog(portal_type='dmsthesaurus')[0].getObject()
try:
thesaurus = catalog(portal_type='dmsthesaurus')[0].getObject()
except IndexError:
return None
return thesaurus

View File

@ -26,6 +26,8 @@ class SimpleThesaurusSource(object):
def __call__(self, context):
# build vocab from first thesaurus returned by catalog
thesaurus = utils.get_thesaurus_object(context)
if thesaurus is None:
return SimpleVocabulary([])
thesaurus_path = '/'.join(thesaurus.getPhysicalPath())
catalog = getToolByName(context, 'portal_catalog')
results = catalog(portal_type='dmskeyword',
@ -56,6 +58,8 @@ class KeywordFromSameThesaurusSource(object):
thesaurus_path = '/'.join(context.getPhysicalPath())
else:
thesaurus = utils.get_thesaurus_object(context)
if thesaurus is None:
return SimpleVocabulary([])
thesaurus_path = '/'.join(thesaurus.getPhysicalPath())
catalog = getToolByName(context, 'portal_catalog')
results = catalog(portal_type='dmskeyword',