Skip to content

Commit

Permalink
addressed comments - made the template more consistent & fixed the is…
Browse files Browse the repository at this point in the history
…_ajax depreceation issue
  • Loading branch information
Rutvikrj26 committed Oct 11, 2023
1 parent f807fc8 commit 879a047
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ <h5 class="modal-title">Participants</h5>
<span aria-hidden="true">&times;</span>
</button>
</div>
{% include 'events/event_entries.html' %}
{% include 'events/event_applications.html' %}
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 37 additions & 0 deletions physionet-django/events/templates/events/event_applications.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<div class="table-responsive">
<table class="table table-bordered">
<thead>
<tr>
<th>Username</th>
<th>Full name</th>
<th>Email</th>
<th>Credentialed</th>
<th>Cohost</th>
</tr>
</thead>
<tbody>
{% for participant in event.participants.all %}
<tr>
<td>{{ participant.user.username }}</td>
<td>{{ participant.user.get_full_name }}</td>
<td>{{ participant.user.email }}</td>
<td>{{ participant.user.is_credentialed }}</td>
<td>
{% if not event.has_ended %}
<form class="manage-cohost" action="{% url 'manage_co_hosts' %}">
{% csrf_token %}
<input type="text" name="event" value="{{ event.slug }}" hidden>
<input type="text" name="participant" value="{{ participant.id }}" hidden>
{% if participant.is_cohost %}
<input type="submit" value="Remove cohost" class="btn btn-sm btn-danger">
{% else %}
<input type="submit" value="Make cohost" class="btn btn-sm btn-success">
{% endif %}
</form>
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
4 changes: 2 additions & 2 deletions physionet-django/events/templates/events/event_home.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ <h5 class="modal-title">Participants</h5>
<span aria-hidden="true">&times;</span>
</button>
</div>
{% include 'events/event_entries.html' %}
{% include 'events/event_applications.html' %}
</div>
</div>
</div>
Expand Down Expand Up @@ -178,7 +178,7 @@ <h5 class="modal-title">Participants</h5>
<span aria-hidden="true">&times;</span>
</button>
</div>
{% include 'events/event_entries.html' %}
{% include 'events/event_applications.html' %}
</div>
</div>
</div>
Expand Down
6 changes: 1 addition & 5 deletions physionet-django/events/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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')

Expand All @@ -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')

Expand Down
9 changes: 4 additions & 5 deletions physionet-django/notification/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
from email.utils import formataddr
from functools import cache
import re
from urllib import parse

from django.conf import settings
Expand Down Expand Up @@ -1006,17 +1007,16 @@ 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.
"""
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]),
'event_url': request.build_absolute_uri(reverse('event_detail', args=[event.slug])),
'status': status,
'SITE_NAME': settings.SITE_NAME,
}
Expand All @@ -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,
}
Expand Down

0 comments on commit 879a047

Please sign in to comment.