mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-05-03 23:51:22 -04:00
Move code for rendering messages/templates → utils
Utils is better structured to handle the logic of what thing to show for what template type, especially now that what we show for different template types in different contexts has diverged significantly. See https://github.com/alphagov/notifications-utils/commit/6b39c1a for an example of this code moving into utils Depends on and implements: https://github.com/alphagov/notifications-utils/pull/84 The main reason for doing this is to get Paul’s fix for the misaligned CSV columns: https://github.com/alphagov/notifications-utils/pull/87
This commit is contained in:
19
app/utils.py
19
app/utils.py
@@ -8,6 +8,8 @@ import unicodedata
|
||||
from flask import (abort, current_app, session, request, redirect, url_for)
|
||||
from flask_login import current_user
|
||||
|
||||
from notifications_utils.renderers import SMSPreview, EmailPreview, LetterPreview
|
||||
|
||||
import pyexcel
|
||||
import pyexcel.ext.io
|
||||
import pyexcel.ext.xls
|
||||
@@ -216,3 +218,20 @@ def is_gov_user(email_address):
|
||||
valid_domains = current_app.config['EMAIL_DOMAIN_REGEXES']
|
||||
email_regex = (r"[\.|@]({})$".format("|".join(valid_domains)))
|
||||
return bool(re.search(email_regex, email_address.lower()))
|
||||
|
||||
|
||||
def get_renderer(template_type, service, show_recipient, expand_emails=False):
|
||||
return {
|
||||
'email': EmailPreview(
|
||||
from_name=service['name'],
|
||||
from_address='{}@notifications.service.gov.uk'.format(service['email_from']),
|
||||
expanded=expand_emails,
|
||||
show_recipient=show_recipient
|
||||
),
|
||||
'sms': SMSPreview(
|
||||
prefix=service['name'],
|
||||
sender=service['sms_sender'],
|
||||
show_recipient=show_recipient
|
||||
),
|
||||
'letter': LetterPreview(),
|
||||
}[template_type]
|
||||
|
||||
Reference in New Issue
Block a user