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

Fix 'post' check so that it works in tests

parent cf204740
......@@ -95,33 +95,39 @@
{% 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 registration is not None and registration.date_cancelled is None and event.has_fields %}
<a class="btn btn-style1" href="{% url 'events:registration' event.id 'update' %}">{% trans "Update registration" %}</a>
<br /><br />
<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 %}
<a class="btn btn-style1" href="{% url 'events:registration' event.id 'register' %}">
<form action="{% url 'events:registration' event.id 'register' %}" method="post">{% csrf_token %}
{% if event.reached_participants_limit %}
{% trans "Put me on the waiting list" %}
<input type="submit" class="btn btn-style1" value="{% trans "Put me on the waiting list" %}" />
{% else %}
{% trans "Register" %}
<input type="submit" class="btn btn-style1" value="{% trans "Register" %}" />
{% endif %}
</a>
</form>
{% 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 #}
{% if registration.queue_position == 0 and event.after_cancel_deadline %}
<a class="btn btn-style1" href="{% url 'events:registration' event.id 'cancel' %}" 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 %}');">{% trans "Cancel registration" %}</a>
{% else %}
<a class="btn btn-style1" href="{% url 'events:registration' event.id 'cancel' %}" onclick="return confirm('{% trans "Are you sure you want to cancel your registration?" %}');">{% trans "Cancel registration" %}</a>
{% endif %}
<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 %}
{% 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>
......
......@@ -66,7 +66,7 @@ class RegistrationTest(TestCase):
response = self.client.post('/events/1/registration/register/',
follow=True)
self.assertEqual(response.status_code, 200)
response = self.client.post('/events/1/registration/register',
response = self.client.post('/events/1/registration/register/',
follow=True)
self.assertEqual(response.status_code, 200)
self.assertEqual(self.event.num_participants(), 1)
......
......@@ -175,7 +175,7 @@ def event(request, event_id):
def _send_queue_mail(event):
if (event.max_participants is not None and
Registration.objects
Registration.objects
.filter(event=event, date_cancelled=None)
.count() > event.max_participants):
# Prepare email to send to the first person on the waiting
......@@ -214,7 +214,7 @@ def _show_registration_fields(request, event, reg, action):
for field in form_field_values:
if (field['field'].type ==
RegistrationInformationField.INTEGER_FIELD and
field['value'] is None):
field['value'] is None):
field['value'] = 0
field['field'].set_value_for(reg,
field['value'])
......@@ -228,11 +228,11 @@ def _registration_register(request, event, reg):
reg = Registration()
reg.event = event
reg.member = request.user.member
messages.success(request, _("Registration successful."))
if event.has_fields():
return _show_registration_fields(request, event, reg, 'register')
else:
reg.save()
messages.success(request, _("Registration successful."))
elif reg.date_cancelled is not None:
if reg.is_late_cancellation():
messages.error(request, _("You cannot re-register anymore since "
......@@ -240,16 +240,22 @@ def _registration_register(request, event, reg):
else:
reg.date = timezone.now()
reg.date_cancelled = None
messages.success(request, _("Registration successful."))
if event.has_fields():
return _show_registration_fields(request, event, reg,
'register')
else:
reg.save()
messages.success(request, _("Registration successful."))
elif not reg.member.can_attend_events:
messages.error(request, _("You may not register"))
else:
messages.error(request, _("You were already registered."))
storage = messages.get_messages(request)
was_success = False
for message in storage:
was_success = message.message == _("Registration successful.")
storage.used = False
if not was_success:
messages.error(request, _("You were already registered."))
return redirect(event)
......@@ -300,18 +306,18 @@ def registration(request, event_id, action=None):
except Registration.DoesNotExist:
reg = None
if request.POST:
if request.method.lower() == 'post':
if action == 'register' and (
event.status == Event.REGISTRATION_OPEN or
event.status == Event.REGISTRATION_OPEN_NO_CANCEL
):
_registration_register(request, event, reg)
return _registration_register(request, event, reg)
elif (action == 'update' and
(event.status == Event.REGISTRATION_OPEN or
event.status == Event.REGISTRATION_OPEN_NO_CANCEL)):
_registration_update(request, event, reg)
return _registration_update(request, event, reg)
elif action == 'cancel':
_registration_cancel(request, event, reg)
return _registration_cancel(request, event, reg)
return redirect(event)
......
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