diff --git a/src/collective/dms/thesaurus/utils.py b/src/collective/dms/thesaurus/utils.py index 48cdbcf..5a85b11 100644 --- a/src/collective/dms/thesaurus/utils.py +++ b/src/collective/dms/thesaurus/utils.py @@ -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 diff --git a/src/collective/dms/thesaurus/vocabulary.py b/src/collective/dms/thesaurus/vocabulary.py index 279b59c..62e6ab3 100644 --- a/src/collective/dms/thesaurus/vocabulary.py +++ b/src/collective/dms/thesaurus/vocabulary.py @@ -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',