Agenda virtuel : ajouter des infos sur les agendas concernés dans les appels à datetime (#78064) #92
|
@ -801,25 +801,55 @@ class MeetingDatetimes(APIView):
|
||||||
# slot from the list if there is still a bookable slot on a desk at the
|
# slot from the list if there is still a bookable slot on a desk at the
|
||||||
# same time.
|
# same time.
|
||||||
# The generator also remove slots starting before the current time.
|
# The generator also remove slots starting before the current time.
|
||||||
def unique_slots():
|
if agenda.kind == 'meetings':
|
||||||
last_slot = None
|
|
||||||
all_slots = list(
|
def unique_slots():
|
||||||
agenda.get_all_slots(
|
last_slot = None
|
||||||
meeting_type,
|
all_slots = list(
|
||||||
resources=resources,
|
agenda.get_all_slots(
|
||||||
unique=True,
|
meeting_type,
|
||||||
start_datetime=start_datetime,
|
resources=resources,
|
||||||
end_datetime=end_datetime,
|
unique=True,
|
||||||
user_external_id=booked_user_external_id or excluded_user_external_id,
|
start_datetime=start_datetime,
|
||||||
|
end_datetime=end_datetime,
|
||||||
|
user_external_id=booked_user_external_id or excluded_user_external_id,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
for slot in sorted(all_slots, key=lambda slot: slot[:3]):
|
||||||
for slot in sorted(all_slots, key=lambda slot: slot[:3]):
|
if slot.start_datetime < now_datetime:
|
||||||
if slot.start_datetime < now_datetime:
|
continue
|
||||||
continue
|
if last_slot and last_slot[:2] == slot[:2]:
|
||||||
if last_slot and last_slot[:2] == slot[:2]:
|
continue
|
||||||
continue
|
last_slot = slot
|
||||||
last_slot = slot
|
yield slot, None
|
||||||
yield slot
|
|
||||||
|
elif agenda.kind == 'virtual':
|
||||||
|
|
||||||
|
def unique_slots():
|
||||||
|
all_slots = list(
|
||||||
|
agenda.get_all_slots(
|
||||||
|
meeting_type,
|
||||||
|
resources=resources,
|
||||||
|
unique=False,
|
||||||
|
start_datetime=start_datetime,
|
||||||
|
end_datetime=end_datetime,
|
||||||
|
user_external_id=booked_user_external_id or excluded_user_external_id,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
last_slot, slot_agendas = None, set()
|
||||||
|
for slot in sorted(all_slots, key=lambda slot: slot[:3]):
|
||||||
|
if slot.start_datetime < now_datetime:
|
||||||
|
continue
|
||||||
|
if last_slot is None:
|
||||||
|
last_slot = slot
|
||||||
|
elif last_slot[:2] != slot[:2]:
|
||||||
|
yield last_slot, slot_agendas
|
||||||
|
last_slot = slot
|
||||||
|
slot_agendas = set()
|
||||||
|
if not slot.full:
|
||||||
|
slot_agendas.add(slot.desk.agenda)
|
||||||
|
if last_slot:
|
||||||
|
yield last_slot, slot_agendas
|
||||||
|
|
||||||
generator_of_unique_slots = unique_slots()
|
generator_of_unique_slots = unique_slots()
|
||||||
|
|
||||||
|
@ -839,7 +869,7 @@ class MeetingDatetimes(APIView):
|
||||||
bookable_datetimes_number_available = 0
|
bookable_datetimes_number_available = 0
|
||||||
first_bookable_slot = None
|
first_bookable_slot = None
|
||||||
data = []
|
data = []
|
||||||
for slot in generator_of_unique_slots:
|
for slot, slot_agendas in generator_of_unique_slots:
|
||||||
if request.GET.get('hide_disabled') and slot.full:
|
if request.GET.get('hide_disabled') and slot.full:
|
||||||
continue
|
continue
|
||||||
if minutes and slot.start_datetime.minute not in minutes:
|
if minutes and slot.start_datetime.minute not in minutes:
|
||||||
|
@ -861,6 +891,23 @@ class MeetingDatetimes(APIView):
|
||||||
}
|
}
|
||||||
if booked_user_external_id and slot.booked_for_external_user:
|
if booked_user_external_id and slot.booked_for_external_user:
|
||||||
slot_data['booked_for_external_user'] = True
|
slot_data['booked_for_external_user'] = True
|
||||||
|
if slot_agendas is not None:
|
||||||
|
slot_data['agendas'] = [
|
||||||
|
{
|
||||||
|
'id': agenda.id,
|
||||||
|
'text': agenda.label,
|
||||||
|
'slug': agenda.slug,
|
||||||
|
'api': {
|
||||||
|
'fillslot_url': request.build_absolute_uri(
|
||||||
|
reverse(
|
||||||
|
'api-fillslot',
|
||||||
|
kwargs={'agenda_identifier': agenda.slug, 'event_identifier': slot_id},
|
||||||
|
)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for agenda in sorted(slot_agendas, key=lambda a: a.label)
|
||||||
|
]
|
||||||
data.append(slot_data)
|
data.append(slot_data)
|
||||||
|
|
||||||
bookable_datetimes_number_total += 1
|
bookable_datetimes_number_total += 1
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue