From 3136d1a33b4f388d35a9b06a1752346ccf3388d7 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Fri, 10 Jul 2020 09:26:47 +0100 Subject: [PATCH] Implement sorting Shows the broadcasts with the longest time still to live at the top. At the moment this will be the same as the newest broadcasts, so we may want to revisit this sort order when we have broadcasts of variable duration. For no-longer-live broadcasts we show the most-recently-finished at the top, whether it finished naturally or was cancelled. --- app/models/broadcast_message.py | 7 +++++++ app/templates/views/broadcast/dashboard.html | 2 +- tests/app/main/views/test_broadcast.py | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/models/broadcast_message.py b/app/models/broadcast_message.py index 03677339c..c3efd2ed1 100644 --- a/app/models/broadcast_message.py +++ b/app/models/broadcast_message.py @@ -36,6 +36,13 @@ class BroadcastMessage(JSONModel): libraries = broadcast_area_libraries + def __lt__(self, other): + return ( + self.cancelled_at or self.finishes_at + ) < ( + other.cancelled_at or other.finishes_at + ) + @classmethod def create(cls, *, service_id, template_id): return cls(broadcast_message_api_client.create_broadcast_message( diff --git a/app/templates/views/broadcast/dashboard.html b/app/templates/views/broadcast/dashboard.html index 011bd756b..7a5267489 100644 --- a/app/templates/views/broadcast/dashboard.html +++ b/app/templates/views/broadcast/dashboard.html @@ -5,7 +5,7 @@ {% macro broadcast_table(broadcasts, empty_message) %}
{% call(item, row_number) list_table( - broadcasts, + broadcasts|sort|reverse|list, caption="Live broadcasts", caption_visible=False, empty_message=empty_message, diff --git a/tests/app/main/views/test_broadcast.py b/tests/app/main/views/test_broadcast.py index 961b32ac4..4b24d74b2 100644 --- a/tests/app/main/views/test_broadcast.py +++ b/tests/app/main/views/test_broadcast.py @@ -83,8 +83,8 @@ def test_broadcast_dashboard( assert [ normalize_spaces(row.text) for row in page.select('table')[1].select('tbody tr') ] == [ - 'Example template To England and Scotland Finished yesterday at 8:20pm', 'Example template To England and Scotland Stopped 10 February at 2:20am', + 'Example template To England and Scotland Finished yesterday at 8:20pm', ]