From 4aeb1b566d74513b2855984be3aac6a810d411a4 Mon Sep 17 00:00:00 2001 From: Thomas Steen Rasmussen Date: Mon, 22 Jun 2020 00:49:02 +0200 Subject: [PATCH] handle cases where a speaker has three events in a row --- .../management/commands/convert_eventinstances.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/utils/management/commands/convert_eventinstances.py b/src/utils/management/commands/convert_eventinstances.py index 9e043db4..5c59a245 100644 --- a/src/utils/management/commands/convert_eventinstances.py +++ b/src/utils/management/commands/convert_eventinstances.py @@ -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