Updated documents indexers to handle null attributes
authorThierry Florac <tflorac@ulthar.net>
Wed, 19 Sep 2018 10:31:36 +0200
changeset 85 1a37243abeae
parent 84 a4c07965e256
child 86 e91c03da4e28
Updated documents indexers to handle null attributes
src/pyams_content_es/component/paragraph.py
--- a/src/pyams_content_es/component/paragraph.py	Wed Sep 19 10:31:06 2018 +0200
+++ b/src/pyams_content_es/component/paragraph.py	Wed Sep 19 10:31:36 2018 +0200
@@ -12,10 +12,6 @@
 
 __docformat__ = 'restructuredtext'
 
-
-# import standard library
-
-# import interfaces
 from pyams_content.component.gallery.interfaces import IGalleryParagraph
 from pyams_content.component.illustration.interfaces import IIllustrationParagraph
 from pyams_content.component.paragraph.interfaces import IParagraphContainer, IParagraphContainerTarget, \
@@ -32,8 +28,6 @@
 from pyams_content.shared.imagemap.interfaces import IImageMapParagraph
 from pyams_content_es.interfaces import IDocumentIndexInfo
 from pyams_i18n.interfaces import II18nManager
-
-# import packages
 from pyams_utils.adapter import adapter_config
 from pyams_utils.html import html_to_text
 from pyams_utils.traversing import get_parent
@@ -128,11 +122,11 @@
     manager = get_parent(paragraph, II18nManager)
     for lang in manager.get_languages():
         for attr in ('title', 'description'):
-            value = getattr(paragraph, attr, {}).get(lang, '')
+            value = (getattr(paragraph, attr, {}) or {}).get(lang, '')
             if value:
                 info[lang] = '{old}\n{value}'.format(old=info.get(lang, ''),
                                                      value=value)
-        for attr in ('author', ):
+        for attr in ('author',):
             value = getattr(paragraph, attr, '')
             if value:
                 info[lang] = '{old}\n{value}'.format(old=info.get(lang, ''),
@@ -147,11 +141,11 @@
     manager = get_parent(paragraph, II18nManager)
     for lang in manager.get_languages():
         for attr in ('title', 'description'):
-            value = getattr(paragraph, attr, {}).get(lang, '')
+            value = (getattr(paragraph, attr, {}) or {}).get(lang, '')
             if value:
                 info[lang] = '{old}\n{value}'.format(old=info.get(lang, ''),
                                                      value=value)
-        for attr in ('author', ):
+        for attr in ('author',):
             value = getattr(paragraph, attr, '')
             if value:
                 info[lang] = '{old}\n{value}'.format(old=info.get(lang, ''),
@@ -170,7 +164,7 @@
             info[lang] = '{old}\n{body}'.format(old=info.get(lang, ''),
                                                 body=html_to_text(body.replace('\r', '')))
         for attr in ('title', 'description'):
-            value = getattr(paragraph, attr, {}).get(lang, '')
+            value = (getattr(paragraph, attr, {}) or {}).get(lang, '')
             if value:
                 info[lang] = '{old}\n{value}'.format(old=info.get(lang, ''),
                                                      value=value)
@@ -199,7 +193,7 @@
     manager = get_parent(paragraph, II18nManager)
     for lang in manager.get_languages():
         for attr in ('title', 'charge'):
-            value = getattr(paragraph, attr, {}).get(lang, '')
+            value = (getattr(paragraph, attr, {}) or {}).get(lang, '')
             if value:
                 info[lang] = '{old}\n{value}'.format(old=info.get(lang, ''),
                                                      value=value)
@@ -242,11 +236,11 @@
     manager = get_parent(paragraph, II18nManager)
     for lang in manager.get_languages():
         for attr in ('title', 'quote', 'charge'):
-            value = getattr(paragraph, attr, {}).get(lang, '')
+            value = (getattr(paragraph, attr, {}) or {}).get(lang, '')
             if value:
                 info[lang] = '{old}\n{value}'.format(old=info.get(lang, ''),
                                                      value=value)
-        for attr in ('author', ):
+        for attr in ('author',):
             value = getattr(paragraph, attr, '')
             if value:
                 info[lang] = '{old}\n{value}'.format(old=info.get(lang, ''),