From 08f5c4fd7fd7f216d8cb34508071077827415b34 Mon Sep 17 00:00:00 2001 From: rutvikrj26 Date: Wed, 8 Nov 2023 16:47:25 -0500 Subject: [PATCH] fixed multiple return statements with one error message --- physionet-django/events/views.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/physionet-django/events/views.py b/physionet-django/events/views.py index 3af4688bdb..ce1a0ef7ee 100644 --- a/physionet-django/events/views.py +++ b/physionet-django/events/views.py @@ -254,13 +254,11 @@ def manage_co_hosts(request): event = get_object_or_404(Event, slug=event_slug) if not event.host == user: - return JsonResponse({'error': 'You are not the host of this event'}, status=403) - + error_message = = 'You are not the host of this event' if event.end_date < datetime.now().date(): - return JsonResponse({'error': 'You cannot manage co-hosts of an event that has ended'}, status=403) - + error_message = 'You cannot manage co-hosts of an event that has ended' if not event.participants.filter(id=participant_id).exists(): - return JsonResponse({'error': 'User is not a participant of this event'}, status=403) + error_message = 'User is not a participant of this event' participant = event.participants.get(id=participant_id) @@ -288,4 +286,8 @@ def manage_co_hosts(request): return JsonResponse({'success': 'Cohost added successfully'}) messages.error(request, 'Invalid request') + + if error_message: + return JsonResponse({'error': error_message}, status=403) + return redirect(event_home)