Allow adding broadcast templates

At the moment the page is the same as for text message templates,
except:
- different H1
- no guidance about personalisation, links, etc (until we decide how
  these should work)

For now you won’t be able to really create a broadcast template, because
the API doesn’t support it (the API will respond with a 400). But that’s
OK because no real services have the broadcast permission yet.

This required a bit of refactoring of how we check which template types
a service can use, because there were some hard-coded assumptions about
emails and text messages.
This commit is contained in:
Chris Hill-Scott
2020-07-01 16:43:08 +01:00
parent 8a1d86633c
commit 154d4bdb85
11 changed files with 175 additions and 77 deletions

View File

@@ -780,6 +780,10 @@ class SMSTemplateForm(BaseTemplateForm):
OnlySMSCharacters()(None, field)
class BroadcastTemplateForm(SMSTemplateForm):
pass
class LetterAddressForm(StripWhitespaceForm):
def __init__(self, *args, allow_international_letters=False, **kwargs):
@@ -1644,7 +1648,7 @@ class TemplateAndFoldersSelectionForm(Form):
self,
all_template_folders,
template_list,
allow_adding_letter_template,
available_template_types,
allow_adding_copy_of_template,
*args,
**kwargs
@@ -1652,6 +1656,8 @@ class TemplateAndFoldersSelectionForm(Form):
super().__init__(*args, **kwargs)
self.available_template_types = available_template_types
self.templates_and_folders.choices = template_list.as_id_and_name
self.op = None
@@ -1664,12 +1670,25 @@ class TemplateAndFoldersSelectionForm(Form):
]
self.add_template_by_template_type.choices = list(filter(None, [
# We want to show email and text message to everyone,
# whether or not the service has them switched on. The
# option to add letter or broadcast templates should only
# be shown to services which have that permission
('email', 'Email'),
('sms', 'Text message'),
('letter', 'Letter') if allow_adding_letter_template else None,
('letter', 'Letter') if 'letter' in available_template_types else None,
('broadcast', 'Broadcast') if 'broadcast' in available_template_types else None,
('copy-existing', 'Copy an existing template') if allow_adding_copy_of_template else None,
]))
@property
def trying_to_add_unavailable_template_type(self):
return all((
self.is_add_template_op,
self.add_template_by_template_type.data,
self.add_template_by_template_type.data not in self.available_template_types,
))
def is_selected(self, template_folder_id):
return template_folder_id in (self.templates_and_folders.data or [])