diff --git a/AKModel/availability/models.py b/AKModel/availability/models.py index 7ce794dcda52fcbde462584379e1447ad2b124f2..de51e438bf9ff427dff1714d0ad63267ecd7e278 100644 --- a/AKModel/availability/models.py +++ b/AKModel/availability/models.py @@ -267,6 +267,14 @@ class Availability(models.Model): return Availability(start=timeframe_start, end=timeframe_end, event=event, person=person, room=room, ak=ak, ak_category=ak_category) + @classmethod + def is_event_covered(cls, event, availabilities: List['Availability']) -> bool: + # NOTE: Cannot use `Availability.with_event_length` as its end is the + # event end + 1 day + full_event = Availability(event=event, start=event.start, end=event.end) + avail_union = Availability.union(availabilities) + return not avail_union or avail_union[0].contains(full_event) + class Meta: verbose_name = _('Availability') verbose_name_plural = _('Availabilities') diff --git a/AKModel/models.py b/AKModel/models.py index c00780134a3fce1f7b0405f8b3debfac7369d390..2052a5cd99b3cfe6f90f0635d3fe625f4085a0ae 100644 --- a/AKModel/models.py +++ b/AKModel/models.py @@ -579,12 +579,7 @@ class Room(models.Model): # check if room is available for the whole event # -> no time constraint needs to be introduced - - # NOTE: Cannot use `Availability.with_event_length` as its end is the - # event end + 1 day - full_event = Availability(event=self.event, start=self.event.start, end=self.event.end) - avail_union = Availability.union(self.availabilities.all()) - if not avail_union or avail_union[0].contains(full_event): + if Availability.is_event_covered(self.event, self.availabilities.all()): time_constraints = [] else: time_constraints = [f"availability-room-{self.pk}"] @@ -703,19 +698,13 @@ class AKSlot(models.Model): # check if ak resp. owner is available for the whole event # -> no time constraint needs to be introduced - # NOTE: Cannot use `Availability.with_event_length` as its end is the - # event end + 1 day - full_event = Availability(event=self.event, start=self.event.start, end=self.event.end) - - ak_avail_union = Availability.union(self.ak.availabilities.all()) - if not ak_avail_union or ak_avail_union[0].contains(full_event): + if Availability.is_event_covered(self.event, self.ak.availabilities.all()): ak_time_constraints = [] else: ak_time_constraints = [f"availability-ak-{self.ak.pk}"] def _owner_time_constraints(owner: AKOwner): - owner_avail_union = Availability.union(owner.availabilities.all()) - if not owner_avail_union or owner_avail_union[0].contains(full_event): + if Availability.is_event_covered(self.event, owner.availabilities.all()): return [] else: return [f"availability-person-{owner.pk}"]