Skip to content

Commit

Permalink
Merge pull request #1137 from Metro-Records/patch/manual-broadcast
Browse files Browse the repository at this point in the history
Prevent broadcast creation if a proper one already exists
  • Loading branch information
xmedr authored Jul 23, 2024
2 parents 4ba1474 + af53878 commit c91573a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ debug.log

lametro/secrets.py
.env.local

.venv
13 changes: 10 additions & 3 deletions lametro/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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. "
+ "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.")

Expand Down
4 changes: 2 additions & 2 deletions tests/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit c91573a

Please sign in to comment.