Template statistics now surfaced on dashboard.

Job list removed.

Template statistics retrieved at same time as
notification stats.
This commit is contained in:
Adam Shimali
2016-04-05 11:40:13 +01:00
parent ff3dd857ec
commit 159fe60c1a
12 changed files with 158 additions and 24 deletions

View File

@@ -29,6 +29,8 @@ from app.notify_client.notification_api_client import NotificationApiClient
from app.notify_client.status_api_client import StatusApiClient
from app.notify_client.invite_api_client import InviteApiClient
from app.notify_client.statistics_api_client import StatisticsApiClient
from app.notify_client.template_statistics_api_client import TemplateStatisticsApiClient
from app.its_dangerous_session import ItsdangerousSessionInterface
from app.asset_fingerprinter import AssetFingerprinter
from utils.recipients import validate_phone_number, InvalidPhoneError
@@ -51,6 +53,7 @@ notification_api_client = NotificationApiClient()
status_api_client = StatusApiClient()
invite_api_client = InviteApiClient()
statistics_api_client = StatisticsApiClient()
template_statistics_client = TemplateStatisticsApiClient()
asset_fingerprinter = AssetFingerprinter()
# The current service attached to the request stack.
@@ -74,6 +77,7 @@ def create_app():
status_api_client.init_app(application)
invite_api_client.init_app(application)
statistics_api_client.init_app(application)
template_statistics_client.init_app(application)
login_manager.init_app(application)
login_manager.login_view = 'main.sign_in'
@@ -95,6 +99,7 @@ def create_app():
application.add_template_filter(syntax_highlight_json)
application.add_template_filter(valid_phone_number)
application.add_template_filter(linkable_name)
application.add_template_filter(format_date)
application.after_request(useful_headers_after_request)
application.after_request(save_service_after_request)
@@ -175,6 +180,11 @@ def format_time(date):
return native.strftime('%H:%M')
def format_date(date):
date = dateutil.parser.parse(date)
return date.strftime('%A %d %B %Y')
def valid_phone_number(phone_number):
try:
validate_phone_number(phone_number)

View File

@@ -1,15 +1,23 @@
from datetime import date
from flask import (
render_template,
session,
flash,
jsonify,
request
jsonify
)
from datetime import date
from flask_login import login_required
from app.main import main
from app import (job_api_client, statistics_api_client, service_api_client, current_service)
from app import (
job_api_client,
statistics_api_client,
service_api_client,
template_statistics_client,
current_service
)
from app.utils import user_has_permissions
@@ -27,6 +35,7 @@ def service_dashboard(service_id):
flash(message, 'default_with_tick')
statistics = statistics_api_client.get_statistics_for_service(service_id)['data']
template_statistics = template_statistics_client.get_template_statistics_for_service(service_id)
return render_template(
'views/dashboard/dashboard.html',
@@ -36,7 +45,8 @@ def service_dashboard(service_id):
spent_this_month='0.00',
statistics=add_rates_to(statistics),
templates=templates,
service_id=str(service_id))
service_id=str(service_id),
template_statistics=template_statistics)
@main.route("/services/<service_id>/dashboard.json")
@@ -44,11 +54,13 @@ def service_dashboard(service_id):
def service_dashboard_updates(service_id):
statistics = statistics_api_client.get_statistics_for_service(service_id)['data']
template_statistics = template_statistics_client.get_template_statistics_for_service(service_id)
return jsonify(**{
'today': render_template(
'views/dashboard/today.html',
statistics=add_rates_to(statistics),
template_statistics=template_statistics
)
})

View File

@@ -1,4 +1,4 @@
from flask import render_template, url_for, redirect
from flask import render_template, url_for, redirect, jsonify
from app.main import main
from flask_login import login_required

View File

@@ -0,0 +1,18 @@
from notifications_python_client.base import BaseAPIClient
class TemplateStatisticsApiClient(BaseAPIClient):
def __init__(self, base_url=None, client_id=None, secret=None):
super(self.__class__, self).__init__(base_url=base_url or 'base_url',
client_id=client_id or 'client_id',
secret=secret or 'secret')
def init_app(self, app):
self.base_url = app.config['API_HOST_NAME']
self.client_id = app.config['ADMIN_CLIENT_USER_NAME']
self.secret = app.config['ADMIN_CLIENT_SECRET']
def get_template_statistics_for_service(self, service_id):
return self.get(
url='/service/{}/template-statistics'.format(service_id),
)['data']

View File

@@ -5,7 +5,7 @@
{% endblock %}
{% block maincolumn_content %}
{% if not templates and current_user.has_permissions(['send_texts', 'send_emails', 'send_letters'], any_=True) %}
{% include 'views/dashboard/get-started.html' %}
{% elif current_service.restricted %}
@@ -22,8 +22,5 @@
>
{% include 'views/dashboard/today.html' %}
</div>
{% include 'views/dashboard/jobs.html' %}
{% endblock %}

View File

@@ -0,0 +1,23 @@
{% from "components/table.html" import list_table, field, right_aligned_field_heading %}
{% call(item) list_table(
template_statistics,
caption="Recent templates used",
empty_message='You havent sent any batch messages yet',
field_headings=['Template', 'Type','Date', right_aligned_field_heading('Usage')]
) %}
{% call field() %}
<a href="{{ url_for('.edit_service_template', service_id=service_id, template_id=item.template.id) }}">
{{ item.template.name }}
</a>
{% endcall %}
{% call field() %}
{{item.template.template_type}}
{% endcall %}
{% call field() %}
{{ item.day|format_date }}
{% endcall %}
{% call field(align='right') %}
{{ item.usage_count }}
{% endcall %}
{% endcall %}

View File

@@ -0,0 +1,23 @@
{% from "components/table.html" import list_table, field, right_aligned_field_heading %}
{% call(item) list_table(
template_statistics,
caption="Recent templates used",
empty_message='You havent sent any batch messages yet',
field_headings=['Template', 'Type','Date', right_aligned_field_heading('Usage')]
) %}
{% call field() %}
<a href="{{ url_for('.edit_service_template', service_id=service_id, template_id=item.template.id) }}">
{{ item.template.name }}
</a>
{% endcall %}
{% call field() %}
{{item.template.template_type}}
{% endcall %}
{% call field() %}
{{ item.day|format_date }}
{% endcall %}
{% call field(align='right') %}
{{ item.usage_count }}
{% endcall %}
{% endcall %}

View File

@@ -23,3 +23,6 @@
) }}
</div>
</div>
{% include 'views/dashboard/template-statistics.html' %}