diff --git a/physionet-django/events/views.py b/physionet-django/events/views.py index 3af4688bdb..d6ce088f61 100644 --- a/physionet-django/events/views.py +++ b/physionet-django/events/views.py @@ -254,13 +254,13 @@ 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_response = JsonResponse({'error': 'You are not the host of this event'}, status=403) if event.end_date < datetime.now().date(): - return JsonResponse({'error': 'You cannot manage co-hosts of an event that has ended'}, status=403) - + error_response JsonResponse({'error': 'You cannot manage co-hosts of an event that has ended'}, status=403) if not event.participants.filter(id=participant_id).exists(): - return JsonResponse({'error': 'User is not a participant of this event'}, status=403) + error_response JsonResponse({'error': 'User is not a participant of this event'}, status=403) + if error_response: + return error_response participant = event.participants.get(id=participant_id)