Show monthly usage by SMS provider on Providers page

This adds a '% monthly traffic' column to the SMS table on the Providers page
to let us see how much traffic is being sent to each SMS provider.
This commit is contained in:
Katie Smith
2019-05-07 08:30:34 +01:00
parent a7d8918ee0
commit a74da6d14e
3 changed files with 57 additions and 10 deletions
+13
View File
@@ -22,6 +22,8 @@ def view_providers():
elif provider['notification_type'] == 'email':
domestic_email_providers.append(provider)
add_monthly_traffic(domestic_sms_providers)
return render_template(
'views/providers/providers.html',
email_providers=domestic_email_providers,
@@ -30,6 +32,17 @@ def view_providers():
)
def add_monthly_traffic(domestic_sms_providers):
total_sms_sent = sum(provider.get('current_month_billable_sms', 0) for provider in domestic_sms_providers)
for provider in domestic_sms_providers:
if provider.get('current_month_billable_sms'):
percentage = (provider['current_month_billable_sms'] / total_sms_sent * 100) if total_sms_sent else 0
provider['monthly_traffic'] = round(percentage)
else:
provider['monthly_traffic'] = 0
@main.route("/provider/<provider_id>/edit", methods=['GET', 'POST'])
@login_required
@user_is_platform_admin
+3 -1
View File
@@ -17,7 +17,7 @@ Providers
caption="Domestic SMS providers",
caption_visible=False,
empty_message='No domestic sms providers',
field_headings=['Provider', 'Priority', 'Active', 'Last Updated', 'Updated By'],
field_headings=['Provider', 'Priority', '% monthly traffic', 'Active', 'Last Updated', 'Updated By'],
field_headings_visible=True
) %}
@@ -25,6 +25,8 @@ Providers
{{ text_field(item.priority) }}
{{ text_field(item.monthly_traffic) }}
{{ text_field(item.active) }}
{% if item.updated_at %}