handle cases where a speaker has three events in a row

This commit is contained in:
Thomas Steen Rasmussen 2020-06-22 00:49:02 +02:00
parent fc7761e315
commit 4aeb1b566d

View file

@ -58,6 +58,20 @@ class Command(BaseCommand):
logger.info(
f"created speakeravailability {sa} for instance {instance}"
)
except SpeakerAvailability.MultipleObjectsReturned:
# who the hell does three events in a row?!
sas = SpeakerAvailability.objects.filter(
speaker=speaker,
when__adjacent_to=instance.when,
available=True,
).order_by("when")
sa = SpeakerAvailability(
speaker=speaker,
when=(sas[0].when.lower, sas[1].when.upper),
available=True,
)
sas.all().delete()
sa.save()
duration = int(
(instance.when.upper - instance.when.lower).total_seconds() / 60