Verified Commit 9f83a090 authored by Sébastiaan Versteeg's avatar Sébastiaan Versteeg
Browse files

Fix message for cancelling after deadline and reduce template complexity

parent ae728405
......@@ -366,6 +366,11 @@ class Registration(models.Model):
date__lte=self.date
).count() - self.event.max_participants, 0)
def would_cancel_after_deadline(self):
return (self.queue_position() == 0 and
(self.event.status == Event.REGISTRATION_CLOSED or
self.event.status == Event.REGISTRATION_OPEN_NO_CANCEL))
def clean(self):
if ((self.member is None and not self.name) or
(self.member and self.name)):
......
......@@ -92,42 +92,36 @@
<tr>
<td></td>
<td>
{% if request.user.is_authenticated and request.user.member is not None and request.user.member.current_membership is not None and request.user.member.can_attend_events %}
{% if event.status == event.REGISTRATION_OPEN or event.status == event.REGISTRATION_OPEN_NO_CANCEL %}
{% if user_registration_allowed %}
{% if can_update_event_registration %}
{% if registration is not None and registration.date_cancelled is None and event.has_fields %}
<form action="{% url 'events:registration' event.id 'update' %}" method="post">{% csrf_token %}
<input type="submit" class="btn btn-style1" value="{% trans "Update registration" %}" />
</form>
{% endif %}
{% endif %}
{% if event.status == event.REGISTRATION_OPEN or event.status == event.REGISTRATION_CLOSED_CANCEL_ONLY or event.status == event.REGISTRATION_OPEN_NO_CANCEL %}
{% if registration is None or registration.date_cancelled is not None %}
{% if event.status == event.REGISTRATION_OPEN or event.status == event.REGISTRATION_OPEN_NO_CANCEL %}
<form action="{% url 'events:registration' event.id 'register' %}" method="post">{% csrf_token %}
{% if event.reached_participants_limit %}
<input type="submit" class="btn btn-style1" value="{% trans "Put me on the waiting list" %}" />
{% else %}
{% if can_create_event_registration %}
<form action="{% url 'events:registration' event.id 'register' %}" method="post">{% csrf_token %}
{% if event.reached_participants_limit %}
<input type="submit" class="btn btn-style1" value="{% trans "Put me on the waiting list" %}" />
{% else %}
<input type="submit" class="btn btn-style1" value="{% trans "Register" %}" />
{% endif %}
</form>
<input type="submit" class="btn btn-style1" value="{% trans "Register" %}" />
{% endif %}
{% elif registration is not None and registration.date_cancelled is None %}
{# Special message to accept costs when cancelling after the deadline, unless member is on the waiting list #}
<form action="{% url 'events:registration' event.id 'cancel' %}" method="post">{% csrf_token %}
{% if event.reached_participants_limit %}
<input type="submit" class="btn btn-style1" value="{% trans "Cancel registration" %}" onclick="return confirm('{% blocktrans with costs=event.fine %}The deadline has passed, are you sure you want to cancel your registration and pay the full costs of €{{ costs }}? You will not be able to undo this!{% endblocktrans %}');" />
{% else %}
<input type="submit" class="btn btn-style1" value="{% trans "Cancel registration" %}" />
{% endif %}
</form>
{% endif %}
</form>
{% elif can_cancel_event_registration %}
{# Special message to accept costs when cancelling after the deadline, unless member is on the waiting list #}
<form action="{% url 'events:registration' event.id 'cancel' %}" method="post">{% csrf_token %}
{% if registration.would_cancel_after_deadline %}
<input type="submit" class="btn btn-style1" value="{% trans "Cancel registration" %}" onclick="return confirm('{% blocktrans with costs=event.fine %}The deadline has passed, are you sure you want to cancel your registration and pay the full costs of €{{ costs }}? You will not be able to undo this!{% endblocktrans %}');" />
{% else %}
<input type="submit" class="btn btn-style1" value="{% trans "Cancel registration" %}" />
{% endif %}
</form>
{% endif %}
{% elif request.user.is_authenticated is False %}
<a class="btn btn-style1" href="{% url 'login' %}?next={{ request.path }}">{% trans "Login" %}</a>
{% endif %}
</form>
</td>
</tr>
<tr>
......
......@@ -217,3 +217,20 @@ class RegistrationTest(TestCase):
name='test name',
member=self.member)
r3.clean()
def test_would_cancel_after_deadline(self):
self.event.registration_start = (timezone.now() -
datetime.timedelta(hours=1))
self.event.registration_end = (timezone.now() -
datetime.timedelta(hours=1))
self.event.cancel_deadline = (timezone.now() -
datetime.timedelta(hours=1))
# Test situation where the event status is REGISTRATION_CLOSED
self.assertEqual(self.r1.would_cancel_after_deadline(), True)
self.event.registration_end = (timezone.now() +
datetime.timedelta(hours=2))
# Test situation where the event status is REGISTRATION_OPEN_NO_CANCEL
self.assertEqual(self.r1.would_cancel_after_deadline(), True)
......@@ -171,6 +171,7 @@ def event(request, event_id):
perc = 100.0 * len(registrations) / event.max_participants
context['registration_percentage'] = perc
registration = None
try:
registration = Registration.objects.get(
event=event,
......@@ -180,6 +181,22 @@ def event(request, event_id):
except (Registration.DoesNotExist, AttributeError):
pass
context['user_registration_allowed'] = (
request.user.is_authenticated and request.user.member is not None and
request.user.member.current_membership is not None and
request.user.member.can_attend_events)
context['can_create_event_registration'] = (
(registration is None or registration.date_cancelled is not None) and
(event.status == event.REGISTRATION_OPEN or
event.status == event.REGISTRATION_OPEN_NO_CANCEL))
context['can_cancel_event_registration'] = (
registration is not None and registration.date_cancelled is None and
(event.status == event.REGISTRATION_OPEN or
event.status == event.REGISTRATION_CLOSED_CANCEL_ONLY))
context['can_update_event_registration'] = (
event.status == event.REGISTRATION_OPEN or
event.status == event.REGISTRATION_OPEN_NO_CANCEL)
return render(request, 'events/event.html', context)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment