Skip to content
Snippets Groups Projects
Commit 440709c1 authored by Felix Blanke's avatar Felix Blanke
Browse files

Introduce availabilits class method is_event_covered

parent e2884a59
No related branches found
No related tags found
6 merge requests!262[WIP] compatibility with koma solver import/export,!261[WIP] compatibility with koma solver import/export,!260[WIP] import/export merge,!259Add view to clear schedule,!237Draft: add tests on json export,!235Merge fork for interoperability of KoMa solver
......@@ -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')
......
......@@ -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}"]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment