Skip to content

Commit

Permalink
only allow to add cohost to active event
Browse files Browse the repository at this point in the history
  • Loading branch information
superryeti committed Mar 8, 2023
1 parent 38a86ad commit 22e430d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
6 changes: 6 additions & 0 deletions physionet-django/events/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
32 changes: 17 additions & 15 deletions physionet-django/events/templates/events/event_entries.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,23 @@
<td>{{ participant.user.email }}</td>
<td>{{ participant.user.is_credentialed }}</td>
<td>
{% if participant.is_cohost %}
<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>
<input type="submit" value="Remove cohost" class="btn btn-sm btn-danger">
</form>
{% else %}
<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>
<input type="submit" value="Make cohost" class="btn btn-sm btn-success">
</form>
{% endif %}
{% if not event.has_ended %}
{% if participant.is_cohost %}
<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>
<input type="submit" value="Remove cohost" class="btn btn-sm btn-danger">
</form>
{% else %}
<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>
<input type="submit" value="Make cohost" class="btn btn-sm btn-success">
</form>
{% endif %}
{% endif %}
</td>
</tr>
{% endfor %}
Expand Down

0 comments on commit 22e430d

Please sign in to comment.