mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-04 21:51:43 -04:00
Merge pull request #226 from alphagov/real-data-on-job-page
Put real data on job page
This commit is contained in:
@@ -14,6 +14,7 @@ from app.notify_client.api_client import NotificationsAdminAPIClient
|
||||
from app.notify_client.api_key_api_client import ApiKeyApiClient
|
||||
from app.notify_client.user_api_client import UserApiClient
|
||||
from app.notify_client.job_api_client import JobApiClient
|
||||
from app.notify_client.notification_api_client import NotificationApiClient
|
||||
from app.notify_client.status_api_client import StatusApiClient
|
||||
from app.notify_client.invite_api_client import InviteApiClient
|
||||
from app.its_dangerous_session import ItsdangerousSessionInterface
|
||||
@@ -30,6 +31,7 @@ notifications_api_client = NotificationsAdminAPIClient()
|
||||
user_api_client = UserApiClient()
|
||||
api_key_api_client = ApiKeyApiClient()
|
||||
job_api_client = JobApiClient()
|
||||
notification_api_client = NotificationApiClient()
|
||||
status_api_client = StatusApiClient()
|
||||
invite_api_client = InviteApiClient()
|
||||
asset_fingerprinter = AssetFingerprinter()
|
||||
@@ -48,6 +50,7 @@ def create_app(config_name, config_overrides=None):
|
||||
user_api_client.init_app(application)
|
||||
api_key_api_client.init_app(application)
|
||||
job_api_client.init_app(application)
|
||||
notification_api_client.init_app(application)
|
||||
status_api_client.init_app(application)
|
||||
invite_api_client.init_app(application)
|
||||
|
||||
@@ -67,6 +70,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)
|
||||
|
||||
@@ -143,6 +147,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)
|
||||
|
||||
@@ -10,7 +10,7 @@ from flask_login import login_required
|
||||
from notifications_python_client.errors import HTTPError
|
||||
from utils.template import Template
|
||||
|
||||
from app import job_api_client
|
||||
from app import job_api_client, notification_api_client
|
||||
from app.main import main
|
||||
from app.main.dao import templates_dao
|
||||
from app.main.dao import services_dao
|
||||
@@ -41,28 +41,27 @@ def view_job(service_id, job_id):
|
||||
service = services_dao.get_service_by_id_or_404(service_id)
|
||||
try:
|
||||
job = job_api_client.get_job(service_id, job_id)['data']
|
||||
messages = []
|
||||
notifications = notification_api_client.get_notifications_for_service(service_id, job_id)
|
||||
finished = job['status'] == 'finished'
|
||||
return render_template(
|
||||
'views/job.html',
|
||||
messages=messages,
|
||||
notifications=notifications['notifications'],
|
||||
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'
|
||||
])
|
||||
'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:
|
||||
|
||||
37
app/notify_client/notification_api_client.py
Normal file
37
app/notify_client/notification_api_client.py
Normal file
@@ -0,0 +1,37 @@
|
||||
from notifications_python_client.base import BaseAPIClient
|
||||
|
||||
|
||||
class NotificationApiClient(BaseAPIClient):
|
||||
def __init__(self, base_url=None, client_id=None, secret=None):
|
||||
super(self.__class__, self).__init__(base_url=base_url or 'base_url',
|
||||
client_id=client_id or 'client_id',
|
||||
secret=secret or 'secret')
|
||||
|
||||
def init_app(self, app):
|
||||
self.base_url = app.config['API_HOST_NAME']
|
||||
self.client_id = app.config['ADMIN_CLIENT_USER_NAME']
|
||||
self.secret = app.config['ADMIN_CLIENT_SECRET']
|
||||
|
||||
def get_all_notifications(self, page=None):
|
||||
params = {}
|
||||
if page is not None:
|
||||
params['page'] = page
|
||||
return self.get(
|
||||
url='/notifications',
|
||||
params=params
|
||||
)
|
||||
|
||||
def get_notifications_for_service(self, service_id, job_id=None, page=None):
|
||||
params = {}
|
||||
if page is not None:
|
||||
params['page'] = page
|
||||
if job_id:
|
||||
return self.get(
|
||||
url='/service/{}/job/{}/notifications'.format(service_id, job_id),
|
||||
params=params
|
||||
)
|
||||
else:
|
||||
return self.get(
|
||||
url='/service/{}/notifications'.format(service_id),
|
||||
params=params
|
||||
)
|
||||
@@ -19,7 +19,7 @@
|
||||
<div class="grid-row">
|
||||
<div class="column-two-thirds">
|
||||
{{ sms_message(
|
||||
template,
|
||||
template.formatted_as_markup,
|
||||
)}}
|
||||
</div>
|
||||
</div>
|
||||
@@ -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,35 +66,32 @@
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
{% call(item) list_table(
|
||||
[
|
||||
{'row': 1, 'phone': '+447700 900995', 'template': template['name'], 'status': 'sent'}
|
||||
],
|
||||
caption=uploaded_file_name,
|
||||
caption_visible=False,
|
||||
empty_message="Messages go here",
|
||||
field_headings=[
|
||||
'Row',
|
||||
'Recipient',
|
||||
'Template',
|
||||
right_aligned_field_heading('Status')
|
||||
]
|
||||
) %}
|
||||
{% call field() %}
|
||||
{{ item.row }}.
|
||||
{% endcall %}
|
||||
{% call field() %}
|
||||
{{item.phone[:3]}} •••• ••••••
|
||||
{% endcall %}
|
||||
{% call field() %}
|
||||
{{item.template}}
|
||||
{% 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 %}
|
||||
|
||||
Reference in New Issue
Block a user