mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-09 06:53:11 -04:00
Put data from job on job page
The main change is showing the finished time if the job is finished, rather than the start time.
This commit is contained in:
@@ -73,6 +73,7 @@ def create_app(config_name, config_overrides=None):
|
|||||||
|
|
||||||
application.add_template_filter(nl2br)
|
application.add_template_filter(nl2br)
|
||||||
application.add_template_filter(format_datetime)
|
application.add_template_filter(format_datetime)
|
||||||
|
application.add_template_filter(format_time)
|
||||||
application.add_template_filter(syntax_highlight_json)
|
application.add_template_filter(syntax_highlight_json)
|
||||||
application.add_template_filter(valid_phone_number)
|
application.add_template_filter(valid_phone_number)
|
||||||
|
|
||||||
@@ -149,6 +150,12 @@ def format_datetime(date):
|
|||||||
return native.strftime('%A %d %B %Y at %H:%M')
|
return native.strftime('%A %d %B %Y at %H:%M')
|
||||||
|
|
||||||
|
|
||||||
|
def format_time(date):
|
||||||
|
date = dateutil.parser.parse(date)
|
||||||
|
native = date.replace(tzinfo=None)
|
||||||
|
return native.strftime('%H:%M')
|
||||||
|
|
||||||
|
|
||||||
def valid_phone_number(phone_number):
|
def valid_phone_number(phone_number):
|
||||||
try:
|
try:
|
||||||
validate_phone_number(phone_number)
|
validate_phone_number(phone_number)
|
||||||
|
|||||||
@@ -42,23 +42,26 @@ def view_job(service_id, job_id):
|
|||||||
try:
|
try:
|
||||||
job = job_api_client.get_job(service_id, job_id)['data']
|
job = job_api_client.get_job(service_id, job_id)['data']
|
||||||
notifications = notification_api_client.get_notifications_for_service(service_id, job_id)
|
notifications = notification_api_client.get_notifications_for_service(service_id, job_id)
|
||||||
|
finished = job['status'] == 'finished'
|
||||||
return render_template(
|
return render_template(
|
||||||
'views/job.html',
|
'views/job.html',
|
||||||
notifications=notifications['notifications'],
|
notifications=notifications['notifications'],
|
||||||
counts={
|
counts={
|
||||||
'total': len(notifications),
|
'queued': 0 if finished else job['notification_count'],
|
||||||
'delivered': len(notifications),
|
'sent': job['notification_count'] if finished else 0,
|
||||||
'failed': 0
|
'failed': 0
|
||||||
},
|
},
|
||||||
|
uploaded_at=job['created_at'],
|
||||||
|
finished_at=job['updated_at'] if finished else None,
|
||||||
cost=u'£0.00',
|
cost=u'£0.00',
|
||||||
uploaded_file_name=job['original_file_name'],
|
uploaded_file_name=job['original_file_name'],
|
||||||
uploaded_file_time=job['created_at'],
|
|
||||||
template=Template(
|
template=Template(
|
||||||
templates_dao.get_service_template_or_404(service_id, job['template'])['data'],
|
templates_dao.get_service_template_or_404(service_id, job['template'])['data'],
|
||||||
prefix=service['name']
|
prefix=service['name']
|
||||||
),
|
),
|
||||||
service_id=service_id,
|
service_id=service_id,
|
||||||
service=service
|
from_name=service['name'],
|
||||||
|
job_id=job_id
|
||||||
)
|
)
|
||||||
except HTTPError as e:
|
except HTTPError as e:
|
||||||
if e.status_code == 404:
|
if e.status_code == 404:
|
||||||
|
|||||||
@@ -28,23 +28,29 @@
|
|||||||
template.subject,
|
template.subject,
|
||||||
template,
|
template,
|
||||||
from_address='{}@notifications.service.gov.uk'.format(service.email_from),
|
from_address='{}@notifications.service.gov.uk'.format(service.email_from),
|
||||||
from_name=service.name
|
from_name=from_name
|
||||||
)}}
|
)}}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<p class='heading-small'>
|
{% if finished_at %}
|
||||||
Started {{ uploaded_file_time|format_datetime }}
|
<p class='heading-small'>
|
||||||
</p>
|
Finished {{ finished_at|format_datetime }}
|
||||||
|
</p>
|
||||||
|
{% else %}
|
||||||
|
<p class='heading-small'>
|
||||||
|
Started {{ uploaded_at|format_datetime }}
|
||||||
|
</p>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<ul class="grid-row job-totals">
|
<ul class="grid-row job-totals">
|
||||||
<li class="column-one-quarter">
|
<li class="column-one-quarter">
|
||||||
{{ big_number(
|
{{ big_number(
|
||||||
0, 'queued'
|
counts.queued, 'queued'
|
||||||
)}}
|
)}}
|
||||||
</li>
|
</li>
|
||||||
<li class="column-one-quarter">
|
<li class="column-one-quarter">
|
||||||
{{ big_number(
|
{{ big_number(
|
||||||
1, 'sent'
|
counts.sent, 'sent'
|
||||||
)}}
|
)}}
|
||||||
</li>
|
</li>
|
||||||
<li class="column-one-quarter">
|
<li class="column-one-quarter">
|
||||||
@@ -60,26 +66,32 @@
|
|||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
{% call(item) list_table(
|
|
||||||
notifications,
|
{% if notifications %}
|
||||||
caption=uploaded_file_name,
|
{% call(item) list_table(
|
||||||
caption_visible=False,
|
notifications,
|
||||||
empty_message="Messages go here",
|
caption=uploaded_file_name,
|
||||||
field_headings=[
|
caption_visible=False,
|
||||||
'Recipient',
|
empty_message="Messages go here",
|
||||||
'Template',
|
field_headings=[
|
||||||
right_aligned_field_heading('Status')
|
'Recipient',
|
||||||
]
|
right_aligned_field_heading('Status')
|
||||||
) %}
|
]
|
||||||
{% call field() %}
|
|
||||||
{{ item.to }}
|
|
||||||
{% endcall %}
|
|
||||||
{% call field(
|
|
||||||
align='right',
|
|
||||||
status='error' if item.status == 'Failed' else 'default'
|
|
||||||
) %}
|
) %}
|
||||||
{{ item.status }}
|
{% call field() %}
|
||||||
|
{{ item.to }}
|
||||||
|
{% endcall %}
|
||||||
|
{% call field(
|
||||||
|
align='right',
|
||||||
|
status='error' if item.status == 'Failed' else 'default'
|
||||||
|
) %}
|
||||||
|
{{ item.status|title }} at {{ item.sent_at|format_time }}
|
||||||
|
{% endcall %}
|
||||||
{% endcall %}
|
{% endcall %}
|
||||||
{% endcall %}
|
{% else %}
|
||||||
|
<p>
|
||||||
|
<a href="{{ url_for(".view_job", service_id=service_id, job_id=job_id) }}">Refresh</a>
|
||||||
|
</p>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
@@ -109,6 +109,18 @@ def job_json():
|
|||||||
'bucket_name': 'service-1-{}-notify'.format(job_id),
|
'bucket_name': 'service-1-{}-notify'.format(job_id),
|
||||||
'file_name': '{}.csv'.format(job_id),
|
'file_name': '{}.csv'.format(job_id),
|
||||||
'created_at': created_at,
|
'created_at': created_at,
|
||||||
'notification_count': 1
|
'notification_count': 1,
|
||||||
|
'status': ''
|
||||||
}
|
}
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
def notification_json():
|
||||||
|
import datetime
|
||||||
|
data = {
|
||||||
|
'notifications': [{
|
||||||
|
'sent_at': str(datetime.datetime.now().time())
|
||||||
|
} for i in range(5)],
|
||||||
|
'links': {}
|
||||||
|
}
|
||||||
|
return data
|
||||||
|
|||||||
@@ -30,7 +30,8 @@ def test_should_show_page_for_one_job(app_,
|
|||||||
mock_get_service,
|
mock_get_service,
|
||||||
mock_get_service_template,
|
mock_get_service_template,
|
||||||
job_data,
|
job_data,
|
||||||
mock_get_job):
|
mock_get_job,
|
||||||
|
mock_get_notifications):
|
||||||
service_id = job_data['service']
|
service_id = job_data['service']
|
||||||
job_id = job_data['id']
|
job_id = job_data['id']
|
||||||
file_name = job_data['original_file_name']
|
file_name = job_data['original_file_name']
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ from . import (
|
|||||||
template_json,
|
template_json,
|
||||||
api_key_json,
|
api_key_json,
|
||||||
job_json,
|
job_json,
|
||||||
|
notification_json,
|
||||||
invite_json
|
invite_json
|
||||||
)
|
)
|
||||||
from app.notify_client.models import (
|
from app.notify_client.models import (
|
||||||
@@ -541,6 +542,16 @@ def mock_get_jobs(mocker):
|
|||||||
return mocker.patch('app.job_api_client.get_job', side_effect=_get_jobs)
|
return mocker.patch('app.job_api_client.get_job', side_effect=_get_jobs)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope='function')
|
||||||
|
def mock_get_notifications(mocker):
|
||||||
|
def _get_notifications(service_id, job_id):
|
||||||
|
return notification_json()
|
||||||
|
return mocker.patch(
|
||||||
|
'app.notification_api_client.get_notifications_for_service',
|
||||||
|
side_effect=_get_notifications
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='function')
|
@pytest.fixture(scope='function')
|
||||||
def mock_has_permissions(mocker):
|
def mock_has_permissions(mocker):
|
||||||
def _has_permission(permissions, service_id=None, or_=False):
|
def _has_permission(permissions, service_id=None, or_=False):
|
||||||
|
|||||||
Reference in New Issue
Block a user