diff --git a/AKModel/models.py b/AKModel/models.py index d30912d3046b8ce4a874e775398cf7b6afbace81..f948da9bb771655b248f9617c298fae8b676b879 100644 --- a/AKModel/models.py +++ b/AKModel/models.py @@ -382,6 +382,13 @@ class Event(models.Model): constraints=category_constraints, ) + def discretize_timeslots(self, *, slots_in_an_hour: float = 1.0) -> Iterable[TimeslotBlock]: + if DefaultSlot.objects.filter(event=self.event).exists(): + # discretize default slots if they exists + yield from merge_blocks(self.default_time_slots(slots_in_an_hour=SLOTS_IN_AN_HOUR)) + else: + yield from self.uniform_time_slots(slots_in_an_hour=SLOTS_IN_AN_HOUR) + def schedule_from_json(self, schedule: str) -> None: """Load AK schedule from a json string. @@ -396,7 +403,7 @@ class Event(models.Model): timeslot_dict = { timeslot.idx: timeslot - for block in merge_blocks(self.default_time_slots(slots_in_an_hour=slots_in_an_hour)) + for block in self.discretize_timeslots(slots_in_an_hour=slots_in_an_hour) for timeslot in block } diff --git a/AKModel/views/ak.py b/AKModel/views/ak.py index 90599a1ba26809c21c17495891ce4c527b827c26..859120bacdb493a2eb062bc2ad1ce355c0da0836 100644 --- a/AKModel/views/ak.py +++ b/AKModel/views/ak.py @@ -114,11 +114,7 @@ class AKJSONExportView(AdminViewMixin, FilterByEventSlugMixin, ListView): if (values := AKSlot.objects.select_related().filter(ak__pk=ak_id, fixed=True)).exists() } - if DefaultSlot.objects.filter(event=self.event).exists(): - # discretize default slots if they exists - blocks = merge_blocks(self.event.default_time_slots(slots_in_an_hour=SLOTS_IN_AN_HOUR)) - else: - blocks = self.event.uniform_time_slots(slots_in_an_hour=SLOTS_IN_AN_HOUR) + blocks = self.event.discretize_timeslots(slots_in_an_hour=SLOTS_IN_AN_HOUR) for block in blocks: current_block = []