From 3bd47ef399b339d87a67513a10ec3b9be6f4b56b Mon Sep 17 00:00:00 2001 From: Amit Upreti Date: Wed, 8 Mar 2023 15:41:43 -0500 Subject: [PATCH 01/14] use buttons to create/remove cohosts --- .../events/templates/events/event_entries.html | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/physionet-django/events/templates/events/event_entries.html b/physionet-django/events/templates/events/event_entries.html index 861655d96b..d15edca40c 100644 --- a/physionet-django/events/templates/events/event_entries.html +++ b/physionet-django/events/templates/events/event_entries.html @@ -18,9 +18,19 @@ {{ participant.user.is_credentialed }} {% if participant.is_cohost %} - +
+ {% csrf_token %} + + + +
{% else %} - +
+ {% csrf_token %} + + + +
{% endif %} From d6a229b4cf1215ddccdc36baa1176548b365bf45 Mon Sep 17 00:00:00 2001 From: Amit Upreti Date: Wed, 8 Mar 2023 15:55:15 -0500 Subject: [PATCH 02/14] add view to manage cohost The view will be used by ajax request which will be sent from event_home.html. --- physionet-django/events/urls.py | 1 + physionet-django/events/views.py | 47 ++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/physionet-django/events/urls.py b/physionet-django/events/urls.py index 6feaeac384..3b19086667 100644 --- a/physionet-django/events/urls.py +++ b/physionet-django/events/urls.py @@ -6,6 +6,7 @@ urlpatterns = [ path('', views.event_home, name='event_home'), path('create/', views.create_event, name='create_event'), + path('manage_co_hosts/', views.manage_co_hosts, name='manage_co_hosts'), path('/', views.event_detail, name='event_detail'), path('/edit_event/', views.update_event, name='update_event'), path('/details/', views.get_event_details, name='get_event_details'), diff --git a/physionet-django/events/views.py b/physionet-django/events/views.py index c0d36b3d97..8eb92bcd42 100644 --- a/physionet-django/events/views.py +++ b/physionet-django/events/views.py @@ -235,3 +235,50 @@ def event_detail(request, event_slug): 'is_waitlisted': is_waitlisted, 'event_datasets': event_datasets, }) + + +@login_required +def manage_co_hosts(request): + """ + Manage co-hosts of an event + """ + user = request.user + + if request.method == 'POST' and request.is_ajax(): + participant_id = request.POST.get('participant_id') + + event_slug = request.POST.get('event_slug') + 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) + + if event.end_date < datetime.now().date(): + return 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) + + participant = event.participants.get(id=participant_id) + + if 'Remove cohost' in request.POST.get('submit'): + if not participant.is_cohost: + return JsonResponse({'error': 'User is not a cohost of this event'}, status=403) + participant.is_cohost = False + participant.save() + + # placeholder for notification to cohost that they have been removed and to host that they removed a cohost + + return JsonResponse({'success': 'Cohost removed successfully'}) + elif 'Make cohost' in request.POST.get('submit'): + if participant.is_cohost: + return JsonResponse({'error': 'User is already a cohost of this event'}, status=403) + participant.is_cohost = True + participant.save() + + # placeholder for notification to cohost that they have been added and to host that they added a cohost + + return JsonResponse({'success': 'Cohost added successfully'}) + + messages.error(request, 'Invalid request') + return redirect(event_home) From 2f56e4945d4fcade5348bd27c9586cba821cd466 Mon Sep 17 00:00:00 2001 From: Amit Upreti Date: Wed, 8 Mar 2023 16:39:41 -0500 Subject: [PATCH 03/14] implement the make cohost on templates Here, when event host clicks the `Make Cohost` or the `Remove Cohost` button, 1. we will immediately disable the button(so that host cant spam the button), it also acts like a feedback to host that the task is processing. 2. Then we send ajax request to our view 3. Depending on the response from view, a. If successfull, we will either change the button from `Make Cohost` to `Remove Cohost` or vice versa(depending on whether the host was trying to make cohost or remove cohost) b. If unsuccessfull, we will enable the button again to allow host to try again. --- .../templates/events/event_entries.html | 4 +- .../events/templates/events/event_home.html | 41 +++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/physionet-django/events/templates/events/event_entries.html b/physionet-django/events/templates/events/event_entries.html index d15edca40c..c2f8c5370c 100644 --- a/physionet-django/events/templates/events/event_entries.html +++ b/physionet-django/events/templates/events/event_entries.html @@ -18,14 +18,14 @@ {{ participant.user.is_credentialed }} {% if participant.is_cohost %} -
+ {% csrf_token %}
{% else %} -
+ {% csrf_token %} diff --git a/physionet-django/events/templates/events/event_home.html b/physionet-django/events/templates/events/event_home.html index bd62b980eb..323215c857 100644 --- a/physionet-django/events/templates/events/event_home.html +++ b/physionet-django/events/templates/events/event_home.html @@ -190,6 +190,47 @@ {% block local_js_bottom %} {% endblock %} From 1bb6ca068a3d35e7ccc71f0e52ec684bd75bfad4 Mon Sep 17 00:00:00 2001 From: Amit Upreti Date: Wed, 8 Mar 2023 16:53:36 -0500 Subject: [PATCH 04/14] only allow to add cohost to active event --- physionet-django/events/models.py | 6 ++++ .../templates/events/event_entries.html | 32 ++++++++++--------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/physionet-django/events/models.py b/physionet-django/events/models.py index 1b904b950e..dcc09cda27 100644 --- a/physionet-django/events/models.py +++ b/physionet-django/events/models.py @@ -59,6 +59,12 @@ def get_cohosts(self): """ return self.participants.filter(is_cohost=True) + def has_ended(self): + """ + Returns true if the event has ended. + """ + return self.end_date < timezone.now().date() + class EventParticipant(models.Model): """ diff --git a/physionet-django/events/templates/events/event_entries.html b/physionet-django/events/templates/events/event_entries.html index c2f8c5370c..ed998096bc 100644 --- a/physionet-django/events/templates/events/event_entries.html +++ b/physionet-django/events/templates/events/event_entries.html @@ -17,21 +17,23 @@ {{ participant.user.email }} {{ participant.user.is_credentialed }} - {% if participant.is_cohost %} - - {% csrf_token %} - - - - - {% else %} -
- {% csrf_token %} - - - -
- {% endif %} + {% if not event.has_ended %} + {% if participant.is_cohost %} +
+ {% csrf_token %} + + + +
+ {% else %} +
+ {% csrf_token %} + + + +
+ {% endif %} + {% endif %} {% endfor %} From 1135c7d1c28efff2c062f5785a2092be96f9a044 Mon Sep 17 00:00:00 2001 From: Amit Upreti Date: Fri, 10 Mar 2023 14:31:55 -0500 Subject: [PATCH 05/14] send email to host,cohost Whenever a host adds or removes a cohost to the event, email notification are sent to a) host and b) the added/removed cohost --- .../event_cohost_cohost_status_change.html | 15 +++++++ .../event_host_cohost_status_change.html | 14 +++++++ physionet-django/events/views.py | 16 ++++++-- physionet-django/notification/utility.py | 39 +++++++++++++++++++ 4 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 physionet-django/events/templates/events/email/event_cohost_cohost_status_change.html create mode 100644 physionet-django/events/templates/events/email/event_host_cohost_status_change.html diff --git a/physionet-django/events/templates/events/email/event_cohost_cohost_status_change.html b/physionet-django/events/templates/events/email/event_cohost_cohost_status_change.html new file mode 100644 index 0000000000..03d9b0bc55 --- /dev/null +++ b/physionet-django/events/templates/events/email/event_cohost_cohost_status_change.html @@ -0,0 +1,15 @@ +{% load i18n %}{% autoescape off %}{% filter wordwrap:70 %} +Dear {{ name }}, +{% if status == 'Make cohost' %} +You have been added as Cohost to the Event : {{ event_title }}. + +You can now manage the event participants from your events dashboard. +{% elif status == 'Remove cohost' %} +Your Cohost access has been removed from the Event : {{ event_title }}. +{% endif %} +You can view further information about the event using the following link: +{{ url_prefix }}{{ event_url }} + +Regards +The {{ SITE_NAME }} Team +{% endfilter %}{% endautoescape %} diff --git a/physionet-django/events/templates/events/email/event_host_cohost_status_change.html b/physionet-django/events/templates/events/email/event_host_cohost_status_change.html new file mode 100644 index 0000000000..c22563e470 --- /dev/null +++ b/physionet-django/events/templates/events/email/event_host_cohost_status_change.html @@ -0,0 +1,14 @@ +{% load i18n %}{% autoescape off %}{% filter wordwrap:70 %} +Dear {{ host_name }}, +{% if status == 'Make cohost' %} +You have provided {{ cohost_name }} Cohost access to the Event : {{ event_title }}. +{% elif status == 'Remove cohost' %} +You have removed {{ cohost_name }}'s Cohost access from the Event : {{ event_title }}. +{% endif %} +If this was done by mistake, you can change the cohost status by visiting the events dashboard. + +{{ url_prefix }}/events/ + +Regards +The {{ SITE_NAME }} Team +{% endfilter %}{% endautoescape %} diff --git a/physionet-django/events/views.py b/physionet-django/events/views.py index 8eb92bcd42..a29195f53d 100644 --- a/physionet-django/events/views.py +++ b/physionet-django/events/views.py @@ -266,8 +266,12 @@ def manage_co_hosts(request): return JsonResponse({'error': 'User is not a cohost of this event'}, status=403) participant.is_cohost = False participant.save() - - # placeholder for notification to cohost that they have been removed and to host that they removed a cohost + # notify the cohost that their cohost permission has been removed + notification.notify_event_cohost_cohost_status_change(request=request, cohost=participant.user, + event=event, status='Remove cohost') + # notify the host that they have removed a cohost + notification.notify_event_host_cohost_status_change(request=request, cohost=participant.user, event=event, + status='Remove cohost') return JsonResponse({'success': 'Cohost removed successfully'}) elif 'Make cohost' in request.POST.get('submit'): @@ -275,8 +279,12 @@ def manage_co_hosts(request): return JsonResponse({'error': 'User is already a cohost of this event'}, status=403) participant.is_cohost = True participant.save() - - # placeholder for notification to cohost that they have been added and to host that they added a cohost + # notify the cohost that they have been added as a cohost for the event + notification.notify_event_cohost_cohost_status_change(request=request, cohost=participant.user, + event=event, status='Make cohost') + # notify the host that they have added a cohost for the event + notification.notify_event_host_cohost_status_change(request=request, cohost=participant.user, event=event, + status='Make cohost') return JsonResponse({'success': 'Cohost added successfully'}) diff --git a/physionet-django/notification/utility.py b/physionet-django/notification/utility.py index f531057719..7f81ebec52 100644 --- a/physionet-django/notification/utility.py +++ b/physionet-django/notification/utility.py @@ -1005,6 +1005,45 @@ def notify_participant_event_decision(request, user, event, decision, comment_to send_mail(subject, body, settings.DEFAULT_FROM_EMAIL, [user.email], fail_silently=False) +def notify_event_cohost_cohost_status_change(request, cohost, event, status='Make cohost'): + """ + Send email to co-host about their cohost status change for the event. + """ + subject = f"{settings.SITE_NAME} Event Cohost Status Change" + context = { + 'name': cohost.get_full_name(), + 'domain': get_current_site(request), + 'url_prefix': get_url_prefix(request), + 'event_title': event.title, + 'event_url': reverse('event_detail', args=[event.slug]), + 'status': status, + 'SITE_NAME': settings.SITE_NAME, + } + body = loader.render_to_string('events/email/event_cohost_cohost_status_change.html', context) + # Not resend the email if there was an integrity error + send_mail(subject, body, settings.DEFAULT_FROM_EMAIL, [cohost.email], fail_silently=False) + + +def notify_event_host_cohost_status_change(request, cohost, event, status='Make cohost'): + """ + Send email to host about cohost status change for the event. + """ + subject = f"{settings.SITE_NAME} Event Cohost Status Change" + context = { + 'host_name': event.host.get_full_name(), + 'cohost_name': cohost.get_full_name(), + 'domain': get_current_site(request), + 'url_prefix': get_url_prefix(request), + 'event_title': event.title, + 'event_url': reverse('event_detail', args=[event.slug]), + 'status': status, + 'SITE_NAME': settings.SITE_NAME, + } + body = loader.render_to_string('events/email/event_host_cohost_status_change.html', context) + # Not resend the email if there was an integrity error + send_mail(subject, body, settings.DEFAULT_FROM_EMAIL, [cohost.email], fail_silently=False) + + def notify_event_participant_application(request, user, registered_user, event): """ Send email to host and co-host about new registration request on event. From 879a04780d310ea53f39803464c1a17be453f931 Mon Sep 17 00:00:00 2001 From: rutvikrj26 Date: Wed, 11 Oct 2023 15:39:49 -0400 Subject: [PATCH 06/14] addressed comments - made the template more consistent & fixed the is_ajax depreceation issue --- .../templates/console/event_management.html | 2 +- .../event_cohost_cohost_status_change.html | 2 +- .../event_host_cohost_status_change.html | 3 +- .../templates/events/event_applications.html | 37 +++++++++++++++++++ .../events/templates/events/event_home.html | 4 +- physionet-django/events/views.py | 6 +-- physionet-django/notification/utility.py | 9 ++--- 7 files changed, 47 insertions(+), 16 deletions(-) create mode 100644 physionet-django/events/templates/events/event_applications.html diff --git a/physionet-django/console/templates/console/event_management.html b/physionet-django/console/templates/console/event_management.html index 1ec760e079..8a1cd8bd58 100644 --- a/physionet-django/console/templates/console/event_management.html +++ b/physionet-django/console/templates/console/event_management.html @@ -72,7 +72,7 @@ - {% include 'events/event_entries.html' %} + {% include 'events/event_applications.html' %} diff --git a/physionet-django/events/templates/events/email/event_cohost_cohost_status_change.html b/physionet-django/events/templates/events/email/event_cohost_cohost_status_change.html index 03d9b0bc55..fbc4a5be78 100644 --- a/physionet-django/events/templates/events/email/event_cohost_cohost_status_change.html +++ b/physionet-django/events/templates/events/email/event_cohost_cohost_status_change.html @@ -8,7 +8,7 @@ Your Cohost access has been removed from the Event : {{ event_title }}. {% endif %} You can view further information about the event using the following link: -{{ url_prefix }}{{ event_url }} +{{ event_url }} Regards The {{ SITE_NAME }} Team diff --git a/physionet-django/events/templates/events/email/event_host_cohost_status_change.html b/physionet-django/events/templates/events/email/event_host_cohost_status_change.html index c22563e470..dcaa1e4a1f 100644 --- a/physionet-django/events/templates/events/email/event_host_cohost_status_change.html +++ b/physionet-django/events/templates/events/email/event_host_cohost_status_change.html @@ -6,8 +6,7 @@ You have removed {{ cohost_name }}'s Cohost access from the Event : {{ event_title }}. {% endif %} If this was done by mistake, you can change the cohost status by visiting the events dashboard. - -{{ url_prefix }}/events/ +{{ event_url }} Regards The {{ SITE_NAME }} Team diff --git a/physionet-django/events/templates/events/event_applications.html b/physionet-django/events/templates/events/event_applications.html new file mode 100644 index 0000000000..28c9ed6aa4 --- /dev/null +++ b/physionet-django/events/templates/events/event_applications.html @@ -0,0 +1,37 @@ +
+ + + + + + + + + + + + {% for participant in event.participants.all %} + + + + + + + + {% endfor %} + +
UsernameFull nameEmailCredentialedCohost
{{ participant.user.username }}{{ participant.user.get_full_name }}{{ participant.user.email }}{{ participant.user.is_credentialed }} + {% if not event.has_ended %} +
+ {% csrf_token %} + + + {% if participant.is_cohost %} + + {% else %} + + {% endif %} +
+ {% endif %} +
+
diff --git a/physionet-django/events/templates/events/event_home.html b/physionet-django/events/templates/events/event_home.html index 323215c857..c583fa6c7f 100644 --- a/physionet-django/events/templates/events/event_home.html +++ b/physionet-django/events/templates/events/event_home.html @@ -110,7 +110,7 @@ - {% include 'events/event_entries.html' %} + {% include 'events/event_applications.html' %} @@ -178,7 +178,7 @@ - {% include 'events/event_entries.html' %} + {% include 'events/event_applications.html' %} diff --git a/physionet-django/events/views.py b/physionet-django/events/views.py index 88d80ce721..d12584772d 100644 --- a/physionet-django/events/views.py +++ b/physionet-django/events/views.py @@ -247,7 +247,7 @@ def manage_co_hosts(request): """ user = request.user - if request.method == 'POST' and request.is_ajax(): + if request.method == 'POST' and request.META.get('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest': participant_id = request.POST.get('participant_id') event_slug = request.POST.get('event_slug') @@ -269,10 +269,8 @@ def manage_co_hosts(request): return JsonResponse({'error': 'User is not a cohost of this event'}, status=403) participant.is_cohost = False participant.save() - # notify the cohost that their cohost permission has been removed notification.notify_event_cohost_cohost_status_change(request=request, cohost=participant.user, event=event, status='Remove cohost') - # notify the host that they have removed a cohost notification.notify_event_host_cohost_status_change(request=request, cohost=participant.user, event=event, status='Remove cohost') @@ -282,10 +280,8 @@ def manage_co_hosts(request): return JsonResponse({'error': 'User is already a cohost of this event'}, status=403) participant.is_cohost = True participant.save() - # notify the cohost that they have been added as a cohost for the event notification.notify_event_cohost_cohost_status_change(request=request, cohost=participant.user, event=event, status='Make cohost') - # notify the host that they have added a cohost for the event notification.notify_event_host_cohost_status_change(request=request, cohost=participant.user, event=event, status='Make cohost') diff --git a/physionet-django/notification/utility.py b/physionet-django/notification/utility.py index afaf6e5add..2c312714af 100644 --- a/physionet-django/notification/utility.py +++ b/physionet-django/notification/utility.py @@ -3,6 +3,7 @@ """ from email.utils import formataddr from functools import cache +import re from urllib import parse from django.conf import settings @@ -1006,7 +1007,7 @@ def notify_participant_event_decision(request, user, event, decision, comment_to send_mail(subject, body, settings.DEFAULT_FROM_EMAIL, [user.email], fail_silently=False) -def notify_event_cohost_cohost_status_change(request, cohost, event, status='Make cohost'): +def notify_event_cohost_cohost_status_change(request, cohost, event, status): """ Send email to co-host about their cohost status change for the event. """ @@ -1014,9 +1015,8 @@ def notify_event_cohost_cohost_status_change(request, cohost, event, status='Mak context = { 'name': cohost.get_full_name(), 'domain': get_current_site(request), - 'url_prefix': get_url_prefix(request), 'event_title': event.title, - 'event_url': reverse('event_detail', args=[event.slug]), + 'event_url': request.build_absolute_uri(reverse('event_detail', args=[event.slug])), 'status': status, 'SITE_NAME': settings.SITE_NAME, } @@ -1034,9 +1034,8 @@ def notify_event_host_cohost_status_change(request, cohost, event, status='Make 'host_name': event.host.get_full_name(), 'cohost_name': cohost.get_full_name(), 'domain': get_current_site(request), - 'url_prefix': get_url_prefix(request), 'event_title': event.title, - 'event_url': reverse('event_detail', args=[event.slug]), + 'event_url': request.build_absolute_uri(reverse('event_detail', args=[event.slug])), 'status': status, 'SITE_NAME': settings.SITE_NAME, } From a23606245a378efdf7a58fbc34004d6e59df6064 Mon Sep 17 00:00:00 2001 From: rutvikrj26 Date: Wed, 8 Nov 2023 16:21:20 -0500 Subject: [PATCH 07/14] Removed string based email triggers - now using boolean based on database status --- .../email/event_cohost_cohost_status_change.html | 6 +++--- .../events/email/event_host_cohost_status_change.html | 7 ++++--- physionet-django/events/views.py | 10 +++++----- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/physionet-django/events/templates/events/email/event_cohost_cohost_status_change.html b/physionet-django/events/templates/events/email/event_cohost_cohost_status_change.html index fbc4a5be78..6e3a633534 100644 --- a/physionet-django/events/templates/events/email/event_cohost_cohost_status_change.html +++ b/physionet-django/events/templates/events/email/event_cohost_cohost_status_change.html @@ -1,10 +1,10 @@ {% load i18n %}{% autoescape off %}{% filter wordwrap:70 %} Dear {{ name }}, -{% if status == 'Make cohost' %} +{% if status == True %} You have been added as Cohost to the Event : {{ event_title }}. You can now manage the event participants from your events dashboard. -{% elif status == 'Remove cohost' %} +{% elif status == False %} Your Cohost access has been removed from the Event : {{ event_title }}. {% endif %} You can view further information about the event using the following link: @@ -12,4 +12,4 @@ Regards The {{ SITE_NAME }} Team -{% endfilter %}{% endautoescape %} +{% endfilter %}{% endautoescape %} \ No newline at end of file diff --git a/physionet-django/events/templates/events/email/event_host_cohost_status_change.html b/physionet-django/events/templates/events/email/event_host_cohost_status_change.html index dcaa1e4a1f..fcecfef1e4 100644 --- a/physionet-django/events/templates/events/email/event_host_cohost_status_change.html +++ b/physionet-django/events/templates/events/email/event_host_cohost_status_change.html @@ -1,8 +1,9 @@ {% load i18n %}{% autoescape off %}{% filter wordwrap:70 %} Dear {{ host_name }}, -{% if status == 'Make cohost' %} + +{% if status == True %} You have provided {{ cohost_name }} Cohost access to the Event : {{ event_title }}. -{% elif status == 'Remove cohost' %} +{% elif status == False %} You have removed {{ cohost_name }}'s Cohost access from the Event : {{ event_title }}. {% endif %} If this was done by mistake, you can change the cohost status by visiting the events dashboard. @@ -10,4 +11,4 @@ Regards The {{ SITE_NAME }} Team -{% endfilter %}{% endautoescape %} +{% endfilter %}{% endautoescape %} \ No newline at end of file diff --git a/physionet-django/events/views.py b/physionet-django/events/views.py index d12584772d..3af4688bdb 100644 --- a/physionet-django/events/views.py +++ b/physionet-django/events/views.py @@ -247,7 +247,7 @@ def manage_co_hosts(request): """ user = request.user - if request.method == 'POST' and request.META.get('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest': + if request.method == 'POST': participant_id = request.POST.get('participant_id') event_slug = request.POST.get('event_slug') @@ -270,9 +270,9 @@ def manage_co_hosts(request): participant.is_cohost = False participant.save() notification.notify_event_cohost_cohost_status_change(request=request, cohost=participant.user, - event=event, status='Remove cohost') + event=event, status=participant.is_cohost) notification.notify_event_host_cohost_status_change(request=request, cohost=participant.user, event=event, - status='Remove cohost') + status=participant.is_cohost) return JsonResponse({'success': 'Cohost removed successfully'}) elif 'Make cohost' in request.POST.get('submit'): @@ -281,9 +281,9 @@ def manage_co_hosts(request): participant.is_cohost = True participant.save() notification.notify_event_cohost_cohost_status_change(request=request, cohost=participant.user, - event=event, status='Make cohost') + event=event, status=participant.is_cohost) notification.notify_event_host_cohost_status_change(request=request, cohost=participant.user, event=event, - status='Make cohost') + status=participant.is_cohost) return JsonResponse({'success': 'Cohost added successfully'}) From 08f5c4fd7fd7f216d8cb34508071077827415b34 Mon Sep 17 00:00:00 2001 From: rutvikrj26 Date: Wed, 8 Nov 2023 16:47:25 -0500 Subject: [PATCH 08/14] 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) From 93f1c8b220c3558d7adc12cb32e71265c015c7fa Mon Sep 17 00:00:00 2001 From: rutvikrj26 Date: Wed, 8 Nov 2023 17:02:28 -0500 Subject: [PATCH 09/14] fixed the double equal issue --- .../templates/events/event_applications.html | 70 +++++++++---------- .../templates/events/event_entries.html | 42 ----------- physionet-django/events/views.py | 2 +- 3 files changed, 36 insertions(+), 78 deletions(-) delete mode 100644 physionet-django/events/templates/events/event_entries.html diff --git a/physionet-django/events/templates/events/event_applications.html b/physionet-django/events/templates/events/event_applications.html index 28c9ed6aa4..083cfa00e1 100644 --- a/physionet-django/events/templates/events/event_applications.html +++ b/physionet-django/events/templates/events/event_applications.html @@ -1,37 +1,37 @@
- - - - - - - - - - - - {% for participant in event.participants.all %} - - - - - - + + {% endfor %} + +
UsernameFull nameEmailCredentialedCohost
{{ participant.user.username }}{{ participant.user.get_full_name }}{{ participant.user.email }}{{ participant.user.is_credentialed }} - {% if not event.has_ended %} -
- {% csrf_token %} - - - {% if participant.is_cohost %} - - {% else %} - - {% endif %} -
+ + + + + + + + + + + + {% for participant in event.participants.all %} + + + + + + - - {% endfor %} - -
UsernameFull nameEmailCredentialedCohost
{{ participant.user.username }}{{ participant.user.get_full_name }}{{ participant.user.email }}{{ participant.user.is_credentialed }} + {% if not event.has_ended %} +
+ {% csrf_token %} + + + {% if participant.is_cohost %} + + {% else %} + {% endif %} -
- + + {% endif %} +
+
\ No newline at end of file diff --git a/physionet-django/events/templates/events/event_entries.html b/physionet-django/events/templates/events/event_entries.html deleted file mode 100644 index b365676eda..0000000000 --- a/physionet-django/events/templates/events/event_entries.html +++ /dev/null @@ -1,42 +0,0 @@ -
- - - - - - - - - - - - {% for participant in event.participants.all %} - - - - - - - - {% endfor %} - -
UsernameFull nameEmailCredentialedCohost
{{ participant.user.username }}{{ participant.user.get_full_name }}{{ participant.user.email }}{{ participant.user.get_credentialing_status }} - {% if not event.has_ended %} - {% if participant.is_cohost %} -
- {% csrf_token %} - - - -
- {% else %} -
- {% csrf_token %} - - - -
- {% endif %} - {% endif %} -
-
diff --git a/physionet-django/events/views.py b/physionet-django/events/views.py index ce1a0ef7ee..0b7faf230f 100644 --- a/physionet-django/events/views.py +++ b/physionet-django/events/views.py @@ -254,7 +254,7 @@ def manage_co_hosts(request): event = get_object_or_404(Event, slug=event_slug) if not event.host == user: - error_message = = 'You are not the host of this event' + error_message = 'You are not the host of this event' if event.end_date < datetime.now().date(): error_message = 'You cannot manage co-hosts of an event that has ended' if not event.participants.filter(id=participant_id).exists(): From ff7d936c4625e9845710f41533b29f2d1bf706d3 Mon Sep 17 00:00:00 2001 From: rutvikrj26 Date: Wed, 15 Nov 2023 10:10:49 -0500 Subject: [PATCH 10/14] Fully working events functionality - serialized add/remove pending --- .../templates/console/event_management.html | 127 ++++--- .../templates/events/event_applications.html | 48 ++- .../events/templates/events/event_home.html | 329 ++++++++---------- physionet-django/events/views.py | 22 +- 4 files changed, 272 insertions(+), 254 deletions(-) diff --git a/physionet-django/console/templates/console/event_management.html b/physionet-django/console/templates/console/event_management.html index 8a1cd8bd58..02a9da2c9f 100644 --- a/physionet-django/console/templates/console/event_management.html +++ b/physionet-django/console/templates/console/event_management.html @@ -2,78 +2,77 @@ {% load static %} {% block title %}Event Management{% endblock %} {% block content %} -

{{ event.title }}

-
-
-
Event Details
-
-
-
Event Organizer:
- -
-
-
Category:
-
{{ event.category }}
-
-
-
Created on:
-
{{ event.added_datetime | date:"d M Y" }}
-
-
-
Start Date:
-
{{ event.start_date | date:"d M Y" }}
+

{{ event.title }}

+
+
+
Event Details
+
+
+
Event Organizer:
+ -
-
End Date:
-
{{ event.end_date | date:"d M Y" }}
-
-
-
Allowed Domains:
-
- {% if event.allowed_domains %} - {{ event.allowed_domains }} - {% else %} - {% endif %} -
+
+
+
Category:
+
{{ event.category }}
+
+
+
Created on:
+
{{ event.added_datetime | date:"d M Y" }}
+
+
+
Start Date:
+
{{ event.start_date | date:"d M Y" }}
+
+
+
End Date:
+
{{ event.end_date | date:"d M Y" }}
+
+
+
Allowed Domains:
+
+ {% if event.allowed_domains %} + {{ event.allowed_domains }} + {% else %} + {% endif %}
-
-
Total participants:
-
-
-
{{ event.participants.count }}
-
- -
+
+
+
Total participants:
+
+
+
{{ event.participants.count }}
+
+
-
-
Description:
-
{{ event.description }}
-
+
+
+
Description:
+
{{ event.description }}
- {% include 'console/event_management_manage_dataset.html' %} - + +{% block local_js_bottom %} + +{% endblock %} \ No newline at end of file diff --git a/physionet-django/events/templates/events/event_home.html b/physionet-django/events/templates/events/event_home.html index c583fa6c7f..34b0f6b802 100644 --- a/physionet-django/events/templates/events/event_home.html +++ b/physionet-django/events/templates/events/event_home.html @@ -16,221 +16,188 @@ {% include "message_snippet.html" %}

Events Home

- {% if can_change_event %} -

Create new events and access event details.

-

- - Create New Event -

- {% else %} -

View events that you have registered to attend.

- {% endif %} -
+ {% if can_change_event %} +

Create new events and access event details.

+

+ + Create New Event +

+ {% else %} +

View events that you have registered to attend.

+ {% endif %} +
-