From 4604704de09aa3ef1691e2e7583ee2965c190c85 Mon Sep 17 00:00:00 2001 From: Xavier Medrano Date: Thu, 18 Jul 2024 12:22:55 -0400 Subject: [PATCH 1/3] prevent broadcast creation if a proper one already exists --- .gitignore | 2 ++ lametro/views.py | 13 ++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 9be953be..50fa6a89 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,5 @@ debug.log lametro/secrets.py .env.local + +.venv diff --git a/lametro/views.py b/lametro/views.py index 39382e51..eb3e1ecc 100644 --- a/lametro/views.py +++ b/lametro/views.py @@ -316,15 +316,22 @@ def manual_event_live_link(request, event_slug): Toggle a manually live event broadcast link """ event = LAMetroEvent.objects.get(slug=event_slug) - broadcasts = event.broadcast.filter(is_manually_live=True) + has_regular_broadcasts = event.broadcast.filter(is_manually_live=False).exists() + manual_broadcasts = event.broadcast.filter(is_manually_live=True) - if broadcasts.count() == 0: + if manual_broadcasts.count() == 0 and not has_regular_broadcasts: # Create a manual broadcast EventBroadcast.objects.create(event=event, is_manually_live=True) messages.success(request, f"Link for {event.name} has been manually published.") + elif has_regular_broadcasts: + messages.info( + request, + f"The event {event.name} already has a proper broadcast. " + + f"A manual broadcast cannot be created.", + ) else: # Delete that broadcast - for b in broadcasts: + for b in manual_broadcasts: b.delete() messages.success(request, f"Link for {event.name} has been unpublished.") From c2d4015fb0053166f898792d1799c890127f8ca6 Mon Sep 17 00:00:00 2001 From: Xavier Medrano Date: Thu, 18 Jul 2024 12:36:20 -0400 Subject: [PATCH 2/3] remove unneeded f-string --- lametro/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lametro/views.py b/lametro/views.py index eb3e1ecc..e53b262d 100644 --- a/lametro/views.py +++ b/lametro/views.py @@ -327,7 +327,7 @@ def manual_event_live_link(request, event_slug): messages.info( request, f"The event {event.name} already has a proper broadcast. " - + f"A manual broadcast cannot be created.", + + "A manual broadcast cannot be created.", ) else: # Delete that broadcast From af53878833efbe3e3b7e2a0803a60c688c36fbf0 Mon Sep 17 00:00:00 2001 From: Xavier Medrano Date: Fri, 19 Jul 2024 10:14:29 -0400 Subject: [PATCH 3/3] fix manual broadcast tests --- tests/test_events.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_events.py b/tests/test_events.py index 00f51368..9665046e 100644 --- a/tests/test_events.py +++ b/tests/test_events.py @@ -763,7 +763,7 @@ def test_manual_broadcast_permissions(event, client, admin_client, mocker): """ Check that only authenticated users can make/delete manual broadcasts """ - test_event = event.build() + test_event = event.build(has_broadcast=False) mock_api_representation = mocker.patch( "lametro.models.SourcesMixin.api_representation", new_callable=mocker.PropertyMock, @@ -803,7 +803,7 @@ def test_manually_broadcasted_events(event, admin_client, mocker): """ Check that events marked as having a manual broadcast are counted as being current/live. """ - test_event = event.build() + test_event = event.build(has_broadcast=False) mock_api_representation = mocker.patch( "lametro.models.SourcesMixin.api_representation", new_callable=mocker.PropertyMock,