From 2e742550a80a12505ed34b62c64218bd5f75b6c4 Mon Sep 17 00:00:00 2001 From: Ernesto Rico Schmidt <ernesto@helsinki.at> Date: Wed, 23 Feb 2022 15:11:08 -0400 Subject: [PATCH] Replace generate method in TimeSlot with hash property --- program/models.py | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/program/models.py b/program/models.py index 51199a17..acd065cc 100644 --- a/program/models.py +++ b/program/models.py @@ -372,8 +372,7 @@ class Schedule(models.Model): if ends[k].date() > schedule.until: schedule.until = ends[k].date() - timeslots.append( - TimeSlot(schedule=schedule, start=timezone.make_aware(starts[k]), end=timezone.make_aware(ends[k])).generate()) + timeslots.append(TimeSlot(schedule=schedule, start=timezone.make_aware(starts[k]), end=timezone.make_aware(ends[k]))) return timeslots @@ -832,7 +831,7 @@ class TimeSlotManager(models.Manager): def instantiate(start, end, schedule, show): return TimeSlot(start=parse_datetime(start), end=parse_datetime(end), - show=show, is_repetition=schedule.is_repetition, schedule=schedule).generate() + show=show, is_repetition=schedule.is_repetition, schedule=schedule) @staticmethod def get_24h_timeslots(start): @@ -875,17 +874,10 @@ class TimeSlot(models.Model): super(TimeSlot, self).save(*args, **kwargs) return self - # FIXME: this should be a property - def generate(self): - """Returns the object instance without saving""" - - self.show = self.schedule.show - - # Generate a distinct and reproducible hash for the timeslot - # Makes sure none of these fields changed when updating a schedule + @property + def hash(self): string = str(self.start) + str(self.end) + str(self.schedule.rrule.id) + str(self.schedule.byweekday) - self.hash = str(''.join(s for s in string if s.isdigit())) - return self + return str(''.join(s for s in string if s.isdigit())) class Note(models.Model): -- GitLab