-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UPRN error handling now has propper user feedback for UPRN input
- Loading branch information
Showing
5 changed files
with
50 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
""" Validation for user inputs when it isn't handled by submitting to the API and dealing with the error """ | ||
|
||
|
||
def validate_uprn(uprn): | ||
""" Check if a UPRN complies with valid format """ | ||
# Raise exception with title 'Limit Parameter Error' and description 'Limit parameter must be a positive integer' | ||
|
||
basic_message = 'UPRN must be numeric. They can have up to 12 digits and have no leading zeros.' | ||
additional_message = '' | ||
if not uprn.isdigit(): | ||
if uprn != '': | ||
additional_message = additional_message + '<br> The UPRN you entered is not numeric.' | ||
else: | ||
additional_message = additional_message + '<br> The UPRN you entered is blank.' | ||
|
||
# Check not longer than 12 | ||
if len(uprn) > 12: | ||
additional_message = additional_message + '<br> The UPRN you entered is longer than 12.' | ||
|
||
# Check for leading zeros | ||
if str(uprn).startswith('0'): | ||
additional_message = additional_message + '<br> The UPRN you entered has leading zeros.' | ||
|
||
if additional_message != '': | ||
raise Exception('UPRN Parameter Error', | ||
f'{basic_message} {additional_message}') |