api: include full events in /datetimes/ API, with a disabled attribute (#13037)

This commit is contained in:
Frédéric Péters 2016-10-09 11:37:51 +02:00
parent 89a452d924
commit 948bb3d003
2 changed files with 12 additions and 9 deletions

View File

@ -52,14 +52,15 @@ class Datetimes(GenericAPIView):
raise APIException('not an events agenda')
kwargs = {}
kwargs['full'] = False
kwargs['start_datetime__gte'] = (now() + datetime.timedelta(days=agenda.minimal_booking_delay)).date()
if agenda.maximal_booking_delay:
kwargs['start_datetime__lt'] = (now() + datetime.timedelta(days=agenda.maximal_booking_delay)).date()
entries = Event.objects.filter(agenda=pk).filter(**kwargs)
response = {'data': [{'id': x.id, 'text': unicode(x)} for x in entries]}
response = {'data': [{'id': x.id,
'text': unicode(x),
'disabled': bool(x.full)} for x in entries]}
return Response(response)
datetimes = Datetimes.as_view()

View File

@ -263,15 +263,16 @@ def test_soldout(app, some_data, user):
event = Event.objects.filter(agenda_id=agenda_id).exclude(start_datetime__lt=now())[0]
resp = app.get('/api/agenda/%s/datetimes/' % agenda_id)
assert len(resp.json['data']) == 3
assert len([x for x in resp.json['data'] if not x.get('disabled')]) == 3
assert event.id in [x['id'] for x in resp.json['data']]
for i in range(event.places):
Booking(event=event).save()
resp = app.get('/api/agenda/%s/datetimes/' % agenda_id)
assert len(resp.json['data']) == 2
assert not event.id in [x['id'] for x in resp.json['data']]
assert len([x for x in resp.json['data'] if not x.get('disabled')]) == 2
assert not event.id in [x['id'] for x in resp.json['data'] if not x.get('disabled')]
assert event.id in [x['id'] for x in resp.json['data'] if x.get('disabled')]
app.authorization = ('Basic', ('john.doe', 'password'))
resp = app.post('/api/agenda/%s/fillslot/%s/' % (agenda_id, event.id), status=200)
@ -310,7 +311,7 @@ def test_waiting_list_datetimes(app, some_data, user):
event.save()
resp = app.get('/api/agenda/%s/datetimes/' % agenda_id)
assert len(resp.json['data']) == 3
assert len([x for x in resp.json['data'] if not x.get('disabled')]) == 3
assert event.id in [x['id'] for x in resp.json['data']]
for i in range(event.places):
@ -319,7 +320,7 @@ def test_waiting_list_datetimes(app, some_data, user):
# all places are booked but all the dates are still displayed as there is a
# waiting list.
resp = app.get('/api/agenda/%s/datetimes/' % agenda_id)
assert len(resp.json['data']) == 3
assert len([x for x in resp.json['data'] if not x.get('disabled')]) == 3
# fill the waiting list
for i in range(event.waiting_list_places):
@ -327,8 +328,9 @@ def test_waiting_list_datetimes(app, some_data, user):
# the event datetime should no longer be returned
resp = app.get('/api/agenda/%s/datetimes/' % agenda_id)
assert len(resp.json['data']) == 2
assert not event.id in [x['id'] for x in resp.json['data']]
assert len([x for x in resp.json['data'] if not x.get('disabled')]) == 2
assert not event.id in [x['id'] for x in resp.json['data'] if not x.get('disabled')]
assert event.id in [x['id'] for x in resp.json['data'] if x.get('disabled')]
def test_waiting_list_booking(app, some_data, user):
agenda_id = Agenda.objects.filter(label=u'Foo bar')[0].id