diff --git a/home/migrations/0046_alter_contentpage_whatsapp_body.py b/home/migrations/0046_alter_contentpage_whatsapp_body.py new file mode 100644 index 00000000..876eced8 --- /dev/null +++ b/home/migrations/0046_alter_contentpage_whatsapp_body.py @@ -0,0 +1,190 @@ +# Generated by Django 4.1.13 on 2024-01-24 04:40 + +import django.core.validators +import wagtail.blocks +import wagtail.documents.blocks +import wagtail.fields +import wagtail.images.blocks +from django.db import migrations + +import home.models + + +class Migration(migrations.Migration): + dependencies = [ + ("home", "0045_merge_20240123_1102"), + ] + + operations = [ + migrations.AlterField( + model_name="contentpage", + name="whatsapp_body", + field=wagtail.fields.StreamField( + [ + ( + "Whatsapp_Message", + wagtail.blocks.StructBlock( + [ + ( + "image", + wagtail.images.blocks.ImageChooserBlock( + required=False + ), + ), + ( + "document", + wagtail.documents.blocks.DocumentChooserBlock( + icon="document", required=False + ), + ), + ( + "media", + home.models.MediaBlock( + icon="media", required=False + ), + ), + ( + "message", + wagtail.blocks.TextBlock( + help_text="each text message cannot exceed 4096 characters, messages with media cannot exceed 1024 characters.", + validators=( + django.core.validators.MaxLengthValidator( + 4096 + ), + ), + ), + ), + ( + "example_values", + wagtail.blocks.ListBlock( + wagtail.blocks.CharBlock(label="Example Value"), + default=[], + help_text="Please add example values for all variables used in a WhatsApp template", + label="Variable Example Values", + ), + ), + ( + "variation_messages", + wagtail.blocks.ListBlock( + wagtail.blocks.StructBlock( + [ + ( + "variation_restrictions", + wagtail.blocks.StreamBlock( + [ + ( + "gender", + wagtail.blocks.ChoiceBlock( + choices=home.models.get_gender_choices + ), + ), + ( + "age", + wagtail.blocks.ChoiceBlock( + choices=home.models.get_age_choices + ), + ), + ( + "relationship", + wagtail.blocks.ChoiceBlock( + choices=home.models.get_relationship_choices + ), + ), + ], + help_text="Restrict this variation to users with this profile value. Valid values must be added to the Site Settings", + max_num=1, + min_num=1, + required=False, + use_json_field=True, + ), + ), + ( + "message", + wagtail.blocks.TextBlock( + help_text="each message cannot exceed 4096 characters.", + validators=( + django.core.validators.MaxLengthValidator( + 4096 + ), + ), + ), + ), + ] + ), + default=[], + ), + ), + ( + "next_prompt", + wagtail.blocks.CharBlock( + help_text="prompt text for next message", + required=False, + validators=( + django.core.validators.MaxLengthValidator( + 20 + ), + ), + ), + ), + ( + "buttons", + wagtail.blocks.StreamBlock( + [ + ( + "next_message", + wagtail.blocks.StructBlock( + [ + ( + "title", + wagtail.blocks.CharBlock( + help_text="text for the button, up to 20 characters.", + validators=( + django.core.validators.MaxLengthValidator( + 20 + ), + ), + ), + ) + ] + ), + ), + ( + "go_to_page", + wagtail.blocks.StructBlock( + [ + ( + "title", + wagtail.blocks.CharBlock( + help_text="text for the button, up to 20 characters.", + validators=( + django.core.validators.MaxLengthValidator( + 20 + ), + ), + ), + ), + ( + "page", + wagtail.blocks.PageChooserBlock( + help_text="page the button should go to" + ), + ), + ] + ), + ), + ], + max_num=3, + required=False, + ), + ), + ], + help_text="Each message will be sent with the text and media", + ), + ) + ], + blank=True, + null=True, + use_json_field=True, + ), + ), + ] diff --git a/home/migrations/0047_alter_contentpage_messenger_title_and_more.py b/home/migrations/0047_alter_contentpage_messenger_title_and_more.py new file mode 100644 index 00000000..17432262 --- /dev/null +++ b/home/migrations/0047_alter_contentpage_messenger_title_and_more.py @@ -0,0 +1,79 @@ +# Generated by Django 4.1.13 on 2024-01-24 05:21 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("home", "0046_alter_contentpage_whatsapp_body"), + ] + + operations = [ + migrations.AlterField( + model_name="contentpage", + name="messenger_title", + field=models.CharField(blank=True, default="", max_length=200), + ), + migrations.AlterField( + model_name="contentpage", + name="subtitle", + field=models.CharField(blank=True, default="", max_length=200), + ), + migrations.AlterField( + model_name="contentpage", + name="viber_title", + field=models.CharField(blank=True, default="", max_length=200), + ), + migrations.AlterField( + model_name="contentpage", + name="whatsapp_title", + field=models.CharField(blank=True, default="", max_length=200), + ), + migrations.AlterField( + model_name="pageview", + name="platform", + field=models.CharField( + blank=True, + choices=[ + ("WHATSAPP", "whatsapp"), + ("SMS", "sms"), + ("USSD", "ussd"), + ("VIBER", "viber"), + ("MESSENGER", "messenger"), + ("WEB", "web"), + ], + default="web", + max_length=20, + ), + ), + migrations.AlterField( + model_name="sitesettings", + name="login_message", + field=models.CharField( + blank=True, + default="", + help_text="The login message shown on the login page", + max_length=100, + ), + ), + migrations.AlterField( + model_name="sitesettings", + name="title", + field=models.CharField( + blank=True, + default="", + help_text="The branding title shown in the CMS", + max_length=30, + ), + ), + migrations.AlterField( + model_name="sitesettings", + name="welcome_message", + field=models.CharField( + blank=True, + default="", + help_text="The welcome message shown after logging in", + max_length=100, + ), + ), + ] diff --git a/home/models.py b/home/models.py index 48efdd79..b71c9513 100644 --- a/home/models.py +++ b/home/models.py @@ -97,19 +97,19 @@ class SiteSettings(BaseSiteSetting): title = models.CharField( max_length=30, blank=True, - null=True, + default="", help_text="The branding title shown in the CMS", ) login_message = models.CharField( max_length=100, blank=True, - null=True, + default="", help_text="The login message shown on the login page", ) welcome_message = models.CharField( max_length=100, blank=True, - null=True, + default="", help_text="The welcome message shown after logging in", ) logo = models.ImageField(blank=True, null=True, upload_to="images") @@ -465,7 +465,7 @@ class WhatsAppTemplateCategory(models.TextChoices): ) # Web page setup - subtitle = models.CharField(max_length=200, blank=True, null=True) + subtitle = models.CharField(max_length=200, blank=True, default="") body = StreamField( [ ("paragraph", blocks.RichTextBlock()), @@ -500,7 +500,7 @@ class WhatsAppTemplateCategory(models.TextChoices): choices=WhatsAppTemplateCategory.choices, default=WhatsAppTemplateCategory.UTILITY, ) - whatsapp_title = models.CharField(max_length=200, blank=True, null=True) + whatsapp_title = models.CharField(max_length=200, blank=True, default="") whatsapp_body = StreamField( [ ( @@ -575,7 +575,7 @@ class WhatsAppTemplateCategory(models.TextChoices): ] # messenger page setup - messenger_title = models.CharField(max_length=200, blank=True, null=True) + messenger_title = models.CharField(max_length=200, blank=True, default="") messenger_body = StreamField( [ ( @@ -604,7 +604,7 @@ class WhatsAppTemplateCategory(models.TextChoices): ] # viber page setup - viber_title = models.CharField(max_length=200, blank=True, null=True) + viber_title = models.CharField(max_length=200, blank=True, default="") viber_body = StreamField( [ ( @@ -1092,7 +1092,6 @@ class PageView(models.Model): ("MESSENGER", "messenger"), ("WEB", "web"), ], - null=True, blank=True, default="web", max_length=20, diff --git a/home/tests/test_api.py b/home/tests/test_api.py index d603fd84..4278b906 100644 --- a/home/tests/test_api.py +++ b/home/tests/test_api.py @@ -264,7 +264,7 @@ def test_detail_view_content(self, uclient): assert content == { "id": page2.id, "title": "self-help", - "subtitle": None, + "subtitle": "", "body": {"text": []}, "whatsapp_template_example_values": [], "tags": ["self_help"], @@ -311,7 +311,7 @@ def test_detail_view_with_children(self, uclient): assert content == { "id": page1.id, "title": "main menu first time user", - "subtitle": None, + "subtitle": "", "body": {"text": []}, "whatsapp_template_example_values": [], "tags": ["menu"], diff --git a/home/tests/test_page_builder.py b/home/tests/test_page_builder.py index 830c236b..f9a34173 100644 --- a/home/tests/test_page_builder.py +++ b/home/tests/test_page_builder.py @@ -116,7 +116,7 @@ def test_build_simple_pages() -> None: assert ha_menu.seo_title == "" assert ha_menu.show_in_menus is False assert ha_menu.slug == "ha-menu" - assert ha_menu.subtitle is None + assert ha_menu.subtitle == "" assert list(ha_menu.tags.values()) == [] assert ha_menu.title == "HealthAlert menu" assert isinstance(ha_menu.translation_key, UUID) @@ -188,24 +188,24 @@ def test_build_web_content() -> None: assert ha_menu.live_revision == ha_menu.latest_revision assert ha_menu.locale == Locale.objects.get(language_code="en") assert unwagtail(ha_menu.messenger_body) == [] - assert ha_menu.messenger_title is None + assert ha_menu.messenger_title == "" assert ha_menu.numchild == 0 assert unwagtail(ha_menu.related_pages) == [] assert ha_menu.search_description == "" assert ha_menu.seo_title == "" assert ha_menu.show_in_menus is False assert ha_menu.slug == "ha-menu" - assert ha_menu.subtitle is None + assert ha_menu.subtitle == "" assert list(ha_menu.tags.values()) == [] assert ha_menu.title == "HealthAlert menu" assert isinstance(ha_menu.translation_key, UUID) assert ha_menu.url_path == "/home/main-menu/ha-menu/" assert unwagtail(ha_menu.viber_body) == [] - assert ha_menu.viber_title is None + assert ha_menu.viber_title == "" assert unwagtail(ha_menu.whatsapp_body) == [] assert ha_menu.whatsapp_template_category == "UTILITY" assert ha_menu.whatsapp_template_name == "" - assert ha_menu.whatsapp_title is None + assert ha_menu.whatsapp_title == "" @pytest.mark.django_db @@ -297,19 +297,19 @@ def test_build_variations() -> None: assert cp_imp_exp.live_revision == cp_imp_exp.latest_revision assert cp_imp_exp.locale == Locale.objects.get(language_code="en") assert unwagtail(cp_imp_exp.messenger_body) == [] - assert cp_imp_exp.messenger_title is None + assert cp_imp_exp.messenger_title == "" assert cp_imp_exp.numchild == 0 assert unwagtail(cp_imp_exp.related_pages) == [] assert cp_imp_exp.search_description == "" assert cp_imp_exp.seo_title == "" assert cp_imp_exp.show_in_menus is False assert cp_imp_exp.slug == "cp-import-export" - assert cp_imp_exp.subtitle is None + assert cp_imp_exp.subtitle == "" assert cp_imp_exp.title == "CP-Import/export" assert isinstance(cp_imp_exp.translation_key, UUID) assert cp_imp_exp.url_path == "/home/import-export/cp-import-export/" assert unwagtail(cp_imp_exp.viber_body) == [] - assert cp_imp_exp.viber_title is None + assert cp_imp_exp.viber_title == "" assert unwagtail(cp_imp_exp.whatsapp_body) == [ ( "Whatsapp_Message",