...
 
Commits (3)
......@@ -38,8 +38,7 @@ class EventFeed(ICalFeed):
query = Q(published=True)
if self.user:
query &= (Q(registration_start__isnull=True) |
Q(registration__member=self.user))
query &= Q(registration__member=self.user)
return Event.objects.filter(query).order_by('-start')
......
......@@ -224,14 +224,16 @@ class Event(models.Model, metaclass=ModelTranslateMeta):
@property
def registration_allowed(self):
now = timezone.now()
return ((self.registration_start or self.registration_end) and
self.registration_end > now >= self.registration_start)
if self.registration_start or self.registration_end:
return self.registration_end > now >= self.registration_start
return self.end > now
@property
def cancellation_allowed(self):
now = timezone.now()
return ((self.registration_start or self.registration_end)
and self.registration_start <= now < self.start)
if self.registration_start or self.registration_end:
return self.registration_start <= now < self.start
return self.end > now
def is_pizza_event(self):
try:
......@@ -518,7 +520,7 @@ class Registration(models.Model):
def would_cancel_after_deadline(self):
now = timezone.now()
return (self.queue_position == 0 and
return (self.event.cancel_deadline and self.queue_position == 0 and
now >= self.event.cancel_deadline)
def clean(self):
......
......@@ -131,6 +131,7 @@
</form>
{% endif %}
{% if permissions.create_registration %}
{% if event.registration_required %}
<p>
{% url 'event-registration-terms' as terms_url %}
{% blocktrans trimmed %}
......@@ -140,27 +141,33 @@
that you understand them and that you agree to be bound by them.
{% endblocktrans %}
</p>
{% endif %}
<form action="{% url 'events:register' event.id %}" method="post">{% csrf_token %}
{% if event.reached_participants_limit %}
{% if event.reached_participants_limit and event.registration_required %}
<input type="submit" class="btn btn-primary"
value="{% trans "Put me on the waiting list" %}"/>
{% else %}
{% elif event.registration_required %}
<input type="submit" class="btn btn-primary"
value="{% trans "Register" %}"/>
{% else %}
<input type="submit" class="btn btn-primary"
value="{% trans "I'm going" %}"/>
{% endif %}
</form>
{% elif permissions.cancel_registration %}
{# Special message to accept costs when cancelling after the deadline, unless member is on the waiting list #}
<form action="{% url 'events:cancel' event.id %}" method="post">{% csrf_token %}
{% if registration.would_cancel_after_deadline %}
{% if registration.would_cancel_after_deadline and event.registration_required %}
<input type="submit" class="btn btn-primary"
value="{% trans "Cancel registration" %}"
onclick="return confirm('{% blocktrans trimmed with costs=event.fine %}The deadline has passed, are you sure you want to cancel your registration and pay the estimated full costs of €{{ costs }}? You will not be able to undo this!{% endblocktrans %}');"/>
{% else %}
{% elif event.registration_required %}
<input type="submit" class="btn btn-primary"
value="{% trans "Cancel registration" %}"
onclick="return confirm('{% trans 'Are you sure you want to cancel your registration?' %}');"/>
{% else %}
<input type="submit" class="btn btn-primary"
value="{% trans "Cancel registration" %}" />
{% endif %}
</form>
{% elif request.user.is_authenticated is False %}
......
......@@ -44,8 +44,8 @@ class RegistrationApiTest(TestCase):
def test_registration_register_not_required(self):
response = self.client.post('/api/v1/events/1/registrations/',
follow=True)
self.assertEqual(response.status_code, 403)
self.assertEqual(self.event.participants.count(), 0)
self.assertEqual(response.status_code, 201)
self.assertEqual(self.event.participants.count(), 1)
def test_registration_register(self):
self.event.registration_start = (timezone.now() -
......
......@@ -196,7 +196,7 @@ class EventTest(TestCase):
self.event.registration_start = None
self.event.registration_end = None
self.event.cancel_deadline = None
self.assertFalse(self.event.registration_allowed)
self.assertTrue(self.event.registration_allowed)
def test_missing_orgination_mailinglist(self):
self.event.clean()
......@@ -269,7 +269,7 @@ class EventTest(TestCase):
self.event.registration_start = None
self.event.registration_end = None
self.event.cancel_deadline = None
self.assertFalse(self.event.cancellation_allowed)
self.assertTrue(self.event.cancellation_allowed)
class RegistrationTest(TestCase):
......
......@@ -168,7 +168,7 @@ class RegistrationTest(TestCase):
response = self.client.post('/events/1/registration/register/',
follow=True)
self.assertEqual(response.status_code, 200)
self.assertEqual(self.event.participants.count(), 0)
self.assertEqual(self.event.participants.count(), 1)
def test_registration_register(self):
self.event.registration_start = (timezone.now() -
......