From f85ee3dd0acf147a8d8046950a513e879cb3d468 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Mon, 11 Oct 2021 14:15:25 +0100 Subject: [PATCH] Move go live ticket content to a Jinja template Jinja is a better language for doing complex templating. And we can use the global Jinja scope to automatically get access to things like `current_user` and our formatters. --- app/main/views/service_settings.py | 36 +----------------------------- app/templates/go-live-request.txt | 18 +++++++++++++++ 2 files changed, 19 insertions(+), 35 deletions(-) create mode 100644 app/templates/go-live-request.txt diff --git a/app/main/views/service_settings.py b/app/main/views/service_settings.py index 4527bec3d..64bb51aa7 100644 --- a/app/main/views/service_settings.py +++ b/app/main/views/service_settings.py @@ -23,7 +23,6 @@ from app import ( billing_api_client, current_service, email_branding_client, - format_thousands, inbound_number_client, letter_branding_client, notification_api_client, @@ -210,40 +209,7 @@ def request_to_go_live(service_id): @user_has_permissions('manage_service') @user_is_gov_user def submit_request_to_go_live(service_id): - ticket_message = ( - 'Service: {service_name}\n' - '{service_dashboard}\n' - '\n---' - '\nOrganisation type: {organisation_type}' - '\nAgreement signed: {agreement}' - '\n' - '\nEmails in next year: {volume_email_formatted}' - '\nText messages in next year: {volume_sms_formatted}' - '\nLetters in next year: {volume_letter_formatted}' - '\n' - '\nConsent to research: {research_consent}' - '\nOther live services for that user: {existing_live}' - '\n' - '\nService reply-to address: {email_reply_to}' - '\n' - '\n---' - '\nRequest sent by {email_address}' - '\n' - ).format( - service_name=current_service.name, - service_dashboard=url_for('main.service_dashboard', service_id=current_service.id, _external=True), - organisation_type=current_service.organisation_type_label, - agreement=current_service.organisation.as_agreement_statement_for_go_live_request( - current_user.email_domain - ), - volume_email_formatted=format_thousands(current_service.volume_email), - volume_sms_formatted=format_thousands(current_service.volume_sms), - volume_letter_formatted=format_thousands(current_service.volume_letter), - research_consent='Yes' if current_service.consent_to_research else 'No', - existing_live='Yes' if current_user.live_services else 'No', - email_address=current_user.email_address, - email_reply_to=current_service.default_email_reply_to_address or 'not set', - ) + ticket_message = render_template('go-live-request.txt') + '\n' ticket = NotifySupportTicket( subject=f'Request to go live - {current_service.name}', diff --git a/app/templates/go-live-request.txt b/app/templates/go-live-request.txt new file mode 100644 index 000000000..65122635e --- /dev/null +++ b/app/templates/go-live-request.txt @@ -0,0 +1,18 @@ +Service: {{ current_service.name }} +{{ url_for('main.service_dashboard', service_id=current_service.id, _external=True) }} + +--- +Organisation type: {{ current_service.organisation_type_label }} +Agreement signed: {{ current_service.organisation.as_agreement_statement_for_go_live_request(current_user.email_domain) }} + +Emails in next year: {{ current_service.volume_email|format_thousands }} +Text messages in next year: {{ current_service.volume_sms|format_thousands }} +Letters in next year: {{ current_service.volume_letter|format_thousands }} + +Consent to research: {{ "Yes" if current_service.consent_to_research else "No" }} +Other live services for that user: {{ "Yes" if current_user.live_services else "No" }} + +Service reply-to address: {{ current_service.default_email_reply_to_address or "not set" }} + +--- +Request sent by {{ current_user.email_address }}