mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-11 17:38:50 -04:00
This commit: - adds the template to the jobs page (and puts it at the top of the send SMS page) so that it consistently appears in the same place throughout the journey - put the real data about a job on the jobs page and on the dashboard
81 lines
2.2 KiB
Python
81 lines
2.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
import time
|
|
|
|
from flask import (
|
|
render_template,
|
|
abort
|
|
)
|
|
from flask_login import login_required
|
|
from client.errors import HTTPError
|
|
|
|
from app import job_api_client
|
|
from app.main import main
|
|
from app.main.dao import templates_dao
|
|
|
|
now = time.strftime('%H:%M')
|
|
|
|
|
|
@main.route("/services/<service_id>/jobs")
|
|
@login_required
|
|
def view_jobs(service_id):
|
|
try:
|
|
jobs = job_api_client.get_job(service_id)['data']
|
|
return render_template(
|
|
'views/jobs.html',
|
|
jobs=jobs,
|
|
service_id=service_id
|
|
)
|
|
except HTTPError as e:
|
|
if e.status_code == 404:
|
|
abort(404)
|
|
else:
|
|
raise e
|
|
|
|
|
|
@main.route("/services/<service_id>/jobs/<job_id>")
|
|
@login_required
|
|
def view_job(service_id, job_id):
|
|
try:
|
|
job = job_api_client.get_job(service_id, job_id)['data']
|
|
template = templates_dao.get_service_template(service_id, job['template'])['data']
|
|
messages = []
|
|
return render_template(
|
|
'views/job.html',
|
|
messages=messages,
|
|
counts={
|
|
'total': len(messages),
|
|
'delivered': len([
|
|
message for message in messages if message['status'] == 'Delivered'
|
|
]),
|
|
'failed': len([
|
|
message for message in messages if message['status'] == 'Failed'
|
|
])
|
|
},
|
|
cost=u'£0.00',
|
|
uploaded_file_name=job['original_file_name'],
|
|
uploaded_file_time=job['created_at'],
|
|
template=template,
|
|
service_id=service_id
|
|
)
|
|
except HTTPError as e:
|
|
if e.status_code == 404:
|
|
abort(404)
|
|
else:
|
|
raise e
|
|
|
|
|
|
@main.route("/services/<service_id>/jobs/<job_id>/notification/<string:notification_id>")
|
|
@login_required
|
|
def view_notification(service_id, job_id, notification_id):
|
|
return render_template(
|
|
'views/notification.html',
|
|
message=[
|
|
message for message in messages if message['id'] == notification_id
|
|
][0],
|
|
delivered_at=now,
|
|
uploaded_at=now,
|
|
service_id=service_id,
|
|
job_id=job_id
|
|
)
|