From 4da38e42e33301f38560e95640af381b3fb83191 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Thu, 8 Apr 2021 13:34:29 +0100 Subject: [PATCH] Make alert page work for rejected broadcasts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The code for this page was making assumptions about properties which aren’t present on rejected broadcasts. This commit accounts for those properties and presents the relevant elements on the page. --- app/models/broadcast_message.py | 2 +- app/templates/views/broadcast/view-message.html | 14 +++++++++++--- tests/app/main/views/test_broadcast.py | 8 ++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/app/models/broadcast_message.py b/app/models/broadcast_message.py index e59e5f791..a4285a916 100644 --- a/app/models/broadcast_message.py +++ b/app/models/broadcast_message.py @@ -158,7 +158,7 @@ class BroadcastMessage(JSONModel): @cached_property def approved_by(self): - return User.from_id(self.approved_by_id) + return User.from_id(self.approved_by_id) if self.approved_by_id else None @cached_property def cancelled_by(self): diff --git a/app/templates/views/broadcast/view-message.html b/app/templates/views/broadcast/view-message.html index 08be7e083..cca6309ee 100644 --- a/app/templates/views/broadcast/view-message.html +++ b/app/templates/views/broadcast/view-message.html @@ -116,6 +116,11 @@ Stop broadcasting {% endif %}

+ {% elif broadcast_message.status == 'rejected' %} +

+ Rejected + {{ broadcast_message.updated_at|format_datetime_human }}. +

{% else %}

Broadcast @@ -150,10 +155,13 @@

{% if broadcast_message.created_by %} Prepared by {{ broadcast_message.created_by.name }} - {% else %} + {%- else %} Created from an API call - {% endif %} - and approved by {{ broadcast_message.approved_by.name }}. + {%- endif %} + {%- if broadcast_message.approved_by %} + and approved by {{ broadcast_message.approved_by.name }} + {%- endif %} + {{- '.' }}

{% endif %} diff --git a/tests/app/main/views/test_broadcast.py b/tests/app/main/views/test_broadcast.py index 1e5046984..36a687d6f 100644 --- a/tests/app/main/views/test_broadcast.py +++ b/tests/app/main/views/test_broadcast.py @@ -1404,6 +1404,13 @@ def test_start_broadcasting( 'Prepared by Alice and approved by Bob.', 'Stopped by Carol yesterday at 9:21pm.', ]), + ('.view_rejected_broadcast', False, { + 'status': 'rejected', + 'updated_at': '2020-02-21T21:21:21.000000', + }, [ + 'Rejected yesterday at 9:21pm.', + 'Prepared by Alice and approved by Bob.', + ]), )) @freeze_time('2020-02-22T22:22:22.000000') def test_view_broadcast_message_page( @@ -1505,6 +1512,7 @@ def test_view_broadcast_message_shows_correct_highlighted_navigation( starts_at='2020-02-20T20:20:20.000000', finishes_at='2021-12-21T21:21:21.000000', cancelled_at='2021-01-01T01:01:01.000000', + updated_at='2021-01-01T01:01:01.000000', status=status, ), )