mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-31 23:26:23 -05:00
Refactor postcode validation to use utils
We don’t need to reformat the postcode here once template preview takes care of it when rendering the PDF. It’s better (and less code) to store what people give us, so we give them back the same thing.
This commit is contained in:
@@ -3,10 +3,7 @@ from datetime import datetime
|
||||
from collections import namedtuple, defaultdict
|
||||
|
||||
from flask import current_app
|
||||
from notifications_utils.recipients import (
|
||||
format_postcode_for_printing,
|
||||
RecipientCSV
|
||||
)
|
||||
from notifications_utils.recipients import RecipientCSV
|
||||
from notifications_utils.statsd_decorators import statsd
|
||||
from notifications_utils.timezones import convert_utc_to_bst
|
||||
from requests import (
|
||||
@@ -346,10 +343,6 @@ def save_letter(
|
||||
# we store the recipient as just the first item of the person's address
|
||||
recipient = notification['personalisation']['addressline1']
|
||||
|
||||
notification['personalisation']['postcode'] = format_postcode_for_printing(
|
||||
notification['personalisation']['postcode']
|
||||
)
|
||||
|
||||
service = dao_fetch_service_by_id(service_id)
|
||||
template = dao_get_template_by_id(notification['template'], version=notification['template_version'])
|
||||
|
||||
|
||||
@@ -5,9 +5,8 @@ from datetime import datetime
|
||||
|
||||
from boto.exception import SQSError
|
||||
from flask import request, jsonify, current_app, abort
|
||||
from notifications_utils.recipients import (
|
||||
format_postcode_for_printing, is_a_real_uk_postcode, try_validate_and_format_phone_number
|
||||
)
|
||||
from notifications_utils.postal_address import PostalAddress
|
||||
from notifications_utils.recipients import try_validate_and_format_phone_number
|
||||
from notifications_utils.template import WithSubjectTemplate
|
||||
|
||||
from app import (
|
||||
@@ -349,8 +348,7 @@ def process_letter_notification(*, letter_data, api_key, template, reply_to_text
|
||||
template=template,
|
||||
reply_to_text=reply_to_text)
|
||||
|
||||
postcode = letter_data['personalisation']['postcode']
|
||||
if not is_a_real_uk_postcode(postcode):
|
||||
if not PostalAddress.from_personalisation(letter_data['personalisation']).postcode:
|
||||
raise ValidationError(message='Must be a real UK postcode')
|
||||
|
||||
test_key = api_key.key_type == KEY_TYPE_TEST
|
||||
@@ -359,8 +357,6 @@ def process_letter_notification(*, letter_data, api_key, template, reply_to_text
|
||||
status = NOTIFICATION_CREATED if not test_key else NOTIFICATION_SENDING
|
||||
queue = QueueNames.CREATE_LETTERS_PDF if not test_key else QueueNames.RESEARCH_MODE
|
||||
|
||||
letter_data['personalisation']['postcode'] = format_postcode_for_printing(postcode)
|
||||
|
||||
notification = create_letter_notification(letter_data=letter_data,
|
||||
template=template,
|
||||
api_key=api_key,
|
||||
|
||||
Reference in New Issue
Block a user