manager: mark events that are out of booking period (#13382)
This commit is contained in:
parent
1f89a542f6
commit
89a452d924
|
@ -177,6 +177,14 @@ class Event(models.Model):
|
|||
(self.booked_places >= self.places and self.waiting_list_places == 0) or
|
||||
(self.waiting_list_places and self.waiting_list >= self.waiting_list_places))
|
||||
|
||||
def in_bookable_period(self):
|
||||
if now() >= (self.start_datetime - datetime.timedelta(days=self.agenda.minimal_booking_delay)):
|
||||
return False
|
||||
if self.agenda.maximal_booking_delay and (
|
||||
now() < (self.start_datetime - datetime.timedelta(days=self.agenda.maximal_booking_delay))):
|
||||
return False
|
||||
return True
|
||||
|
||||
@property
|
||||
def booked_places(self):
|
||||
return self.booking_set.filter(cancellation_datetime__isnull=True,
|
||||
|
|
|
@ -13,6 +13,10 @@
|
|||
background: #e33;
|
||||
}
|
||||
|
||||
li.not-bookable {
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
li.full {
|
||||
background: #f8f8fe;
|
||||
}
|
||||
|
|
|
@ -37,7 +37,8 @@
|
|||
<ul class="objects-list single-links">
|
||||
{% for event in object.event_set.all %}
|
||||
<li class="{% if event.booked_places > event.places %}overbooking{% endif %}
|
||||
{% if event.full %}full{% endif %}"
|
||||
{% if event.full %}full{% endif %}
|
||||
{% if not event.in_bookable_period %}not-{% endif %}bookable"
|
||||
{% if event.places %}
|
||||
data-total="{{event.places}}" data-booked="{{event.booked_places}}"
|
||||
{% elif event.waiting_list_places %}
|
||||
|
@ -58,6 +59,9 @@
|
|||
{% endblocktrans %}
|
||||
{% endif %}
|
||||
)
|
||||
{% if not event.in_bookable_period %}
|
||||
({% trans "out of bookable period" %})
|
||||
{% endif %}
|
||||
</a>
|
||||
<span class="occupation-bar"></span>
|
||||
</li>
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import pytest
|
||||
import datetime
|
||||
|
||||
from django.utils.timezone import now
|
||||
|
||||
|
@ -39,3 +40,17 @@ def test_event_manager():
|
|||
booking.cancellation_datetime = now()
|
||||
booking.save()
|
||||
assert Event.objects.all()[0].booked_places == 0
|
||||
|
||||
def test_event_bookable_period():
|
||||
agenda = Agenda(label=u'Foo bar')
|
||||
agenda.save()
|
||||
event = Event(start_datetime=now() + datetime.timedelta(days=10), places=10, agenda=agenda)
|
||||
event.save()
|
||||
assert event.in_bookable_period() is True
|
||||
agenda.minimal_booking_delay = 20
|
||||
assert event.in_bookable_period() is False
|
||||
agenda.minimal_booking_delay = 1
|
||||
agenda.maximal_booking_delay = 5
|
||||
assert event.in_bookable_period() is False
|
||||
agenda.maximal_booking_delay = 20
|
||||
assert event.in_bookable_period() is True
|
||||
|
|
|
@ -78,25 +78,37 @@ def test_agendas_api(app, some_data):
|
|||
def test_datetimes_api(app, some_data):
|
||||
agenda = Agenda.objects.filter(label=u'Foo bar')[0]
|
||||
agenda_id = agenda.id
|
||||
|
||||
def check_bookability(data):
|
||||
for event in data:
|
||||
assert Event.objects.get(id=event['id']).in_bookable_period()
|
||||
for event in agenda.event_set.all():
|
||||
if not event.in_bookable_period():
|
||||
assert not event.id in [x['id'] for x in data]
|
||||
|
||||
resp = app.get('/api/agenda/%s/datetimes/' % agenda_id)
|
||||
assert 'data' in resp.json
|
||||
assert len(resp.json['data']) == 3
|
||||
check_bookability(resp.json['data'])
|
||||
|
||||
agenda.minimal_booking_delay = 5
|
||||
agenda.save()
|
||||
resp = app.get('/api/agenda/%s/datetimes/' % agenda_id)
|
||||
assert len(resp.json['data']) == 0
|
||||
check_bookability(resp.json['data'])
|
||||
|
||||
agenda.minimal_booking_delay = 2
|
||||
agenda.save()
|
||||
resp = app.get('/api/agenda/%s/datetimes/' % agenda_id)
|
||||
assert len(resp.json['data']) == 2
|
||||
check_bookability(resp.json['data'])
|
||||
|
||||
agenda.minimal_booking_delay = 0
|
||||
agenda.maximal_booking_delay = 3
|
||||
agenda.save()
|
||||
resp = app.get('/api/agenda/%s/datetimes/' % agenda_id)
|
||||
assert len(resp.json['data']) == 2
|
||||
check_bookability(resp.json['data'])
|
||||
|
||||
def test_datetimes_api_wrong_kind(app, some_data):
|
||||
agenda = Agenda.objects.filter(label=u'Foo bar')[0]
|
||||
|
|
Loading…
Reference in New Issue