mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-11 02:23:19 -04:00
Merge pull request #1364 from alphagov/letter-job-page-real
Customise the job page to make sense for letters
This commit is contained in:
+36
-11
@@ -40,6 +40,7 @@ from app.utils import (
|
|||||||
FAILURE_STATUSES,
|
FAILURE_STATUSES,
|
||||||
SENDING_STATUSES,
|
SENDING_STATUSES,
|
||||||
DELIVERED_STATUSES,
|
DELIVERED_STATUSES,
|
||||||
|
get_letter_timings,
|
||||||
)
|
)
|
||||||
from app.statistics_utils import add_rate_to_job
|
from app.statistics_utils import add_rate_to_job
|
||||||
|
|
||||||
@@ -109,6 +110,13 @@ def view_job(service_id, job_id):
|
|||||||
|
|
||||||
total_notifications = job.get('notification_count', 0)
|
total_notifications = job.get('notification_count', 0)
|
||||||
processed_notifications = job.get('notifications_delivered', 0) + job.get('notifications_failed', 0)
|
processed_notifications = job.get('notifications_delivered', 0) + job.get('notifications_failed', 0)
|
||||||
|
|
||||||
|
template = service_api_client.get_service_template(
|
||||||
|
service_id=service_id,
|
||||||
|
template_id=job['template'],
|
||||||
|
version=job['template_version']
|
||||||
|
)['data']
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
'views/jobs/job.html',
|
'views/jobs/job.html',
|
||||||
finished=(total_notifications == processed_notifications),
|
finished=(total_notifications == processed_notifications),
|
||||||
@@ -121,7 +129,11 @@ def view_job(service_id, job_id):
|
|||||||
job_id=job['id'],
|
job_id=job['id'],
|
||||||
status=request.args.get('status', ''),
|
status=request.args.get('status', ''),
|
||||||
),
|
),
|
||||||
partials=get_job_partials(job),
|
partials=get_job_partials(job, template),
|
||||||
|
just_sent=bool(
|
||||||
|
request.args.get('just_sent') == 'yes' and
|
||||||
|
template['template_type'] == 'letter'
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -170,8 +182,16 @@ def cancel_job(service_id, job_id):
|
|||||||
@main.route("/services/<service_id>/jobs/<job_id>.json")
|
@main.route("/services/<service_id>/jobs/<job_id>.json")
|
||||||
@user_has_permissions('view_activity', admin_override=True)
|
@user_has_permissions('view_activity', admin_override=True)
|
||||||
def view_job_updates(service_id, job_id):
|
def view_job_updates(service_id, job_id):
|
||||||
|
|
||||||
|
job = job_api_client.get_job(service_id, job_id)['data']
|
||||||
|
|
||||||
return jsonify(**get_job_partials(
|
return jsonify(**get_job_partials(
|
||||||
job_api_client.get_job(service_id, job_id)['data']
|
job,
|
||||||
|
service_api_client.get_service_template(
|
||||||
|
service_id=current_service['id'],
|
||||||
|
template_id=job['template'],
|
||||||
|
version=job['template_version']
|
||||||
|
)['data'],
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
||||||
@@ -342,23 +362,28 @@ def _get_job_counts(job):
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def get_job_partials(job):
|
def get_job_partials(job, template):
|
||||||
filter_args = _parse_filter_args(request.args)
|
filter_args = _parse_filter_args(request.args)
|
||||||
filter_args['status'] = _set_status_filters(filter_args)
|
filter_args['status'] = _set_status_filters(filter_args)
|
||||||
notifications = notification_api_client.get_notifications_for_service(
|
notifications = notification_api_client.get_notifications_for_service(
|
||||||
job['service'], job['id'], status=filter_args['status']
|
job['service'], job['id'], status=filter_args['status']
|
||||||
)
|
)
|
||||||
template = service_api_client.get_service_template(
|
|
||||||
service_id=current_service['id'],
|
if template['template_type'] == 'letter':
|
||||||
template_id=job['template'],
|
counts = render_template(
|
||||||
version=job['template_version']
|
'partials/jobs/count-letters.html',
|
||||||
)['data']
|
total=job.get('notification_count', 0),
|
||||||
return {
|
delivery_estimate=get_letter_timings(job['created_at']).earliest_delivery,
|
||||||
'counts': render_template(
|
)
|
||||||
|
else:
|
||||||
|
counts = render_template(
|
||||||
'partials/count.html',
|
'partials/count.html',
|
||||||
counts=_get_job_counts(job),
|
counts=_get_job_counts(job),
|
||||||
status=filter_args['status']
|
status=filter_args['status']
|
||||||
),
|
)
|
||||||
|
|
||||||
|
return {
|
||||||
|
'counts': counts,
|
||||||
'notifications': render_template(
|
'notifications': render_template(
|
||||||
'partials/jobs/notifications.html',
|
'partials/jobs/notifications.html',
|
||||||
notifications=list(
|
notifications=list(
|
||||||
|
|||||||
@@ -513,7 +513,13 @@ def start_job(service_id, upload_id):
|
|||||||
)
|
)
|
||||||
|
|
||||||
return redirect(
|
return redirect(
|
||||||
url_for('main.view_job', job_id=upload_id, service_id=service_id, help=request.form.get('help'))
|
url_for(
|
||||||
|
'main.view_job',
|
||||||
|
job_id=upload_id,
|
||||||
|
service_id=service_id,
|
||||||
|
help=request.form.get('help'),
|
||||||
|
just_sent='yes',
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -119,25 +119,29 @@
|
|||||||
|
|
||||||
|
|
||||||
{% macro notification_status_field(notification) %}
|
{% macro notification_status_field(notification) %}
|
||||||
{% call field(status=notification.status|format_notification_status_as_field_status, align='right') %}
|
{% if not notification %}
|
||||||
{% if notification.status in ['created', 'sending', 'delivered'] %}<span class="align-with-message-body">{% endif %}
|
{% call field(align='right') %}{% endcall %}
|
||||||
{% if notification.status|format_notification_status_as_url %}
|
{% else %}
|
||||||
<a href="{{ notification.status|format_notification_status_as_url }}">
|
{% call field(status=notification.status|format_notification_status_as_field_status, align='right') %}
|
||||||
{% endif %}
|
{% if notification.status in ['created', 'sending', 'delivered'] %}<span class="align-with-message-body">{% endif %}
|
||||||
{{ notification.status|format_notification_status(
|
{% if notification.status|format_notification_status_as_url %}
|
||||||
notification.template.template_type
|
<a href="{{ notification.status|format_notification_status_as_url }}">
|
||||||
) }}
|
{% endif %}
|
||||||
{% if notification.status|format_notification_status_as_url %}
|
{{ notification.status|format_notification_status(
|
||||||
</a>
|
notification.template.template_type
|
||||||
{% endif %}
|
|
||||||
<span class="status-hint">
|
|
||||||
{{ notification.status|format_notification_status_as_time(
|
|
||||||
notification.created_at|format_datetime_short,
|
|
||||||
(notification.updated_at or notification.created_at)|format_datetime_short
|
|
||||||
) }}
|
) }}
|
||||||
</span>
|
{% if notification.status|format_notification_status_as_url %}
|
||||||
{% if notification.status in ['created', 'sending', 'delivered'] %}</span>{% endif %}
|
</a>
|
||||||
{% endcall %}
|
{% endif %}
|
||||||
|
<span class="status-hint">
|
||||||
|
{{ notification.status|format_notification_status_as_time(
|
||||||
|
notification.created_at|format_datetime_short,
|
||||||
|
(notification.updated_at or notification.created_at)|format_datetime_short
|
||||||
|
) }}
|
||||||
|
</span>
|
||||||
|
{% if notification.status in ['created', 'sending', 'delivered'] %}</span>{% endif %}
|
||||||
|
{% endcall %}
|
||||||
|
{% endif %}
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
{% from 'components/big-number.html' import big_number %}
|
||||||
|
{% from 'components/message-count-label.html' import message_count_label %}
|
||||||
|
|
||||||
|
<div class="grid-row bottom-gutter-2-3">
|
||||||
|
<div class="column-half">
|
||||||
|
<div class="keyline-block">
|
||||||
|
{{ big_number(
|
||||||
|
total,
|
||||||
|
message_count_label(total, 'letter', suffix='')|capitalize,
|
||||||
|
smaller=True
|
||||||
|
)}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="column-half">
|
||||||
|
<div class="keyline-block">
|
||||||
|
{{ big_number(
|
||||||
|
delivery_estimate|string|format_date_short,
|
||||||
|
'Estimated delivery date',
|
||||||
|
smaller=True
|
||||||
|
)}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -24,16 +24,18 @@
|
|||||||
<div class="dashboard-table bottom-gutter-3-2">
|
<div class="dashboard-table bottom-gutter-3-2">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if percentage_complete < 100 %}
|
{% if template.template_type != 'letter' %}
|
||||||
<p class="bottom-gutter hint">
|
{% if percentage_complete < 100 %}
|
||||||
Report is {{ "{:.0f}%".format(percentage_complete * 0.99) }} complete…
|
<p class="bottom-gutter hint">
|
||||||
</p>
|
Report is {{ "{:.0f}%".format(percentage_complete * 0.99) }} complete…
|
||||||
{% elif notifications %}
|
</p>
|
||||||
<p class="bottom-gutter">
|
{% elif notifications %}
|
||||||
<a href="{{ download_link }}" download="download" class="heading-small">Download this report</a>
|
<p class="bottom-gutter">
|
||||||
 
|
<a href="{{ download_link }}" download="download" class="heading-small">Download this report</a>
|
||||||
<span id="time-left">{{ time_left }}</span>
|
 
|
||||||
</p>
|
<span id="time-left">{{ time_left }}</span>
|
||||||
|
</p>
|
||||||
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% call(item, row_number) list_table(
|
{% call(item, row_number) list_table(
|
||||||
@@ -53,7 +55,9 @@
|
|||||||
{{ item.preview_of_content }}
|
{{ item.preview_of_content }}
|
||||||
</p>
|
</p>
|
||||||
{% endcall %}
|
{% endcall %}
|
||||||
{{ notification_status_field(item) }}
|
{{ notification_status_field(
|
||||||
|
'' if template.template_type == 'letter' else item
|
||||||
|
) }}
|
||||||
{% endcall %}
|
{% endcall %}
|
||||||
|
|
||||||
{% if more_than_one_page %}
|
{% if more_than_one_page %}
|
||||||
|
|||||||
@@ -13,7 +13,11 @@
|
|||||||
{{ uploaded_file_name }}
|
{{ uploaded_file_name }}
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
{{ ajax_block(partials, updates_url, 'status', finished=finished) }}
|
{% if just_sent %}
|
||||||
|
{{ banner('We’ve started printing your letters', type='default', with_tick=True) }}
|
||||||
|
{% else %}
|
||||||
|
{{ ajax_block(partials, updates_url, 'status', finished=finished) }}
|
||||||
|
{% endif %}
|
||||||
{{ ajax_block(partials, updates_url, 'counts', finished=finished) }}
|
{{ ajax_block(partials, updates_url, 'counts', finished=finished) }}
|
||||||
{{ ajax_block(partials, updates_url, 'notifications', finished=finished) }}
|
{{ ajax_block(partials, updates_url, 'notifications', finished=finished) }}
|
||||||
|
|
||||||
|
|||||||
@@ -158,6 +158,77 @@ def test_should_show_job_in_progress(
|
|||||||
assert page.find('p', {'class': 'hint'}).text.strip() == 'Report is 50% complete…'
|
assert page.find('p', {'class': 'hint'}).text.strip() == 'Report is 50% complete…'
|
||||||
|
|
||||||
|
|
||||||
|
@freeze_time("2016-01-01 11:09:00.061258")
|
||||||
|
def test_should_show_letter_job(
|
||||||
|
client_request,
|
||||||
|
mock_get_service_letter_template,
|
||||||
|
mock_get_job,
|
||||||
|
mock_get_notifications,
|
||||||
|
fake_uuid,
|
||||||
|
):
|
||||||
|
|
||||||
|
page = client_request.get(
|
||||||
|
'main.view_job',
|
||||||
|
service_id=SERVICE_ONE_ID,
|
||||||
|
job_id=fake_uuid,
|
||||||
|
)
|
||||||
|
|
||||||
|
assert normalize_spaces(page.h1.text) == 'thisisatest.csv'
|
||||||
|
assert normalize_spaces(page.select('p.bottom-gutter')[0].text) == (
|
||||||
|
'Sent by Test User on 1 January at 11:09am'
|
||||||
|
)
|
||||||
|
assert page.select('.banner-default-with-tick') == []
|
||||||
|
assert normalize_spaces(page.select('tbody tr')[0].text) == (
|
||||||
|
'07123456789 template content'
|
||||||
|
)
|
||||||
|
assert normalize_spaces(page.select('.keyline-block')[0].text) == (
|
||||||
|
'1 Letter'
|
||||||
|
)
|
||||||
|
assert normalize_spaces(page.select('.keyline-block')[1].text) == (
|
||||||
|
'6 January Estimated delivery date'
|
||||||
|
)
|
||||||
|
assert page.select('[download=download]') == []
|
||||||
|
assert page.select('.hint') == []
|
||||||
|
|
||||||
|
mock_get_notifications.assert_called_with(
|
||||||
|
SERVICE_ONE_ID,
|
||||||
|
fake_uuid,
|
||||||
|
status=[
|
||||||
|
'created',
|
||||||
|
'pending',
|
||||||
|
'sending',
|
||||||
|
'delivered',
|
||||||
|
'sent',
|
||||||
|
'failed',
|
||||||
|
'temporary-failure',
|
||||||
|
'permanent-failure',
|
||||||
|
'technical-failure',
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@freeze_time("2016-01-01 11:09:00.061258")
|
||||||
|
def test_should_show_letter_job_with_banner_after_sending(
|
||||||
|
client_request,
|
||||||
|
mock_get_service_letter_template,
|
||||||
|
mock_get_job,
|
||||||
|
mock_get_notifications,
|
||||||
|
fake_uuid,
|
||||||
|
):
|
||||||
|
|
||||||
|
page = client_request.get(
|
||||||
|
'main.view_job',
|
||||||
|
service_id=SERVICE_ONE_ID,
|
||||||
|
job_id=fake_uuid,
|
||||||
|
just_sent='yes',
|
||||||
|
)
|
||||||
|
|
||||||
|
assert page.select('p.bottom-gutter') == []
|
||||||
|
assert normalize_spaces(page.select('.banner-default-with-tick')[0].text) == (
|
||||||
|
'We’ve started printing your letters'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@freeze_time("2016-01-01T00:00:00.061258")
|
@freeze_time("2016-01-01T00:00:00.061258")
|
||||||
def test_should_show_scheduled_job(
|
def test_should_show_scheduled_job(
|
||||||
logged_in_client,
|
logged_in_client,
|
||||||
|
|||||||
@@ -1170,6 +1170,7 @@ def test_can_start_letters_job(
|
|||||||
data={}
|
data={}
|
||||||
)
|
)
|
||||||
assert response.status_code == 302
|
assert response.status_code == 302
|
||||||
|
assert 'just_sent=yes' in response.location
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('filetype', ['pdf', 'png'])
|
@pytest.mark.parametrize('filetype', ['pdf', 'png'])
|
||||||
|
|||||||
+3
-2
@@ -374,7 +374,7 @@ def mock_get_service_email_template_without_placeholders(mocker):
|
|||||||
|
|
||||||
@pytest.fixture(scope='function')
|
@pytest.fixture(scope='function')
|
||||||
def mock_get_service_letter_template(mocker, content=None, subject=None):
|
def mock_get_service_letter_template(mocker, content=None, subject=None):
|
||||||
def _create(service_id, template_id):
|
def _get(service_id, template_id, version=None):
|
||||||
template = template_json(
|
template = template_json(
|
||||||
service_id,
|
service_id,
|
||||||
template_id,
|
template_id,
|
||||||
@@ -386,7 +386,8 @@ def mock_get_service_letter_template(mocker, content=None, subject=None):
|
|||||||
return {'data': template}
|
return {'data': template}
|
||||||
|
|
||||||
return mocker.patch(
|
return mocker.patch(
|
||||||
'app.service_api_client.get_service_template', side_effect=_create)
|
'app.service_api_client.get_service_template', side_effect=_get
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='function')
|
@pytest.fixture(scope='function')
|
||||||
|
|||||||
Reference in New Issue
Block a user