From 2ab23fa4ef6051577fa302a9dc6c9a617955afc0 Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Thu, 28 Jul 2016 16:23:22 +0100 Subject: [PATCH 01/44] move weekly summary page over to new notifications/weekly endpoint --- app/main/views/dashboard.py | 35 ++++++++++++++-------- app/notify_client/statistics_api_client.py | 12 ++------ app/templates/views/weekly.html | 8 ++--- 3 files changed, 28 insertions(+), 27 deletions(-) diff --git a/app/main/views/dashboard.py b/app/main/views/dashboard.py index 74072aa2b..c4958ae49 100644 --- a/app/main/views/dashboard.py +++ b/app/main/views/dashboard.py @@ -2,6 +2,7 @@ from datetime import datetime, date, timedelta from collections import namedtuple from itertools import groupby +import dateutil from flask import ( render_template, url_for, @@ -9,7 +10,6 @@ from flask import ( jsonify, current_app ) - from flask_login import login_required from app.main import main @@ -90,20 +90,10 @@ def usage(service_id): @login_required @user_has_permissions('manage_settings', admin_override=True) def weekly(service_id): - - earliest_date = date(2016, 4, 1) # start of tax year - while earliest_date.weekday() != 0: # 0 for monday - earliest_date -= timedelta(days=1) - + stats = statistics_api_client.get_weekly_notification_stats(service_id)['data'] return render_template( 'views/weekly.html', - days=( - add_rates_to(day) for day in - statistics_api_client.get_7_day_aggregate_for_service( - service_id, - date_from=earliest_date - )['data'] - ), + days=format_stats_to_list(stats), now=datetime.utcnow() ) @@ -199,3 +189,22 @@ def calculate_usage(usage): 'sms_chargeable': max(0, sms_sent - sms_free_allowance), 'sms_rate': sms_rate } + + +def format_stats_to_list(historical_stats): + out = [] + for week, weekly_stats in historical_stats.items(): + for stats in weekly_stats.values(): + stats['failure_rate'] = get_formatted_percentage(stats['failed'], stats['requested']) + + week_start = dateutil.parser.parse(week) + week_end = week_start + timedelta(days=6) + item = { + 'week_start': week_start.isoformat(), + 'week_end': week_end.isoformat(), + 'week_end_datetime': week_end, + } + item.update(weekly_stats) + out.append(item) + + return sorted(out, key=lambda x: x['week_start'], reverse=True) diff --git a/app/notify_client/statistics_api_client.py b/app/notify_client/statistics_api_client.py index cc3fdc480..47f5b89e4 100644 --- a/app/notify_client/statistics_api_client.py +++ b/app/notify_client/statistics_api_client.py @@ -23,16 +23,8 @@ class StatisticsApiClient(BaseAPIClient): else: raise e - def get_7_day_aggregate_for_service(self, service_id, date_from=None, week_count=None): - params = {} - if date_from is not None: - params['date_from'] = date_from - if week_count is not None: - params['week_count'] = week_count - return self.get( - url='/service/{}/notifications-statistics/seven_day_aggregate'.format(service_id), - params=params - ) + def get_weekly_notification_stats(self, service_id): + return self.get(url='/service/{}/notifications/weekly'.format(service_id)) def get_statistics_for_all_services_for_day(self, day): params = { diff --git a/app/templates/views/weekly.html b/app/templates/views/weekly.html index 10a516290..4e413203c 100644 --- a/app/templates/views/weekly.html +++ b/app/templates/views/weekly.html @@ -33,16 +33,16 @@ {% endif %} {% endcall %} {% call field(align='right') %} - {{ item.emails_requested }} + {{ item.email.requested }} {% endcall %} {% call field(align='right') %} - {{ item.emails_failure_rate }}% + {{ item.email.failure_rate }}% {% endcall %} {% call field(align='right') %} - {{ item.sms_requested }} + {{ item.sms.requested }} {% endcall %} {% call field(align='right') %} - {{ item.sms_failure_rate }}% + {{ item.sms.failure_rate }}% {% endcall %} {% endcall %} From a7c8e88ecb0f088be49a9082c4e0b93b2ad32e80 Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Thu, 28 Jul 2016 18:09:17 +0100 Subject: [PATCH 02/44] add tests and remove old aggregate code --- app/main/views/dashboard.py | 17 +++++---- tests/app/main/views/test_dashboard.py | 50 +++++++++++++++++++++++--- tests/conftest.py | 9 ----- 3 files changed, 53 insertions(+), 23 deletions(-) diff --git a/app/main/views/dashboard.py b/app/main/views/dashboard.py index c4958ae49..29c2232be 100644 --- a/app/main/views/dashboard.py +++ b/app/main/views/dashboard.py @@ -1,4 +1,4 @@ -from datetime import datetime, date, timedelta +from datetime import datetime, timedelta from collections import namedtuple from itertools import groupby @@ -93,7 +93,7 @@ def weekly(service_id): stats = statistics_api_client.get_weekly_notification_stats(service_id)['data'] return render_template( 'views/weekly.html', - days=format_stats_to_list(stats), + days=format_weekly_stats_to_list(stats), now=datetime.utcnow() ) @@ -191,7 +191,7 @@ def calculate_usage(usage): } -def format_stats_to_list(historical_stats): +def format_weekly_stats_to_list(historical_stats): out = [] for week, weekly_stats in historical_stats.items(): for stats in weekly_stats.values(): @@ -199,12 +199,11 @@ def format_stats_to_list(historical_stats): week_start = dateutil.parser.parse(week) week_end = week_start + timedelta(days=6) - item = { - 'week_start': week_start.isoformat(), - 'week_end': week_end.isoformat(), + weekly_stats.update({ + 'week_start': week, + 'week_end': week_end.date().isoformat(), 'week_end_datetime': week_end, - } - item.update(weekly_stats) - out.append(item) + }) + out.append(weekly_stats) return sorted(out, key=lambda x: x['week_start'], reverse=True) diff --git a/tests/app/main/views/test_dashboard.py b/tests/app/main/views/test_dashboard.py index dc5a35d80..b1cc51ccb 100644 --- a/tests/app/main/views/test_dashboard.py +++ b/tests/app/main/views/test_dashboard.py @@ -1,3 +1,4 @@ +from datetime import datetime import copy from flask import url_for @@ -5,7 +6,7 @@ import pytest from bs4 import BeautifulSoup from freezegun import freeze_time -from app.main.views.dashboard import get_dashboard_totals +from app.main.views.dashboard import get_dashboard_totals, format_weekly_stats_to_list from tests import validate_route_permission from tests.conftest import SERVICE_ONE_ID @@ -65,7 +66,6 @@ def test_get_started( api_user_active, mock_get_service, mock_get_service_templates_when_no_templates_exist, - mock_get_aggregate_service_statistics, mock_get_user, mock_get_user_by_email, mock_login, @@ -94,7 +94,6 @@ def test_get_started_is_hidden_once_templates_exist( api_user_active, mock_get_service, mock_get_service_templates, - mock_get_aggregate_service_statistics, mock_get_user, mock_get_user_by_email, mock_login, @@ -119,7 +118,6 @@ def test_should_show_recent_templates_on_dashboard(app_, api_user_active, mock_get_service, mock_get_service_templates, - mock_get_aggregate_service_statistics, mock_get_user, mock_get_user_by_email, mock_login, @@ -204,7 +202,6 @@ def test_should_show_recent_jobs_on_dashboard( api_user_active, mock_get_service, mock_get_service_templates, - mock_get_aggregate_service_statistics, mock_get_user, mock_get_user_by_email, mock_login, @@ -482,3 +479,46 @@ def test_get_dashboard_totals_adds_warning(failures, expected): } } assert get_dashboard_totals(stats)['sms']['show_warning'] == expected + + +def test_format_weekly_stats_to_list_empty_case(): + assert format_weekly_stats_to_list({}) == [] + + +def test_format_weekly_stats_to_list_sorts_by_week(): + stats = { + '2016-07-04': {}, + '2016-07-11': {}, + '2016-07-18': {}, + '2016-07-25': {} + } + resp = format_weekly_stats_to_list(stats) + assert resp[0]['week_start'] == '2016-07-25' + assert resp[1]['week_start'] == '2016-07-18' + assert resp[2]['week_start'] == '2016-07-11' + assert resp[3]['week_start'] == '2016-07-04' + + +def test_format_weekly_stats_to_list_includes_datetime_for_comparison(): + stats = { + '2016-07-25': {} + } + resp = format_weekly_stats_to_list(stats) + assert resp == [{ + 'week_start': '2016-07-25', + 'week_end': '2016-07-31', + 'week_end_datetime': datetime(2016, 7, 31, 0, 0, 0) + }] + + +def test_format_weekly_stats_to_list_has_stats_with_failure_rate(): + stats = { + '2016-07-25': {'sms': _stats(3, 1, 2)} + } + resp = format_weekly_stats_to_list(stats) + assert resp[0]['sms']['failure_rate'] == '66.7' + assert resp[0]['sms']['requested'] == 3 + + +def _stats(requested, delivered, failed): + return {'requested': requested, 'delivered': delivered, 'failed': failed} diff --git a/tests/conftest.py b/tests/conftest.py index 2ace067a9..cbdfc37d0 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -220,15 +220,6 @@ def mock_get_service_statistics_for_day(mocker): 'app.statistics_api_client.get_statistics_for_service_for_day', side_effect=_stats) -@pytest.fixture(scope='function') -def mock_get_aggregate_service_statistics(mocker): - def _create(service_id, limit_days=None): - return {'data': [{}]} - - return mocker.patch( - 'app.statistics_api_client.get_7_day_aggregate_for_service', side_effect=_create) - - @pytest.fixture(scope='function') def mock_get_all_service_statistics(mocker): def _create(day): From fe84674a7764c97470881283bc03a817d68916ef Mon Sep 17 00:00:00 2001 From: Martyn Inglis Date: Mon, 4 Jul 2016 17:21:08 +0100 Subject: [PATCH 03/44] Updated start scripts to not look up envrionemnt --- config.py | 17 +++++++++++++++-- config_live.py | 17 ----------------- config_staging.py | 16 ---------------- scripts/aws_change_ownership.sh | 4 ++-- scripts/aws_install_dependencies.sh | 4 ++-- wsgi.py | 12 ------------ 6 files changed, 19 insertions(+), 51 deletions(-) delete mode 100644 config_live.py delete mode 100644 config_staging.py diff --git a/config.py b/config.py index 37df9d749..2a6a220bb 100644 --- a/config.py +++ b/config.py @@ -78,10 +78,23 @@ class Preview(Config): CSV_UPLOAD_BUCKET_NAME = 'preview-notifications-csv-upload' +class Staging(Config): + SHOW_STYLEGUIDE = False + HTTP_PROTOCOL = 'https' + HEADER_COLOUR = '#F47738' # $orange + + +class Live(Config): + SHOW_STYLEGUIDE = False + HEADER_COLOUR = '#B10E1E' # $red + HTTP_PROTOCOL = 'https' + HEADER_COLOUR = '#B10E1E' # $red + + configs = { 'development': 'config.Development', 'test': 'config.Test', 'preview': 'config.Preview', - 'staging': 'config_staging.Staging', - 'live': 'config_live.Live' + 'staging': 'config.Staging', + 'live': 'config.Live' } diff --git a/config_live.py b/config_live.py deleted file mode 100644 index e01535e00..000000000 --- a/config_live.py +++ /dev/null @@ -1,17 +0,0 @@ -import os -from config import Config - - -class Live(Config): - SHOW_STYLEGUIDE = False - HEADER_COLOUR = '#B10E1E' # $red - HTTP_PROTOCOL = 'https' - API_HOST_NAME = os.environ['LIVE_API_HOST_NAME'] - ADMIN_CLIENT_SECRET = os.environ['LIVE_ADMIN_CLIENT_SECRET'] - SECRET_KEY = os.environ['LIVE_SECRET_KEY'] - DANGEROUS_SALT = os.environ['LIVE_DANGEROUS_SALT'] - CSV_UPLOAD_BUCKET_NAME = 'live-notifications-csv-upload' - DESKPRO_API_KEY = os.environ['LIVE_DESKPRO_API_KEY'] - DESKPRO_DEPT_ID = os.environ['LIVE_DESKPRO_DEPT_ID'] - DESKPRO_ASSIGNED_AGENT_TEAM_ID = os.environ['LIVE_DESKPRO_ASSIGNED_AGENT_TEAM_ID'] - HEADER_COLOUR = '#B10E1E' # $red diff --git a/config_staging.py b/config_staging.py deleted file mode 100644 index 775a2d566..000000000 --- a/config_staging.py +++ /dev/null @@ -1,16 +0,0 @@ -import os -from config import Config - - -class Staging(Config): - SHOW_STYLEGUIDE = False - HTTP_PROTOCOL = 'https' - API_HOST_NAME = os.environ['STAGING_API_HOST_NAME'] - ADMIN_CLIENT_SECRET = os.environ['STAGING_ADMIN_CLIENT_SECRET'] - SECRET_KEY = os.environ['STAGING_SECRET_KEY'] - DANGEROUS_SALT = os.environ['STAGING_DANGEROUS_SALT'] - CSV_UPLOAD_BUCKET_NAME = 'staging-notifications-csv-upload' - DESKPRO_API_KEY = os.environ['STAGING_DESKPRO_API_KEY'] - DESKPRO_DEPT_ID = os.environ['STAGING_DESKPRO_DEPT_ID'] - DESKPRO_ASSIGNED_AGENT_TEAM_ID = os.environ['STAGING_DESKPRO_ASSIGNED_AGENT_TEAM_ID'] - HEADER_COLOUR = '#F47738' # $orange diff --git a/scripts/aws_change_ownership.sh b/scripts/aws_change_ownership.sh index a0622593f..e800956d3 100755 --- a/scripts/aws_change_ownership.sh +++ b/scripts/aws_change_ownership.sh @@ -1,5 +1,5 @@ #!/bin/bash echo "Chown application to be owned by ubuntu" -cd /home/ubuntu/; -chown -R ubuntu:ubuntu notifications-admin \ No newline at end of file +cd /home/notify-app/; +chown -R notify-app:govuk-notify-applications notifications-admin \ No newline at end of file diff --git a/scripts/aws_install_dependencies.sh b/scripts/aws_install_dependencies.sh index 474fee8a1..e5988d7b2 100755 --- a/scripts/aws_install_dependencies.sh +++ b/scripts/aws_install_dependencies.sh @@ -1,5 +1,5 @@ #!/bin/bash echo "Install dependencies" -cd /home/ubuntu/notifications-admin; -pip3 install -r /home/ubuntu/notifications-admin/requirements.txt \ No newline at end of file +cd /home/notify-app/notifications-admin; +pip3 install -r /home/notify-app/notifications-admin/requirements.txt \ No newline at end of file diff --git a/wsgi.py b/wsgi.py index 15ff05b38..db71cf075 100644 --- a/wsgi.py +++ b/wsgi.py @@ -1,21 +1,9 @@ from credstash import getAllSecrets import os -default_env_file = '/home/ubuntu/environment' -environment = 'live' - -if os.path.isfile(default_env_file): - with open(default_env_file, 'r') as environment_file: - environment = environment_file.readline().strip() - - # on aws get secrets and export to env os.environ.update(getAllSecrets(region="eu-west-1")) -from config import configs # noqa - -os.environ['NOTIFY_ADMIN_ENVIRONMENT'] = configs[environment] - from app import create_app # noqa application = create_app() From 4222027184084b6812bde54dc99c8d128967e762 Mon Sep 17 00:00:00 2001 From: Martyn Inglis Date: Tue, 5 Jul 2016 14:26:02 +0100 Subject: [PATCH 04/44] Updated config to be string based not class based and removed old style live/staging files. --- app/__init__.py | 7 ++++--- app/version.py | 6 +++--- appspec.yml | 2 +- config.py | 11 +++++------ 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index 71bccc12a..a73025f9c 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -13,8 +13,9 @@ from flask import ( current_app, request, g, - url_for -) + url_for) + +from config import configs from flask._compat import string_types from flask.globals import _lookup_req_object from flask_login import LoginManager @@ -69,7 +70,7 @@ current_service = LocalProxy(partial(_lookup_req_object, 'service')) def create_app(): application = Flask(__name__) - application.config.from_object(os.environ['NOTIFY_ADMIN_ENVIRONMENT']) + application.config.from_object(configs[os.environ['NOTIFY_ADMIN_ENVIRONMENT']]) init_app(application) logging.init_app(application) diff --git a/app/version.py b/app/version.py index 1defd614d..f868ea87c 100644 --- a/app/version.py +++ b/app/version.py @@ -1,3 +1,3 @@ -__travis_commit__ = "dev" -__time__ = "dev" -__travis_job_number__ = "dev" +__travis_commit__ = "" +__time__ = "2016-07-04:17:22:35" +__travis_job_number__ = "" diff --git a/appspec.yml b/appspec.yml index cb81bb36f..c663536ab 100644 --- a/appspec.yml +++ b/appspec.yml @@ -1,7 +1,7 @@ --- files: - - destination: /home/ubuntu/notifications-admin + destination: /home/notify-app/notifications-admin source: / hooks: AfterInstall: diff --git a/config.py b/config.py index 2a6a220bb..84b6d9d3b 100644 --- a/config.py +++ b/config.py @@ -3,7 +3,6 @@ from datetime import timedelta class Config(object): - DEBUG = False ADMIN_CLIENT_SECRET = os.environ['ADMIN_CLIENT_SECRET'] ADMIN_CLIENT_USER_NAME = os.environ['ADMIN_CLIENT_USER_NAME'] @@ -92,9 +91,9 @@ class Live(Config): configs = { - 'development': 'config.Development', - 'test': 'config.Test', - 'preview': 'config.Preview', - 'staging': 'config.Staging', - 'live': 'config.Live' + 'development': Development, + 'test': Test, + 'preview': Preview, + 'staging': Staging, + 'live': Live } From 37167473b3a3516bc1b30a7fffa26779b0965592 Mon Sep 17 00:00:00 2001 From: Martyn Inglis Date: Tue, 5 Jul 2016 15:38:05 +0100 Subject: [PATCH 05/44] New property for environment --- app/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/__init__.py b/app/__init__.py index a73025f9c..377a6da9d 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -70,7 +70,7 @@ current_service = LocalProxy(partial(_lookup_req_object, 'service')) def create_app(): application = Flask(__name__) - application.config.from_object(configs[os.environ['NOTIFY_ADMIN_ENVIRONMENT']]) + application.config.from_object(configs[os.environ['NOTIFY_ENVIRONMENT']]) init_app(application) logging.init_app(application) From 47b8955a9a458f1149b7165ccec6429dcf5f540f Mon Sep 17 00:00:00 2001 From: Martyn Inglis Date: Tue, 5 Jul 2016 16:43:05 +0100 Subject: [PATCH 06/44] Fix import order so that configs work --- app/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/__init__.py b/app/__init__.py index 377a6da9d..9463305c3 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -15,7 +15,6 @@ from flask import ( g, url_for) -from config import configs from flask._compat import string_types from flask.globals import _lookup_req_object from flask_login import LoginManager @@ -68,6 +67,8 @@ current_service = LocalProxy(partial(_lookup_req_object, 'service')) def create_app(): + from config import configs + application = Flask(__name__) application.config.from_object(configs[os.environ['NOTIFY_ENVIRONMENT']]) From d6be4dd5aadc990a11c4f7e0651878f4f7b43114 Mon Sep 17 00:00:00 2001 From: Martyn Inglis Date: Tue, 5 Jul 2016 17:00:29 +0100 Subject: [PATCH 07/44] Changed bucket name --- config.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config.py b/config.py index 84b6d9d3b..1819a76f0 100644 --- a/config.py +++ b/config.py @@ -81,13 +81,14 @@ class Staging(Config): SHOW_STYLEGUIDE = False HTTP_PROTOCOL = 'https' HEADER_COLOUR = '#F47738' # $orange + CSV_UPLOAD_BUCKET_NAME = 'staging-notify-csv-upload' class Live(Config): SHOW_STYLEGUIDE = False HEADER_COLOUR = '#B10E1E' # $red HTTP_PROTOCOL = 'https' - HEADER_COLOUR = '#B10E1E' # $red + CSV_UPLOAD_BUCKET_NAME = 'live-notifications-csv-upload' configs = { From 721ed7c6730df7621371a679ecaa9ef5fca32b31 Mon Sep 17 00:00:00 2001 From: Martyn Inglis Date: Tue, 5 Jul 2016 21:21:11 +0100 Subject: [PATCH 08/44] Fixed the test environment / run scripts --- app/version.py | 2 +- environment_test.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/version.py b/app/version.py index f868ea87c..fc30d1fca 100644 --- a/app/version.py +++ b/app/version.py @@ -1,3 +1,3 @@ __travis_commit__ = "" -__time__ = "2016-07-04:17:22:35" +__time__ = "2016-07-05:14:44:52" __travis_job_number__ = "" diff --git a/environment_test.sh b/environment_test.sh index 549aae5f5..a5b46e479 100644 --- a/environment_test.sh +++ b/environment_test.sh @@ -1,4 +1,4 @@ -export NOTIFY_ADMIN_ENVIRONMENT='config.Test' +export NOTIFY_ENVIRONMENT='test' export ADMIN_CLIENT_SECRET='dev-notify-secret-key' export ADMIN_CLIENT_USER_NAME='dev-notify-admin' export API_HOST_NAME='' From bf3bc1f2f7db52716b51bbad358fec320ffa83e8 Mon Sep 17 00:00:00 2001 From: Martyn Inglis Date: Wed, 6 Jul 2016 11:47:51 +0100 Subject: [PATCH 09/44] Increase ELB timeout --- scripts/common_functions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/common_functions.sh b/scripts/common_functions.sh index 469d22e6c..86b993c2f 100644 --- a/scripts/common_functions.sh +++ b/scripts/common_functions.sh @@ -101,7 +101,7 @@ reset_waiter_timeout() { fi # Base register/deregister action may take up to about 30 seconds - timeout=$((timeout + 30)) + timeout=$((timeout + 60)) WAITER_ATTEMPTS=$((timeout / WAITER_INTERVAL)) } From 19aca03aed21db4bd0df67d3a8e57106bd2ce159 Mon Sep 17 00:00:00 2001 From: Martyn Inglis Date: Fri, 8 Jul 2016 14:36:59 +0100 Subject: [PATCH 10/44] updated python in bootstrap file --- scripts/common_functions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/common_functions.sh b/scripts/common_functions.sh index 86b993c2f..09cdbe4e0 100644 --- a/scripts/common_functions.sh +++ b/scripts/common_functions.sh @@ -183,7 +183,7 @@ get_instance_health_elb() { ;; *) msg "Instance '$instance_id' not part of ELB '$elb_name'" - return 1 + return 0 esac fi } From 147069a626fae7f12344e4d0c30a9e6fdfe7ee1f Mon Sep 17 00:00:00 2001 From: Martyn Inglis Date: Mon, 11 Jul 2016 16:44:53 +0100 Subject: [PATCH 11/44] Removed unused dir change --- scripts/aws_start_app.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/aws_start_app.sh b/scripts/aws_start_app.sh index 1c3743f2c..b4082672a 100755 --- a/scripts/aws_start_app.sh +++ b/scripts/aws_start_app.sh @@ -1,5 +1,4 @@ #!/bin/bash echo "Starting application" -cd ~/notifications-admin/; sudo service notifications-admin start \ No newline at end of file From 4ea23a7484ad8c7f001e7fb9ac2b1ce42366c627 Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Fri, 29 Jul 2016 10:28:18 +0100 Subject: [PATCH 12/44] move away from statistics_api towards service_api --- app/main/views/dashboard.py | 3 +-- app/notify_client/service_api_client.py | 3 +++ app/notify_client/statistics_api_client.py | 3 --- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/main/views/dashboard.py b/app/main/views/dashboard.py index 29c2232be..67588672a 100644 --- a/app/main/views/dashboard.py +++ b/app/main/views/dashboard.py @@ -15,7 +15,6 @@ from flask_login import login_required from app.main import main from app import ( job_api_client, - statistics_api_client, service_api_client, template_statistics_client ) @@ -90,7 +89,7 @@ def usage(service_id): @login_required @user_has_permissions('manage_settings', admin_override=True) def weekly(service_id): - stats = statistics_api_client.get_weekly_notification_stats(service_id)['data'] + stats = service_api_client.get_weekly_notification_stats(service_id)['data'] return render_template( 'views/weekly.html', days=format_weekly_stats_to_list(stats), diff --git a/app/notify_client/service_api_client.py b/app/notify_client/service_api_client.py index f2896a49e..230c53b3e 100644 --- a/app/notify_client/service_api_client.py +++ b/app/notify_client/service_api_client.py @@ -193,6 +193,9 @@ class ServiceAPIClient(NotificationsAPIClient): def get_service_usage(self, service_id): return self.get('/service/{0}/fragment/aggregate_statistics'.format(service_id)) + def get_weekly_notification_stats(self, service_id): + return self.get(url='/service/{}/notifications/weekly'.format(service_id)) + class ServicesBrowsableItem(BrowsableItem): @property diff --git a/app/notify_client/statistics_api_client.py b/app/notify_client/statistics_api_client.py index 47f5b89e4..ba1a6c496 100644 --- a/app/notify_client/statistics_api_client.py +++ b/app/notify_client/statistics_api_client.py @@ -23,9 +23,6 @@ class StatisticsApiClient(BaseAPIClient): else: raise e - def get_weekly_notification_stats(self, service_id): - return self.get(url='/service/{}/notifications/weekly'.format(service_id)) - def get_statistics_for_all_services_for_day(self, day): params = { 'day': day From 30261cf385fea305b5e3c39d9215b9271b3e29ab Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Mon, 1 Aug 2016 14:25:28 +0100 Subject: [PATCH 13/44] Fix newlines in HTML emails This problem was masked because the email message component was also replacing newlines with `
`s. Implements: - [ ] https://github.com/alphagov/notifications-utils/pull/60 --- app/templates/components/email-message.html | 2 +- requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/templates/components/email-message.html b/app/templates/components/email-message.html index 6099d4341..9766c17d6 100644 --- a/app/templates/components/email-message.html +++ b/app/templates/components/email-message.html @@ -50,7 +50,7 @@ {% if not expanded %}
...show full email
diff --git a/requirements.txt b/requirements.txt index a1ce67cba..b04cc336c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,4 +19,4 @@ pytz==2016.4 git+https://github.com/alphagov/notifications-python-client.git@1.0.0#egg=notifications-python-client==1.0.0 -git+https://github.com/alphagov/notifications-utils.git@8.7.1#egg=notifications-utils==8.7.1 +git+https://github.com/alphagov/notifications-utils.git@8.7.2#egg=notifications-utils==8.7.2 From ee52e72f9094587988615ff428d02d50a3b9c867 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Fri, 1 Jul 2016 17:07:39 +0100 Subject: [PATCH 14/44] Move template guidance underneath MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two problems with having it on the side: - some users didn’t see it at all - there wasn’t space to have additional guidance about Markdown-style formatting --- .../templates/guidance-character-count.html | 20 ++++++-------- .../partials/templates/guidance-links.html | 12 +++------ .../templates/guidance-personalisation.html | 26 +++++++++---------- app/templates/views/edit-email-template.html | 3 +-- app/templates/views/edit-sms-template.html | 3 +-- 5 files changed, 26 insertions(+), 38 deletions(-) diff --git a/app/templates/partials/templates/guidance-character-count.html b/app/templates/partials/templates/guidance-character-count.html index b11dae62e..9dea399f4 100644 --- a/app/templates/partials/templates/guidance-character-count.html +++ b/app/templates/partials/templates/guidance-character-count.html @@ -1,12 +1,8 @@ -
- Message length -
-

- If your message is long then it will - cost more. -

-

- See pricing for details. -

-
-
+

Message length

+

+ If your message is long then it will + cost more. +

+

+ See pricing for details. +

diff --git a/app/templates/partials/templates/guidance-links.html b/app/templates/partials/templates/guidance-links.html index 2d7aab039..c53dcca4a 100644 --- a/app/templates/partials/templates/guidance-links.html +++ b/app/templates/partials/templates/guidance-links.html @@ -1,8 +1,4 @@ -
- Links and URLs -
-

- Always use full URLs, starting with https:// -

-
-
+

Links and URLs

+

+ Always use full URLs, starting with https:// +

diff --git a/app/templates/partials/templates/guidance-personalisation.html b/app/templates/partials/templates/guidance-personalisation.html index 3cae73723..0fa4f087a 100644 --- a/app/templates/partials/templates/guidance-personalisation.html +++ b/app/templates/partials/templates/guidance-personalisation.html @@ -1,14 +1,12 @@ -
- Personalisation -
-

- Use double brackets to add personalisation. -

-

- Correct: ((name)) -

-

- Incorrect: ((Helen)) -

-
-
+

+ Personalisation +

+

+ Use double brackets to add personalisation. +

+

+ Correct: ((name)) +

+

+ Incorrect: ((Helen)) +

diff --git a/app/templates/views/edit-email-template.html b/app/templates/views/edit-email-template.html index 1e3db961c..dd94b8962 100644 --- a/app/templates/views/edit-email-template.html +++ b/app/templates/views/edit-email-template.html @@ -26,8 +26,7 @@ delete_link_text='Delete this template' ) }} -