Allow international addresses in spreadsheets

For services with permission, they can now put international addresses
into their spreadsheets without getting a postcode error.

This also means they can start using address line 7 instead of postcode,
since it doesn’t make sense to put a country in a field called
‘postcode’. But this will be undocumented to start with, because we’re
not giving any real users the permission.

It does now mean that the number of possible placeholders (7 + postcode)
is greater than the number of allowed placeholders (7), so we have to
account for that in the one-off address flow where we’re populating the
placeholders automatically. We’re sticking with 6 + postcode here for
backwards compatibility.
This commit is contained in:
Chris Hill-Scott
2020-04-27 10:57:25 +01:00
parent 832445774b
commit 06108de0f7
9 changed files with 197 additions and 30 deletions

View File

@@ -754,6 +754,10 @@ class SMSTemplateForm(BaseTemplateForm):
class LetterAddressForm(StripWhitespaceForm):
def __init__(self, *args, allow_international_letters=False, **kwargs):
self.allow_international_letters = allow_international_letters
super().__init__(*args, **kwargs)
address = PostalAddressField(
'Address',
validators=[DataRequired(message="Cannot be empty")]
@@ -761,7 +765,10 @@ class LetterAddressForm(StripWhitespaceForm):
def validate_address(self, field):
address = PostalAddress(field.data)
address = PostalAddress(
field.data,
allow_international_letters=self.allow_international_letters,
)
if not address.has_enough_lines:
raise ValidationError(
@@ -773,7 +780,11 @@ class LetterAddressForm(StripWhitespaceForm):
f'Address must be no more than {PostalAddress.MAX_LINES} lines long'
)
if not address.postcode:
if not address.has_valid_last_line:
if self.allow_international_letters:
raise ValidationError(
f'Last line of the address must be a UK postcode or another country'
)
raise ValidationError(
f'Last line of the address must be a real UK postcode'
)