Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add language column in import export #407

Merged
merged 6 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions home/export_content_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from openpyxl.workbook import Workbook
from openpyxl.worksheet.worksheet import Worksheet
from wagtail import blocks # type: ignore
from wagtail.coreutils import get_content_languages # type: ignore
from wagtail.models import Locale, Page # type: ignore
from wagtail.query import PageQuerySet # type: ignore

Expand Down Expand Up @@ -80,6 +81,7 @@ class ExportRow:
media_link: str = ""
related_pages: str = ""
footer: str = ""
language_code: str = ""
rudigiesler marked this conversation as resolved.
Show resolved Hide resolved

@classmethod
def headings(cls) -> list[str]:
Expand Down Expand Up @@ -208,6 +210,11 @@ def _export_content_page(self, page: ContentPage, structure: str) -> None:
* We should use the parent slug (which is expected to be unique per
locale (probably?)) instead of the parent title.
rudigiesler marked this conversation as resolved.
Show resolved Hide resolved
"""
export_lang_code = ""
for lang_code, lang_dn in get_content_languages().items():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not just content pages that need language codes, it's also content index pages.

if lang_dn == str(page.locale):
export_lang_code = lang_code
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not just do page.locale.language_code to get the language code for the current page?


row = ExportRow(
structure=structure,
message=1,
Expand All @@ -230,6 +237,7 @@ def _export_content_page(self, page: ContentPage, structure: str) -> None:
triggers=self._comma_sep_qs(page.triggers.all()),
locale=str(page.locale),
related_pages=self._comma_sep_qs(self._related_pages(page)),
language_code=export_lang_code,
)
self.rows.append(row)
message_bodies = list(
Expand Down Expand Up @@ -361,6 +369,7 @@ def _set_xlsx_styles(wb: Workbook, sheet: Worksheet) -> None:
"media_link": 118,
"related": 118,
"footer": 118,
"language_code": 118,
}

for index, column_width in enumerate(column_widths_in_pts.values(), 2):
Expand Down
6 changes: 5 additions & 1 deletion home/import_content_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,10 @@ def create_content_page_index_from_row(self, row: "ContentRow") -> None:
def create_shadow_content_page_from_row(
self, row: "ContentRow", row_num: int
) -> None:
locale = self.locale_from_display_name(row.locale)
if row.language_code:
locale = locale = Locale.objects.get(language_code=row.language_code)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if no Locale exists for the language code given in the row? In that case, we should raise an ImportException, similar to how locale_from_display_name does.

else:
locale = self.locale_from_display_name(row.locale)
page = ShadowContentPage(
row_num=row_num,
slug=row.slug,
Expand Down Expand Up @@ -738,6 +741,7 @@ class ContentRow:
media_link: str = ""
related_pages: list[str] = field(default_factory=list)
footer: str = ""
language_code: str = ""

@classmethod
def from_flat(cls, row: dict[str, str], row_num: int) -> "ContentRow":
Expand Down
10 changes: 5 additions & 5 deletions home/tests/import-export-data/content2.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
structure,message,page_id,Slug,parent,web_title,web_subtitle,web_body,whatsapp_title,whatsapp_body,whatsapp_template_name,whatsapp_template_category,example_values,variation_title,variation_body,list_title,list_items,sms_title,sms_body,ussd_title,ussd_body,messenger_title,messenger_body,viber_title,viber_body,translation_tag,tags,quick_replies,triggers,locale,next_prompt,buttons,image_link,doc_link,media_link,related_pages,footer
Menu 1,0,4,main-menu,,Main Menu,,,,,,,,,,,,,,,,,,,,a0b85075-d01b-46bf-8997-8591e87ba171,,,,English,,,,,,,
structure,message,page_id,Slug,parent,web_title,web_subtitle,web_body,whatsapp_title,whatsapp_body,whatsapp_template_name,whatsapp_template_category,example_values,variation_title,variation_body,list_title,list_items,sms_title,sms_body,ussd_title,ussd_body,messenger_title,messenger_body,viber_title,viber_body,translation_tag,tags,quick_replies,triggers,locale,next_prompt,buttons,image_link,doc_link,media_link,related_pages,footer,language_code
Menu 1,0,4,main-menu,,Main Menu,,,,,,,,,,,,,,,,,,,,a0b85075-d01b-46bf-8997-8591e87ba171,,,,English,,,,,,,,
Sub 1.1,1,5,main-menu-first-time-user,Main Menu,main menu first time user,,,main menu first time user,"*Welcome to HealthAlert* 🌍

This is a messaging service created by the _*World Health Organization*_ *(WHO)* that provides information on COVID-19 as well as emergency resources for disease outbreaks, natural, and man-made disasters.
Expand All @@ -12,12 +12,12 @@ This is a messaging service created by the World Health Organization (WHO) that

You can return to this main menu at any time by replying 🏠

Choose what you'd like to know more about by tapping a button below ⬇️",,,5892bccd-8025-419d-9a8e-a6a37b755dbf,menu,"Self-help🌬️, Settings⚙️, Health Info🏥",Main menu🏠,English,,[],,,,,
Choose what you'd like to know more about by tapping a button below ⬇️",,,5892bccd-8025-419d-9a8e-a6a37b755dbf,menu,"Self-help🌬️, Settings⚙️, Health Info🏥",Main menu🏠,English,,[],,,,,,en
Sub 1.1.1,1,6,health-info,main menu first time user,health info,,,health info,"*Health information* 🏥

Get information and advice from WHO by tapping on a button below ⬇️",,UTILITY,[],,,,[],Health Info SMS Title,*Health Info SMS Body*,Health Info USSD Title,*Health Info USSD Body*,health info,"*Health information* 🏥

Get information and advice from WHO by tapping on a button below ⬇️",,,c9d6309e-173f-4c1d-bbaf-440b1fd4415f,health_info,,,English,,[],,,,,
Get information and advice from WHO by tapping on a button below ⬇️",,,c9d6309e-173f-4c1d-bbaf-440b1fd4415f,health_info,,,English,,[],,,,,,en
Sub 1.1.2,1,7,self-help,main menu first time user,self-help,,,self-help,"*Self-help programs* 🌬️

Reply with a number to take part in a *free* self-help program created by WHO.
Expand All @@ -32,4 +32,4 @@ Reply with a number to take part in a *free* self-help program created by WHO.
1. Quit tobacco 🚭
_Stop smoking with the help of a guided, 42-day program._
2. Manage your stress 🧘🏽‍♀️
_Learn how to cope with stress and improve your wellbeing._",,,3e5d77f7-4d34-430d-aad7-d9ca01f79732,self_help,,,English,,[],,,,,
_Learn how to cope with stress and improve your wellbeing._",,,3e5d77f7-4d34-430d-aad7-d9ca01f79732,self_help,,,English,,[],,,,,,en
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
structure,message,page_id,slug,parent,web_title,web_subtitle,web_body,whatsapp_title,whatsapp_body,whatsapp_template_name,variation_title,variation_body,list_title,list_items,sms_title,sms_body,ussd_title,ussd_body,messenger_title,messenger_body,viber_title,viber_body,translation_tag,tags,quick_replies,triggers,locale,next_prompt,buttons,image_link,doc_link,media_link,related_pages,example_values,footer
Menu 1,0,5,appointment-reminders,,Appointment reminders,,,,,,,,,,,,,,,,,,8cff04aa-cf08-4120-88b4-e2269b7d5d80,,,,English,,,,,,,,
Menu 2,0,6,stage-based-messages,,Stage-based messages,,,,,,,,,,,,,,,,,,5f2d9e63-f047-41ab-921a-c5ca7c04d643,,,,English,,,,,,,,
Menu 3,0,7,health-info-messages,,Health info messages,,,,,,,,,,,,,,,,,,3db069a4-7112-4e66-a9a2-f35c6c18055a,,,,English,,,,,,,,
Menu 4,0,17,whatsapp-template-testing,,whatsapp template testing,,,,,,,,,,,,,,,,,,5f7221f4-146a-48c2-b2e3-c8491aaead9d,,,,English,,,,,,,,
Menu 5,0,164,import-export,,Import Export,,,,,,,,,,,,,,,,,,497bdc1f-43fc-4925-80a1-e68cb942faa4,,,,English,,,,,,,,
Sub 5.1,1,165,cp-import-export,Import Export,CP-Import/export,,,WA import export data,Message 1 contains an image,,,,,[],,,,,,,,,8ac50daf-de21-4d05-b697-6d983b7ed3d5,"Tag2, Tag1",Quick reply1,"Trigger2, Trigger1",English,,[],/admin/images/usage/4/,,,ma_qa_temp,,
,1,165,cp-import-export,,,,,,,,gender: male,Variation message one for Gender Male,,,,,,,,,,,,,,,,,,,,,,,
,2,165,cp-import-export,,,,,,"Message2 has a document attached",,,,,[],,,,,,,,,,,,,,,[],,/admin/documents/usage/1/,,,,
,2,165,cp-import-export,,,,,,,,gender: empty,Variation message one for Gender Rather not say,,,,,,,,,,,,,,,,,,,,,,,
,3,165,cp-import-export,,,,,,Message 3 with no variation but has an audio clip,,,,,[],,,,,,,,,,,,,,,[],,,/admin/media/usage/1/,,,
Sub 5.2,1,166,ma_qa_temp,Import Export,MA QA Temp,,,,,,,,,,,,,,,,,,e9793b5f-f8c7-46c5-8a5e-bd9b8f00fee9,,,,English,,,,,,,,
structure,message,page_id,slug,parent,web_title,web_subtitle,web_body,whatsapp_title,whatsapp_body,whatsapp_template_name,variation_title,variation_body,list_title,list_items,sms_title,sms_body,ussd_title,ussd_body,messenger_title,messenger_body,viber_title,viber_body,translation_tag,tags,quick_replies,triggers,locale,next_prompt,buttons,image_link,doc_link,media_link,related_pages,example_values,footer,language_code
Menu 1,0,5,appointment-reminders,,Appointment reminders,,,,,,,,,,,,,,,,,,8cff04aa-cf08-4120-88b4-e2269b7d5d80,,,,English,,,,,,,,,
Menu 2,0,6,stage-based-messages,,Stage-based messages,,,,,,,,,,,,,,,,,,5f2d9e63-f047-41ab-921a-c5ca7c04d643,,,,English,,,,,,,,,
Menu 3,0,7,health-info-messages,,Health info messages,,,,,,,,,,,,,,,,,,3db069a4-7112-4e66-a9a2-f35c6c18055a,,,,English,,,,,,,,,
Menu 4,0,17,whatsapp-template-testing,,whatsapp template testing,,,,,,,,,,,,,,,,,,5f7221f4-146a-48c2-b2e3-c8491aaead9d,,,,English,,,,,,,,,
Menu 5,0,164,import-export,,Import Export,,,,,,,,,,,,,,,,,,497bdc1f-43fc-4925-80a1-e68cb942faa4,,,,English,,,,,,,,,
Sub 5.1,1,165,cp-import-export,Import Export,CP-Import/export,,,WA import export data,Message 1 contains an image,,,,,[],,,,,,,,,8ac50daf-de21-4d05-b697-6d983b7ed3d5,"Tag2, Tag1",Quick reply1,"Trigger2, Trigger1",English,,[],/admin/images/usage/4/,,,ma_qa_temp,,,en
,1,165,cp-import-export,,,,,,,,gender: male,Variation message one for Gender Male,,,,,,,,,,,,,,,,,,,,,,,,
,2,165,cp-import-export,,,,,,Message2 has a document attached,,,,,[],,,,,,,,,,,,,,,[],,/admin/documents/usage/1/,,,,,
,2,165,cp-import-export,,,,,,,,gender: empty,Variation message one for Gender Rather not say,,,,,,,,,,,,,,,,,,,,,,,,
,3,165,cp-import-export,,,,,,Message 3 with no variation but has an audio clip,,,,,[],,,,,,,,,,,,,,,[],,,/admin/media/usage/1/,,,,
Sub 5.2,1,166,ma_qa_temp,Import Export,MA QA Temp,,,,,,,,,,,,,,,,,,e9793b5f-f8c7-46c5-8a5e-bd9b8f00fee9,,,,English,,,,,,,,,en
35 changes: 35 additions & 0 deletions home/tests/import-export-data/language_code_import.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
structure,message,page_id,Slug,parent,web_title,web_subtitle,web_body,whatsapp_title,whatsapp_body,whatsapp_template_name,whatsapp_template_category,example_values,variation_title,variation_body,list_title,list_items,sms_title,sms_body,ussd_title,ussd_body,messenger_title,messenger_body,viber_title,viber_body,translation_tag,tags,quick_replies,triggers,locale,next_prompt,buttons,image_link,doc_link,media_link,related_pages,footer,language_code
Menu 1,0,4,main-menu,,Main Menu,,,,,,,,,,,,,,,,,,,,a0b85075-d01b-46bf-8997-8591e87ba171,,,,English,,,,,,,,
Sub 1.1,1,5,main-menu-first-time-user,Main Menu,main menu first time user,,,main menu first time user,"*Welcome to HealthAlert* 🌍

This is a messaging service created by the _*World Health Organization*_ *(WHO)* that provides information on COVID-19 as well as emergency resources for disease outbreaks, natural, and man-made disasters.

_You can return to this main menu at any time by replying *0*_ 🏠

Choose what you'd like to know more about by tapping a button below ⬇️",,UTILITY,[],,,,[],,,,,main menu first time user,"Welcome to HealthAlert 🌍

This is a messaging service created by the World Health Organization (WHO) that provides information on COVID-19 as well as emergency resources for disease outbreaks, natural, and man-made disasters.

You can return to this main menu at any time by replying 🏠

Choose what you'd like to know more about by tapping a button below ⬇️",,,5892bccd-8025-419d-9a8e-a6a37b755dbf,menu,"Self-help🌬️, Settings⚙️, Health Info🏥",Main menu🏠,English,,[],,,,,,
Sub 1.1.1,1,6,health-info,main menu first time user,health info,,,health info,"*Health information* 🏥

Get information and advice from WHO by tapping on a button below ⬇️",,UTILITY,[],,,,[],Health Info SMS Title,*Health Info SMS Body*,Health Info USSD Title,*Health Info USSD Body*,health info,"*Health information* 🏥

Get information and advice from WHO by tapping on a button below ⬇️",,,c9d6309e-173f-4c1d-bbaf-440b1fd4415f,health_info,,,English,,[],,,,,,
Sub 1.1.2,1,7,self-help,main menu first time user,self-help,,,self-help,"*Self-help programs* 🌬️

Reply with a number to take part in a *free* self-help program created by WHO.

1. Quit tobacco 🚭
_Stop smoking with the help of a guided, 42-day program._
2. Manage your stress 🧘🏽‍♀️
_Learn how to cope with stress and improve your wellbeing._",,UTILITY,[],,,,[],,,,,self-help,"*Self-help programs* 🌬️

Reply with a number to take part in a *free* self-help program created by WHO.

1. Quit tobacco 🚭
_Stop smoking with the help of a guided, 42-day program._
2. Manage your stress 🧘🏽‍♀️
_Learn how to cope with stress and improve your wellbeing._",,,3e5d77f7-4d34-430d-aad7-d9ca01f79732,self_help,,,English,,[],,,,,,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need so much and so long content for this test? Maybe we can reduce it to just what is necessary, so that it's easier to see what we're testing here.

35 changes: 35 additions & 0 deletions home/tests/import-export-data/language_code_import_output.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
structure,message,page_id,Slug,parent,web_title,web_subtitle,web_body,whatsapp_title,whatsapp_body,whatsapp_template_name,whatsapp_template_category,example_values,variation_title,variation_body,list_title,list_items,sms_title,sms_body,ussd_title,ussd_body,messenger_title,messenger_body,viber_title,viber_body,translation_tag,tags,quick_replies,triggers,locale,next_prompt,buttons,image_link,doc_link,media_link,related_pages,footer,language_code
Menu 1,0,4,main-menu,,Main Menu,,,,,,,,,,,,,,,,,,,,a0b85075-d01b-46bf-8997-8591e87ba171,,,,English,,,,,,,,
Sub 1.1,1,5,main-menu-first-time-user,Main Menu,main menu first time user,,,main menu first time user,"*Welcome to HealthAlert* 🌍

This is a messaging service created by the _*World Health Organization*_ *(WHO)* that provides information on COVID-19 as well as emergency resources for disease outbreaks, natural, and man-made disasters.

_You can return to this main menu at any time by replying *0*_ 🏠

Choose what you'd like to know more about by tapping a button below ⬇️",,UTILITY,[],,,,[],,,,,main menu first time user,"Welcome to HealthAlert 🌍

This is a messaging service created by the World Health Organization (WHO) that provides information on COVID-19 as well as emergency resources for disease outbreaks, natural, and man-made disasters.

You can return to this main menu at any time by replying 🏠

Choose what you'd like to know more about by tapping a button below ⬇️",,,5892bccd-8025-419d-9a8e-a6a37b755dbf,menu,"Self-help🌬️, Settings⚙️, Health Info🏥",Main menu🏠,English,,[],,,,,,en
Sub 1.1.1,1,6,health-info,main menu first time user,health info,,,health info,"*Health information* 🏥

Get information and advice from WHO by tapping on a button below ⬇️",,UTILITY,[],,,,[],Health Info SMS Title,*Health Info SMS Body*,Health Info USSD Title,*Health Info USSD Body*,health info,"*Health information* 🏥

Get information and advice from WHO by tapping on a button below ⬇️",,,c9d6309e-173f-4c1d-bbaf-440b1fd4415f,health_info,,,English,,[],,,,,,en
Sub 1.1.2,1,7,self-help,main menu first time user,self-help,,,self-help,"*Self-help programs* 🌬️

Reply with a number to take part in a *free* self-help program created by WHO.

1. Quit tobacco 🚭
_Stop smoking with the help of a guided, 42-day program._
2. Manage your stress 🧘🏽‍♀️
_Learn how to cope with stress and improve your wellbeing._",,UTILITY,[],,,,[],,,,,self-help,"*Self-help programs* 🌬️

Reply with a number to take part in a *free* self-help program created by WHO.

1. Quit tobacco 🚭
_Stop smoking with the help of a guided, 42-day program._
2. Manage your stress 🧘🏽‍♀️
_Learn how to cope with stress and improve your wellbeing._",,,3e5d77f7-4d34-430d-aad7-d9ca01f79732,self_help,,,English,,[],,,,,,en
6 changes: 3 additions & 3 deletions home/tests/import-export-data/list_items.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
structure,message,page_id,slug,parent,web_title,web_subtitle,web_body,whatsapp_title,whatsapp_body,whatsapp_template_name,whatsapp_template_category,variation_title,variation_body,list_title,list_items,sms_title,sms_body,ussd_title,ussd_body,messenger_title,messenger_body,viber_title,viber_body,translation_tag,tags,quick_replies,triggers,locale,next_prompt,buttons,image_link,doc_link,media_link,related_pages,footer
Menu 1,0,600,main-menu,,Main Menu,,,,,,,,,,,,,,,,,,,35a7f12c-7373-42a6-9ca6-a1caedea5822,,,,English,,,,,,,
Sub 1.1,1,601,ha-menu,Main Menu,HealthAlert menu,,,HealthAlert menu,*Welcome to HealthAlert* WA,,UTILITY,,,List Title,"'Item 1','Item 2'",,,,,HealthAlert menu,Welcome to HealthAlert M,HealthAlert menu,Welcome to HealthAlert V,5ab08854-228b-4f83-ae54-ec2dc6ebaf69,,,,English,,[],,,,,
structure,message,page_id,slug,parent,web_title,web_subtitle,web_body,whatsapp_title,whatsapp_body,whatsapp_template_name,whatsapp_template_category,variation_title,variation_body,list_title,list_items,sms_title,sms_body,ussd_title,ussd_body,messenger_title,messenger_body,viber_title,viber_body,translation_tag,tags,quick_replies,triggers,locale,next_prompt,buttons,image_link,doc_link,media_link,related_pages,footer,language_code
Menu 1,0,600,main-menu,,Main Menu,,,,,,,,,,,,,,,,,,,35a7f12c-7373-42a6-9ca6-a1caedea5822,,,,English,,,,,,,,
Sub 1.1,1,601,ha-menu,Main Menu,HealthAlert menu,,,HealthAlert menu,*Welcome to HealthAlert* WA,,UTILITY,,,List Title,"'Item 1','Item 2'",,,,,HealthAlert menu,Welcome to HealthAlert M,HealthAlert menu,Welcome to HealthAlert V,5ab08854-228b-4f83-ae54-ec2dc6ebaf69,,,,English,,[],,,,,,en
6 changes: 3 additions & 3 deletions home/tests/import-export-data/list_items_output.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
structure,message,page_id,slug,parent,web_title,web_subtitle,web_body,whatsapp_title,whatsapp_body,whatsapp_template_name,whatsapp_template_category,variation_title,variation_body,list_title,list_items,sms_title,sms_body,ussd_title,ussd_body,messenger_title,messenger_body,viber_title,viber_body,translation_tag,tags,quick_replies,triggers,locale,next_prompt,buttons,image_link,doc_link,media_link,related_pages,footer
Menu 1,0,600,main-menu,,Main Menu,,,,,,,,,,,,,,,,,,,35a7f12c-7373-42a6-9ca6-a1caedea5822,,,,English,,,,,,,
Sub 1.1,1,601,ha-menu,Main Menu,HealthAlert menu,,,HealthAlert menu,*Welcome to HealthAlert* WA,,UTILITY,,,List Title,"[{""type"": ""next_message"", ""title"": ""'Item 1'""}, {""type"": ""next_message"", ""title"": ""'Item 2'""}]",,,,,HealthAlert menu,Welcome to HealthAlert M,HealthAlert menu,Welcome to HealthAlert V,5ab08854-228b-4f83-ae54-ec2dc6ebaf69,,,,English,,[],,,,,
structure,message,page_id,slug,parent,web_title,web_subtitle,web_body,whatsapp_title,whatsapp_body,whatsapp_template_name,whatsapp_template_category,variation_title,variation_body,list_title,list_items,sms_title,sms_body,ussd_title,ussd_body,messenger_title,messenger_body,viber_title,viber_body,translation_tag,tags,quick_replies,triggers,locale,next_prompt,buttons,image_link,doc_link,media_link,related_pages,footer,language_code
Menu 1,0,600,main-menu,,Main Menu,,,,,,,,,,,,,,,,,,,35a7f12c-7373-42a6-9ca6-a1caedea5822,,,,English,,,,,,,,
Sub 1.1,1,601,ha-menu,Main Menu,HealthAlert menu,,,HealthAlert menu,*Welcome to HealthAlert* WA,,UTILITY,,,List Title,"[{""type"": ""next_message"", ""title"": ""'Item 1'""}, {""type"": ""next_message"", ""title"": ""'Item 2'""}]",,,,,HealthAlert menu,Welcome to HealthAlert M,HealthAlert menu,Welcome to HealthAlert V,5ab08854-228b-4f83-ae54-ec2dc6ebaf69,,,,English,,[],,,,,,en
Loading
Loading