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:
Chris Hill-Scott
2016-03-02 16:15:15 +00:00
parent 3a3e4258ef
commit d9073862fa
6 changed files with 77 additions and 31 deletions

View File

@@ -73,6 +73,7 @@ def create_app(config_name, config_overrides=None):
application.add_template_filter(nl2br)
application.add_template_filter(format_datetime)
application.add_template_filter(format_time)
application.add_template_filter(syntax_highlight_json)
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')
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):
try:
validate_phone_number(phone_number)

View File

@@ -42,23 +42,26 @@ def view_job(service_id, job_id):
try:
job = job_api_client.get_job(service_id, job_id)['data']
notifications = notification_api_client.get_notifications_for_service(service_id, job_id)
finished = job['status'] == 'finished'
return render_template(
'views/job.html',
notifications=notifications['notifications'],
counts={
'total': len(notifications),
'delivered': len(notifications),
'queued': 0 if finished else job['notification_count'],
'sent': job['notification_count'] if finished else 0,
'failed': 0
},
uploaded_at=job['created_at'],
finished_at=job['updated_at'] if finished else None,
cost=u'£0.00',
uploaded_file_name=job['original_file_name'],
uploaded_file_time=job['created_at'],
template=Template(
templates_dao.get_service_template_or_404(service_id, job['template'])['data'],
prefix=service['name']
),
service_id=service_id,
service=service
from_name=service['name'],
job_id=job_id
)
except HTTPError as e:
if e.status_code == 404:

View File

@@ -28,23 +28,29 @@
template.subject,
template,
from_address='{}@notifications.service.gov.uk'.format(service.email_from),
from_name=service.name
from_name=from_name
)}}
{% endif %}
<p class='heading-small'>
Started {{ uploaded_file_time|format_datetime }}
</p>
{% if finished_at %}
<p class='heading-small'>
Finished {{ finished_at|format_datetime }}
</p>
{% else %}
<p class='heading-small'>
Started {{ uploaded_at|format_datetime }}
</p>
{% endif %}
<ul class="grid-row job-totals">
<li class="column-one-quarter">
{{ big_number(
0, 'queued'
counts.queued, 'queued'
)}}
</li>
<li class="column-one-quarter">
{{ big_number(
1, 'sent'
counts.sent, 'sent'
)}}
</li>
<li class="column-one-quarter">
@@ -60,26 +66,32 @@
</li>
</ul>
{% call(item) list_table(
notifications,
caption=uploaded_file_name,
caption_visible=False,
empty_message="Messages go here",
field_headings=[
'Recipient',
'Template',
right_aligned_field_heading('Status')
]
) %}
{% call field() %}
{{ item.to }}
{% endcall %}
{% call field(
align='right',
status='error' if item.status == 'Failed' else 'default'
{% if notifications %}
{% call(item) list_table(
notifications,
caption=uploaded_file_name,
caption_visible=False,
empty_message="Messages go here",
field_headings=[
'Recipient',
right_aligned_field_heading('Status')
]
) %}
{{ 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 %}
{% else %}
<p>
<a href="{{ url_for(".view_job", service_id=service_id, job_id=job_id) }}">Refresh</a>
</p>
{% endif %}
{% endblock %}

View File

@@ -109,6 +109,18 @@ def job_json():
'bucket_name': 'service-1-{}-notify'.format(job_id),
'file_name': '{}.csv'.format(job_id),
'created_at': created_at,
'notification_count': 1
'notification_count': 1,
'status': ''
}
return data
def notification_json():
import datetime
data = {
'notifications': [{
'sent_at': str(datetime.datetime.now().time())
} for i in range(5)],
'links': {}
}
return data

View File

@@ -30,7 +30,8 @@ def test_should_show_page_for_one_job(app_,
mock_get_service,
mock_get_service_template,
job_data,
mock_get_job):
mock_get_job,
mock_get_notifications):
service_id = job_data['service']
job_id = job_data['id']
file_name = job_data['original_file_name']

View File

@@ -10,6 +10,7 @@ from . import (
template_json,
api_key_json,
job_json,
notification_json,
invite_json
)
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)
@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')
def mock_has_permissions(mocker):
def _has_permission(permissions, service_id=None, or_=False):