Merge pull request #3416 from alphagov/validate-3-lines-csv

Allow all the new address goodness in spreadsheets
This commit is contained in:
Chris Hill-Scott
2020-05-01 15:37:08 +01:00
committed by GitHub
11 changed files with 281 additions and 43 deletions

View File

@@ -781,6 +781,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")]
@@ -788,7 +792,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(
@@ -800,7 +807,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'
)