diff --git a/home/export_content_pages.py b/home/export_content_pages.py index 3b251015..0f5a200c 100644 --- a/home/export_content_pages.py +++ b/home/export_content_pages.py @@ -125,7 +125,7 @@ def add_message_fields(self, msg_blocks: MsgBlocks) -> None: self.whatsapp_body = whatsapp.value["message"].strip() if "image" in whatsapp.value and whatsapp.value["image"] is not None: self.image_link = whatsapp.value["image"].file.url - if "document" in whatsapp.value: + if "document" in whatsapp.value and whatsapp.value["document"] is not None: self.doc_link = whatsapp.value["document"].file.url if "media" in whatsapp.value and whatsapp.value["media"] is not None: self.media_link = whatsapp.value["media"].file.url diff --git a/home/tests/test_content_import_export.py b/home/tests/test_content_import_export.py index 84957b51..b8984ff2 100644 --- a/home/tests/test_content_import_export.py +++ b/home/tests/test_content_import_export.py @@ -1095,6 +1095,21 @@ def test_export_wa_with_document(self, impexp: ImportExport) -> None: # Export should succeed assert content is not None + def test_export_wa_with_none_document(self, impexp: ImportExport) -> None: + home_page = HomePage.objects.first() + main_menu = PageBuilder.build_cpi(home_page, "main-menu", "Main Menu") + _ha_menu = PageBuilder.build_cp( + parent=main_menu, + slug="ha-menu", + title="HealthAlert menu", + bodies=[ + WABody("HA menu", [WABlk("Welcome WA", document=None)]), + ], + ) + content = impexp.export_content(locale="en") + # Export should succeed + assert content is not None + @pytest.fixture(params=["csv", "xlsx"]) def impexp(request: Any, admin_client: Any) -> ImportExport: