api: always return urls with slugs (#46758)
This commit is contained in:
parent
1995cc18e4
commit
4ed8c9ce00
|
@ -409,8 +409,8 @@ class Datetimes(APIView):
|
|||
response = {
|
||||
'data': [
|
||||
{
|
||||
'id': x.id,
|
||||
'slug': x.slug,
|
||||
'id': x.slug,
|
||||
'slug': x.slug, # kept for compatibility
|
||||
'text': force_text(x),
|
||||
'datetime': format_response_datetime(x.start_datetime),
|
||||
'description': x.description,
|
||||
|
@ -514,7 +514,7 @@ class MeetingDatetimes(APIView):
|
|||
It MUST be a garanty of SharedTimePeriod.get_time_slots(),
|
||||
!!!
|
||||
'''
|
||||
return '%s:%s' % (meeting_type.id or meeting_type.slug, start_datetime.strftime('%Y-%m-%d-%H%M'),)
|
||||
return '%s:%s' % (meeting_type.slug, start_datetime.strftime('%Y-%m-%d-%H%M'),)
|
||||
|
||||
response = {
|
||||
'data': [
|
||||
|
@ -813,10 +813,11 @@ class Fillslots(APIView):
|
|||
|
||||
# get all free slots and separate them by desk
|
||||
try:
|
||||
all_slots = sorted(
|
||||
get_all_slots(agenda, agenda.get_meetingtype(id_=meeting_type_id), resources=resources),
|
||||
key=lambda slot: slot.start_datetime,
|
||||
)
|
||||
try:
|
||||
meeting_type = agenda.get_meetingtype(slug=meeting_type_id)
|
||||
except MeetingType.DoesNotExist:
|
||||
# legacy access by id
|
||||
meeting_type = agenda.get_meetingtype(id_=meeting_type_id)
|
||||
except (MeetingType.DoesNotExist, ValueError):
|
||||
return Response(
|
||||
{
|
||||
|
@ -826,6 +827,10 @@ class Fillslots(APIView):
|
|||
},
|
||||
status=status.HTTP_400_BAD_REQUEST,
|
||||
)
|
||||
all_slots = sorted(
|
||||
get_all_slots(agenda, meeting_type, resources=resources),
|
||||
key=lambda slot: slot.start_datetime,
|
||||
)
|
||||
|
||||
all_free_slots = [slot for slot in all_slots if not slot.full]
|
||||
datetimes_by_desk = collections.defaultdict(set)
|
||||
|
@ -894,9 +899,7 @@ class Fillslots(APIView):
|
|||
|
||||
# get a real meeting_type for virtual agenda
|
||||
if agenda.kind == 'virtual':
|
||||
meeting_type_id = MeetingType.objects.get(
|
||||
agenda=available_desk.agenda, slug=meeting_type_id
|
||||
).pk
|
||||
meeting_type = MeetingType.objects.get(agenda=available_desk.agenda, slug=meeting_type.slug)
|
||||
|
||||
# booking requires real Event objects (not lazy Timeslots);
|
||||
# create them now, with data from the slots and the desk we found.
|
||||
|
@ -905,7 +908,7 @@ class Fillslots(APIView):
|
|||
event = Event.objects.create(
|
||||
agenda=available_desk.agenda,
|
||||
slug=str(uuid.uuid4()), # set slug to avoid queries during slug generation
|
||||
meeting_type_id=meeting_type_id,
|
||||
meeting_type=meeting_type,
|
||||
start_datetime=start_datetime,
|
||||
full=False,
|
||||
places=1,
|
||||
|
|
|
@ -297,10 +297,10 @@ def test_datetimes_api(app, some_data):
|
|||
|
||||
def check_bookability(data):
|
||||
for event in data:
|
||||
assert Event.objects.get(id=event['id']).in_bookable_period()
|
||||
assert Event.objects.get(slug=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]
|
||||
assert event.slug not in [x['id'] for x in data]
|
||||
|
||||
resp = app.get('/api/agenda/xxx/datetimes/', status=404)
|
||||
|
||||
|
@ -738,7 +738,7 @@ def test_booking_api(app, some_data, user):
|
|||
|
||||
for agenda_key in (agenda.slug, agenda.id): # acces datetimes via agenda slug or id (legacy)
|
||||
resp_datetimes = app.get('/api/agenda/%s/datetimes/' % agenda_key)
|
||||
event_fillslot_url = [x for x in resp_datetimes.json['data'] if x['id'] == event.id][0]['api'][
|
||||
event_fillslot_url = [x for x in resp_datetimes.json['data'] if x['id'] == event.slug][0]['api'][
|
||||
'fillslot_url'
|
||||
]
|
||||
assert urlparse.urlparse(event_fillslot_url).path == '/api/agenda/%s/fillslot/%s/' % (
|
||||
|
@ -948,8 +948,8 @@ def test_booking_api_fillslots(app, some_data, user):
|
|||
|
||||
for agenda_key in (agenda.slug, agenda.id): # acces datetimes via agenda slug or id (legacy)
|
||||
resp_datetimes = app.get('/api/agenda/%s/datetimes/' % agenda_key)
|
||||
api_event_ids = [x['id'] for x in resp_datetimes.json['data']]
|
||||
assert api_event_ids == events_ids
|
||||
api_event_slugs = [x['id'] for x in resp_datetimes.json['data']]
|
||||
assert api_event_slugs == events_slugs
|
||||
|
||||
assert Booking.objects.count() == 0
|
||||
|
||||
|
@ -1699,15 +1699,15 @@ def test_soldout(app, some_data, user):
|
|||
|
||||
resp = app.get('/api/agenda/%s/datetimes/' % agenda_id)
|
||||
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']]
|
||||
assert event.slug 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([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')]
|
||||
assert event.slug not in [x['id'] for x in resp.json['data'] if not x.get('disabled')]
|
||||
assert event.slug 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)
|
||||
|
@ -1886,7 +1886,7 @@ def test_waiting_list_datetimes(app, some_data, user):
|
|||
|
||||
resp = app.get('/api/agenda/%s/datetimes/' % agenda_id)
|
||||
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']]
|
||||
assert event.slug in [x['id'] for x in resp.json['data']]
|
||||
|
||||
for i in range(event.places):
|
||||
Booking(event=event).save()
|
||||
|
@ -1903,8 +1903,8 @@ 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([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')]
|
||||
assert event.slug not in [x['id'] for x in resp.json['data'] if not x.get('disabled')]
|
||||
assert event.slug in [x['id'] for x in resp.json['data'] if x.get('disabled')]
|
||||
|
||||
|
||||
def test_waiting_list_booking(app, some_data, user):
|
||||
|
@ -2290,7 +2290,7 @@ def test_multiple_booking_api(app, some_data, user):
|
|||
event = [x for x in Event.objects.filter(agenda=agenda) if x.in_bookable_period()][0]
|
||||
|
||||
resp_datetimes = app.get('/api/agenda/%s/datetimes/' % agenda.id)
|
||||
event_fillslot_url = [x for x in resp_datetimes.json['data'] if x['id'] == event.id][0]['api'][
|
||||
event_fillslot_url = [x for x in resp_datetimes.json['data'] if x['id'] == event.slug][0]['api'][
|
||||
'fillslot_url'
|
||||
]
|
||||
|
||||
|
@ -2386,9 +2386,9 @@ def test_multiple_booking_api_fillslots(app, some_data, user):
|
|||
events = [
|
||||
x for x in Event.objects.filter(agenda=agenda).order_by('start_datetime') if x.in_bookable_period()
|
||||
][:2]
|
||||
events_ids = [x.id for x in events]
|
||||
events_slugs = [x.slug for x in events]
|
||||
resp_datetimes = app.get('/api/agenda/%s/datetimes/' % agenda.id)
|
||||
slots = [x['id'] for x in resp_datetimes.json['data'] if x['id'] in events_ids]
|
||||
slots = [x['id'] for x in resp_datetimes.json['data'] if x['id'] in events_slugs]
|
||||
|
||||
app.authorization = ('Basic', ('john.doe', 'password'))
|
||||
resp = app.post('/api/agenda/%s/fillslots/?count=NaN' % agenda.slug, params={'slots': slots}, status=400)
|
||||
|
@ -2505,9 +2505,9 @@ def test_multiple_booking_move_booking(app, user):
|
|||
events.append(event)
|
||||
|
||||
first_two_events = events[:2]
|
||||
events_ids = [x.id for x in first_two_events]
|
||||
events_slugs = [x.slug for x in first_two_events]
|
||||
resp_datetimes = app.get('/api/agenda/%s/datetimes/' % agenda.id)
|
||||
slots = [x['id'] for x in resp_datetimes.json['data'] if x['id'] in events_ids]
|
||||
slots = [x['id'] for x in resp_datetimes.json['data'] if x['id'] in events_slugs]
|
||||
|
||||
app.authorization = ('Basic', ('john.doe', 'password'))
|
||||
|
||||
|
@ -2520,9 +2520,9 @@ def test_multiple_booking_move_booking(app, user):
|
|||
|
||||
# change, 1 place on 2 other slots
|
||||
last_two_events = events[-2:]
|
||||
events_ids = [x.id for x in last_two_events]
|
||||
events_slugs = [x.slug for x in last_two_events]
|
||||
resp_datetimes = app.get('/api/agenda/%s/datetimes/' % agenda.id)
|
||||
slots = [x['id'] for x in resp_datetimes.json['data'] if x['id'] in events_ids]
|
||||
slots = [x['id'] for x in resp_datetimes.json['data'] if x['id'] in events_slugs]
|
||||
|
||||
resp = app.post(
|
||||
'/api/agenda/%s/fillslots/' % agenda.slug, params={'slots': slots, 'cancel_booking_id': booking.pk}
|
||||
|
|
Loading…
Reference in New Issue