Add property to construct account type string

This allows us to start decoupling the form fields from the final,
hyphenated string, which we'll do in the next commits.

Note that I've also removed the conditional that changes the data
of the network field as part of validating it. We shouldn't change
data in validations, and having the new property directly above
makes it clear there's no need for this code.
This commit is contained in:
Ben Thorner
2021-06-07 16:38:58 +01:00
parent e848643361
commit 5ce76b8b33
2 changed files with 10 additions and 3 deletions

View File

@@ -2430,11 +2430,18 @@ class ServiceBroadcastNetworkForm(StripWhitespaceForm):
thing='a mobile network',
)
@property
def account_type(self):
if self.network_variant.data == f'live-{self.broadcast_channel}-all':
provider = 'all'
else:
provider = self.network.provider_restriction
return f'live-{self.broadcast_channel}-{provider}'
def validate_network(self, field):
if not self.network_variant.data and not field.data:
raise ValidationError('Select a mobile network')
if self.network_variant.data == 'all':
field.data = ''
class ServiceBroadcastAccountTypeForm(StripWhitespaceForm):