From da58a1a6c27631a0c013651aad288ca18a0c5eac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Sun, 14 Apr 2013 17:33:36 +0200 Subject: [PATCH] handle absence of thesaurus --- src/collective/dms/thesaurus/utils.py | 5 ++++- src/collective/dms/thesaurus/vocabulary.py | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) 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',