Updated paragraphs index adapters
authortflorac@xsup98-004.onf.fr
Thu, 12 Oct 2017 22:18:45 +0200
changeset 26 76977fecfcbf
parent 25 22aeb66a6092
child 27 8f3ce51a13b8
Updated paragraphs index adapters
src/pyams_content_es/component/paragraph.py
--- a/src/pyams_content_es/component/paragraph.py	Tue Sep 19 11:39:32 2017 +0200
+++ b/src/pyams_content_es/component/paragraph.py	Thu Oct 12 22:18:45 2017 +0200
@@ -33,7 +33,7 @@
 def HeaderParagraphIndexInfo(paragraph):
     """Header paragraph index info"""
     info = {}
-    for lang, header in paragraph.header.items():
+    for lang, header in (getattr(paragraph, 'header', {}) or {}).items():
         if header:
             info.setdefault(lang, header)
     return info
@@ -43,10 +43,10 @@
 def HTMLParagraphIndexInfo(paragraph):
     """HTML paragraph index info"""
     info = {}
-    for lang, title in paragraph.title.items():
+    for lang, title in (getattr(paragraph, 'title', {}) or {}).items():
         if title:
             info.setdefault(lang, title)
-    for lang, body in paragraph.body.items():
+    for lang, body in (getattr(paragraph, 'body', {}) or {}).items():
         if body:
             new_body = '{old}\n{body}'.format(old=info.get(lang, ''),
                                               body=html_to_text(body).replace('\r', ''))
@@ -58,10 +58,10 @@
 def IllustrationIndexInfo(paragraph):
     """Illustration index info"""
     info = {}
-    for lang, title in paragraph.title.items():
+    for lang, title in (getattr(paragraph, 'title', {}) or {}).items():
         if title:
             info.setdefault(lang, title)
-    for lang, legend in paragraph.alt_title.items():
+    for lang, legend in (getattr(paragraph, 'alt_title', {}) or {}).items():
         if legend:
             new_legend = '{old}\n{legend}'.format(old=info.get(lang, ''),
                                                   legend=legend)
@@ -73,7 +73,7 @@
 def GalleryParagraphIndexInfo(paragraph):
     """Gallery paragraph index info"""
     info = {}
-    for lang, title in paragraph.title.items():
+    for lang, title in (getattr(paragraph, 'title', {}) or {}).items():
         if title:
             info.setdefault(lang, title)
     for image in IGalleryParagraph(paragraph).values():
@@ -91,7 +91,7 @@
 def ImagemapParagraphIndexInfo(paragraph):
     """Image map paragraph index info"""
     info = {}
-    for lang, title in paragraph.title.items():
+    for lang, title in (getattr(paragraph, 'title', {}) or {}).items():
         if title:
             info.setdefault(lang, title)
     return info