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

Changes nullable fields to non-nullable and adding migrations #237

Merged
merged 3 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
190 changes: 190 additions & 0 deletions home/migrations/0046_alter_contentpage_whatsapp_body.py
Original file line number Diff line number Diff line change
@@ -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,
),
),
]
79 changes: 79 additions & 0 deletions home/migrations/0047_alter_contentpage_messenger_title_and_more.py
Original file line number Diff line number Diff line change
@@ -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,
),
),
]
15 changes: 7 additions & 8 deletions home/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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()),
Expand Down Expand Up @@ -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(
[
(
Expand Down Expand Up @@ -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(
[
(
Expand Down Expand Up @@ -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(
[
(
Expand Down Expand Up @@ -1092,7 +1092,6 @@ class PageView(models.Model):
("MESSENGER", "messenger"),
("WEB", "web"),
],
null=True,
blank=True,
default="web",
max_length=20,
Expand Down
4 changes: 2 additions & 2 deletions home/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down Expand Up @@ -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"],
Expand Down
Loading