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

Encapsulate discretization in Event::discretize_timeslots

parent aee5627c
No related branches found
No related tags found
1 merge request!7Encapsulate discretization in Event::discretize_timeslots
Pipeline #269127 failed
...@@ -382,6 +382,13 @@ class Event(models.Model): ...@@ -382,6 +382,13 @@ class Event(models.Model):
constraints=category_constraints, 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: def schedule_from_json(self, schedule: str) -> None:
"""Load AK schedule from a json string. """Load AK schedule from a json string.
...@@ -396,7 +403,7 @@ class Event(models.Model): ...@@ -396,7 +403,7 @@ class Event(models.Model):
timeslot_dict = { timeslot_dict = {
timeslot.idx: timeslot 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 for timeslot in block
} }
......
...@@ -114,11 +114,7 @@ class AKJSONExportView(AdminViewMixin, FilterByEventSlugMixin, ListView): ...@@ -114,11 +114,7 @@ class AKJSONExportView(AdminViewMixin, FilterByEventSlugMixin, ListView):
if (values := AKSlot.objects.select_related().filter(ak__pk=ak_id, fixed=True)).exists() if (values := AKSlot.objects.select_related().filter(ak__pk=ak_id, fixed=True)).exists()
} }
if DefaultSlot.objects.filter(event=self.event).exists(): blocks = self.event.discretize_timeslots(slots_in_an_hour=SLOTS_IN_AN_HOUR)
# 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)
for block in blocks: for block in blocks:
current_block = [] current_block = []
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment