2017-07-26 15:57:30 +01:00
|
|
|
from app import create_random_identifier
|
2017-09-26 09:56:09 +01:00
|
|
|
from app.models import LETTER_TYPE
|
2017-07-26 15:57:30 +01:00
|
|
|
from app.notifications.process_notifications import persist_notification
|
|
|
|
|
|
|
|
|
|
|
2017-09-26 09:56:09 +01:00
|
|
|
def create_letter_notification(letter_data, template, api_key, status):
|
2017-07-26 15:57:30 +01:00
|
|
|
notification = persist_notification(
|
2017-09-20 11:12:37 +01:00
|
|
|
template_id=template.id,
|
|
|
|
|
template_version=template.version,
|
2017-07-27 11:10:22 +01:00
|
|
|
# we only accept addresses_with_underscores from the API (from CSV we also accept dashes, spaces etc)
|
|
|
|
|
recipient=letter_data['personalisation']['address_line_1'],
|
2017-09-26 09:56:09 +01:00
|
|
|
service=template.service,
|
2017-07-26 15:57:30 +01:00
|
|
|
personalisation=letter_data['personalisation'],
|
|
|
|
|
notification_type=LETTER_TYPE,
|
|
|
|
|
api_key_id=api_key.id,
|
|
|
|
|
key_type=api_key.key_type,
|
2017-09-20 11:12:37 +01:00
|
|
|
job_id=None,
|
|
|
|
|
job_row_number=None,
|
2017-07-26 15:57:30 +01:00
|
|
|
reference=create_random_identifier(),
|
2017-09-26 09:56:09 +01:00
|
|
|
client_reference=letter_data.get('reference'),
|
|
|
|
|
status=status
|
2017-07-26 15:57:30 +01:00
|
|
|
)
|
|
|
|
|
return notification
|