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

Fix updating scheduled broadcasts #5358

Merged
merged 1 commit into from
Jul 5, 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
36 changes: 11 additions & 25 deletions temba/msgs/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1976,7 +1976,6 @@ def setUp(self):

def _form_data(
self,
org,
Copy link
Member Author

Choose a reason for hiding this comment

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

unrelated - just noticed this isn't used

*,
translations,
contacts=(),
Expand Down Expand Up @@ -2066,15 +2065,15 @@ def test_create(self, mr_mocks):
response = self.process_wizard(
"create",
create_url,
self._form_data(self.org, translations={"und": {"text": ""}}, contacts=[self.joe]),
self._form_data(translations={"und": {"text": ""}}, contacts=[self.joe]),
)
self.assertFormError(response.context["form"], "compose", ["This field is required."])

# text too long
response = self.process_wizard(
"create",
create_url,
self._form_data(self.org, translations={"eng": {"text": "." * 641}}, contacts=[self.joe]),
self._form_data(translations={"eng": {"text": "." * 641}}, contacts=[self.joe]),
)
self.assertFormError(response.context["form"], "compose", ["Maximum allowed text is 640 characters."])

Expand All @@ -2083,21 +2082,17 @@ def test_create(self, mr_mocks):
response = self.process_wizard(
"create",
create_url,
self._form_data(
self.org, translations={"eng": {"text": text, "attachments": attachments * 11}}, contacts=[self.joe]
),
self._form_data(translations={"eng": {"text": text, "attachments": attachments * 11}}, contacts=[self.joe]),
)
self.assertFormError(response.context["form"], "compose", ["Maximum allowed attachments is 10 files."])

# empty recipients
response = self.process_wizard(
"create", create_url, self._form_data(self.org, translations={"eng": {"text": text}})
)
response = self.process_wizard("create", create_url, self._form_data(translations={"eng": {"text": text}}))
self.assertFormError(response.context["form"], "contact_search", ["Contacts or groups are required."])

# empty query
response = self.process_wizard(
"create", create_url, self._form_data(self.org, advanced=True, translations={"eng": {"text": text}})
"create", create_url, self._form_data(advanced=True, translations={"eng": {"text": text}})
)
self.assertFormError(response.context["form"], "contact_search", ["A contact query is required."])

Expand All @@ -2106,15 +2101,15 @@ def test_create(self, mr_mocks):
response = self.process_wizard(
"create",
create_url,
self._form_data(self.org, advanced=True, translations={"eng": {"text": text}}, query="invalid"),
self._form_data(advanced=True, translations={"eng": {"text": text}}, query="invalid"),
)
self.assertFormError(response.context["form"], "contact_search", ["Invalid query syntax."])

# missing start time
response = self.process_wizard(
"create",
create_url,
self._form_data(self.org, translations={"eng": {"text": text}}, contacts=[self.joe]),
self._form_data(translations={"eng": {"text": text}}, contacts=[self.joe]),
)
self.assertFormError(response.context["form"], None, ["Select when you would like the broadcast to be sent"])

Expand All @@ -2123,7 +2118,6 @@ def test_create(self, mr_mocks):
"create",
create_url,
self._form_data(
self.org,
translations={"eng": {"text": text}},
contacts=[self.joe],
start_datetime="2021-06-24 12:00Z",
Expand All @@ -2142,11 +2136,10 @@ def test_create(self, mr_mocks):
"create",
create_url,
self._form_data(
self.org,
translations={"eng": {"text": text}},
contacts=[self.joe],
optin=optin,
start_datetime="2021-06-24 12:00",
start_datetime="2021-06-24 12:00Z",
repeat_period="W",
repeat_days_of_week=["M", "F"],
),
Expand All @@ -2163,7 +2156,6 @@ def test_create(self, mr_mocks):
"create",
create_url,
self._form_data(
self.org,
translations={"eng": {"text": text}},
contacts=[self.joe],
send_when=ScheduleForm.SEND_NOW,
Expand Down Expand Up @@ -2217,7 +2209,6 @@ def test_update(self):
"update",
update_url,
self._form_data(
self.org,
translations=updated_text,
template=translation.template,
variables=["", "World"],
Expand All @@ -2238,7 +2229,6 @@ def test_update(self):
"update",
update_url,
self._form_data(
self.org,
translations=updated_text,
template=translation.template,
variables=["image/jpeg:http://domain/meow.jpg", "World"],
Expand All @@ -2256,7 +2246,6 @@ def test_update(self):
"update",
update_url,
self._form_data(
self.org,
translations={language: {"text": "Updated broadcast"}},
contacts=[self.joe],
optin=optin,
Expand All @@ -2279,7 +2268,6 @@ def test_update(self):
"update",
update_url,
self._form_data(
self.org,
translations=updated_text,
contacts=[self.joe],
start_datetime="2021-06-24 12:00",
Expand All @@ -2298,7 +2286,6 @@ def test_update(self):
"update",
update_url,
self._form_data(
self.org,
translations=updated_text,
contacts=[self.joe],
),
Expand Down Expand Up @@ -2329,7 +2316,7 @@ def get_languages(response):
response = self.process_wizard(
"update",
update_url,
self._form_data(self.org, translations={}, contacts=[self.joe]),
self._form_data(translations={}, contacts=[self.joe]),
)

# we only have a base language and don't have values for org languages, it should be first
Expand All @@ -2341,7 +2328,6 @@ def get_languages(response):
"update",
update_url,
self._form_data(
self.org,
translations={"und": {"text": "undefined"}, "eng": {"text": "hello"}, "esp": {"text": "hola"}},
contacts=[self.joe],
start_datetime="2021-06-24 12:00",
Expand All @@ -2354,7 +2340,7 @@ def get_languages(response):
response = self.process_wizard(
"update",
update_url,
self._form_data(self.org, translations={}, contacts=[self.joe]),
self._form_data(translations={}, contacts=[self.joe]),
)

# We have a primary language, it should be first
Expand All @@ -2372,7 +2358,7 @@ def get_languages(response):
response = self.process_wizard(
"update",
update_url,
self._form_data(self.org, translations={}, contacts=[self.joe]),
self._form_data(translations={}, contacts=[self.joe]),
)
languages = get_languages(response)
self.assertEqual("esp", languages[0]["iso"])
Expand Down
8 changes: 6 additions & 2 deletions temba/msgs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,17 @@ class ScheduleForm(ScheduleFormMixin):

def __init__(self, org, *args, **kwargs):
super().__init__(*args, **kwargs)

self.fields["start_datetime"].required = False
self.set_org(org)

def clean(self):
start_datetime = self.data.get("schedule-start_datetime", None)
if self.data["schedule-send_when"] == ScheduleForm.SEND_LATER and not start_datetime:
send_when = self.data.get("schedule-send_when", ScheduleForm.SEND_LATER) # doesn't exist for updates
start_datetime = self.data.get("schedule-start_datetime")

if send_when == ScheduleForm.SEND_LATER and not start_datetime:
raise forms.ValidationError(_("Select when you would like the broadcast to be sent"))

Copy link
Member Author

Choose a reason for hiding this comment

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

the normal way to clean a form is start with cleaned_data = super().clean() but that doesn't work here.. maybe cuz it's a mixin? Anyways need to get this fix out...

return super().clean()

class Meta:
Expand Down
Loading