From 78681eb452e79c287cfebc181f027e783f0b373a Mon Sep 17 00:00:00 2001
From: Pea Tyczynska
Date: Tue, 18 Jan 2022 12:23:20 +0000
Subject: [PATCH] Display if broadcast was cancelled via API
If broadcast_message has no value under cancelled_by_id, display
in the view that it was cancelled by an API call.
---
app/models/broadcast_message.py | 4 +++-
app/templates/views/broadcast/view-message.html | 2 +-
tests/app/main/views/test_broadcast.py | 9 +++++++++
3 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/app/models/broadcast_message.py b/app/models/broadcast_message.py
index 3aeaf7e3f..310ebd3b2 100644
--- a/app/models/broadcast_message.py
+++ b/app/models/broadcast_message.py
@@ -181,7 +181,9 @@ class BroadcastMessage(JSONModel):
@cached_property
def cancelled_by(self):
- return User.from_id(self.cancelled_by_id)
+ if not self.cancelled_by_id:
+ return "an API call"
+ return User.from_id(self.cancelled_by_id).name
@cached_property
def count_of_phones(self):
diff --git a/app/templates/views/broadcast/view-message.html b/app/templates/views/broadcast/view-message.html
index 7381609df..bed67f6bc 100644
--- a/app/templates/views/broadcast/view-message.html
+++ b/app/templates/views/broadcast/view-message.html
@@ -212,7 +212,7 @@
{% elif broadcast_message.status == 'cancelled' %}
- Stopped by {{ broadcast_message.cancelled_by.name }}
+ Stopped by {{ broadcast_message.cancelled_by }}
{{ broadcast_message.cancelled_at|format_datetime_human }}.
{% elif broadcast_message.status == 'completed' %}
diff --git a/tests/app/main/views/test_broadcast.py b/tests/app/main/views/test_broadcast.py
index 90145bc99..b955e67dd 100644
--- a/tests/app/main/views/test_broadcast.py
+++ b/tests/app/main/views/test_broadcast.py
@@ -1695,6 +1695,15 @@ def test_start_broadcasting(
'Created by Alice and approved by Bob.',
'Stopped by Carol yesterday at 9:21pm.',
]),
+ ('.view_previous_broadcast', False, {
+ 'status': 'cancelled',
+ 'cancelled_by_id': None,
+ 'cancelled_at': '2020-02-21T21:21:21.000000',
+ }, [
+ 'Sent on 20 February at 8:20pm.',
+ 'Created by Alice and approved by Bob.',
+ 'Stopped by an API call yesterday at 9:21pm.',
+ ]),
('.view_rejected_broadcast', False, {
'status': 'rejected',
'updated_at': '2020-02-21T21:21:21.000000',