diff --git a/app/main/views/templates.py b/app/main/views/templates.py index 6c7f8a9dc..5b2a8d5d2 100644 --- a/app/main/views/templates.py +++ b/app/main/views/templates.py @@ -57,6 +57,7 @@ TemplateList, TemplateLists, ) +from app.notify_client.notification_counts_client import notification_counts_client from app.template_previews import TemplatePreview, get_page_count_for_letter from app.utils import ( email_or_sms_not_enabled, @@ -134,6 +135,26 @@ def view_template(service_id, template_id): user_has_template_permission = current_user.has_template_folder_permission(template_folder) + # get the limit stats for the current service + limit_stats = notification_counts_client.get_limit_stats(current_service) + + # transform the stats into a format that can be used in the template + notification_type = template["template_type"] + dailyLimit = limit_stats[notification_type]["daily"]["limit"] + dailyUsed = limit_stats[notification_type]["daily"]["sent"] + dailyRemaining = limit_stats[notification_type]["daily"]["remaining"] + yearlyLimit = limit_stats[notification_type]["annual"]["limit"] + yearlyUsed = limit_stats[notification_type]["annual"]["sent"] + yearlyRemaining = limit_stats[notification_type]["annual"]["remaining"] + + # determine ready to send heading + if yearlyRemaining == 0: + heading = _("Sending paused until annual limit resets") + elif dailyRemaining == 0: + heading = _('Sending paused until 7pm ET. You can schedule more messages to send later.') + else: + heading = _("Ready to send?") + if should_skip_template_page(template["template_type"]): return redirect(url_for(".send_one_off", service_id=service_id, template_id=template_id)) @@ -142,6 +163,14 @@ def view_template(service_id, template_id): template=get_email_preview_template(template, template_id, service_id), template_postage=template["postage"], user_has_template_permission=user_has_template_permission, + dailyLimit=dailyLimit, + dailyUsed=dailyUsed, + yearlyLimit=yearlyLimit, + yearlyUsed=yearlyUsed, + notification_type=notification_type, + dailyRemaining=dailyRemaining, + yearlyRemaining=yearlyRemaining, + heading=heading, ) diff --git a/app/templates/views/templates/_template.html b/app/templates/views/templates/_template.html index 86c19a127..9bb95d511 100644 --- a/app/templates/views/templates/_template.html +++ b/app/templates/views/templates/_template.html @@ -1,4 +1,13 @@ {% from 'components/message-count-label.html' import message_count_label %} +{% from 'components/remaining-messages-summary.html' import remaining_messages_summary with context %} + + +