Skip to content
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
34 changes: 20 additions & 14 deletions ietf/secr/announcement/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,25 +146,31 @@ def __init__(self, *args, **kwargs):
for key in list(self.fields.keys()):
self.fields[key].widget = forms.HiddenInput()

def clean_cc(self):
cc_data = self.cleaned_data["cc"]
cc = [addr.strip() for addr in cc_data.split(",") if addr.strip()]
errors = [
forms.ValidationError(
"Invalid address: %(addr)s", "invalid_cc", {"addr": addr}
)
for addr in cc
if not is_valid_email(addr)
]
if errors:
raise forms.ValidationError(errors)
return cc_data

def clean(self):
super(AnnounceForm, self).clean()
data = self.cleaned_data
if self.errors:
return self.cleaned_data
if data["to"] == "Other..." and not data["to_custom"]:
raise forms.ValidationError('You must enter a "To" email address')
if data["to"] == "Other..." and data["to_custom"]:
addrlist = data["to_custom"]
else:
addrlist = [data["to"]]
if data["cc"]:
cc = [email.strip() for email in data["cc"].split(",") if email.strip()]
addrlist.extend(cc)
emails = [email.strip() for email in addrlist if email.strip()]
for email in emails:
if not is_valid_email(email):
raise forms.ValidationError("An exception occurred while trying to send email to '%s'" % email)


if data.get("to") == "Other..." and data.get("to_custom", []) == []:
self.add_error(
None, forms.ValidationError('Must specify a "To" address', "empty_to")
)

for k in [
"to",
"frm",
Expand Down
5 changes: 3 additions & 2 deletions ietf/secr/announcement/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ def test_valid_submit(self):
self.assertRedirects(response, url)
self.assertEqual(len(outbox), 1)
self.assertEqual(outbox[0]["subject"], "Test Subject")
self.assertEqual(outbox[0]["to"], "<phil@example.com>, <lizz@example.com>, <no-brackets@example.com>")
self.assertEqual(outbox[0]["to"], "<phil@example.com>")
self.assertEqual(outbox[0]["cc"], "lizz@example.com, no-brackets@example.com")
message = Message.objects.filter(by__user__username="secretary").last()
self.assertEqual(message.subject, "Test Subject")
self.assertTrue(nomcom in message.related_groups.all())
Expand Down Expand Up @@ -186,4 +187,4 @@ def test_invalid_submit(self):
self.assertNotContains(response, "Confirm Announcement")
self.assertEqual(len(outbox), 0)



Loading