def _opening(period, weekday): opens = random_hour(time(7), time(8)) closes = random_hour(time(10), time(13)) return Opening(weekday=weekday, period=period, opens=opens, closes=closes)
def _third_opening(period, weekday): opens = random_hour(time(21), time(23)) closes = random_hour(time(1), time(4)) return Opening(weekday=weekday, period=period, opens=opens, closes=closes)
def _second_opening(period, weekday): opens = random_hour(time(14), time(16)) closes = random_hour(time(18), time(20)) return Opening(weekday=weekday, period=period, opens=opens, closes=closes)
def save_period(self, data: dict) -> Period: """ Takes the serialized Period data with Openings, creates and/or updates the corresponding Period object, saves and returns it. """ obj = self._update_or_create_object(Period, data) if obj._created: obj.save() self.logger.debug("%s created" % obj) # Update openings after the period has been created openings = obj.openings.all() openings.delete() new_openings = [] for opening in data.get('openings', []): # openings have no identifiers in kirkanta and they are generated from data # therefore, we cannot identify existing openings with new ones new_opening = Opening(period=obj, weekday=opening['weekday'], week=opening['week'], status=opening['status'], description=opening.get('description', None), opens=opening.get('opens', None), closes=opening.get('closes', None)) new_openings.append(new_opening) Opening.objects.bulk_create(new_openings) obj._changed = True obj._changed_fields.append('openings') if not obj._created: self.logger.debug("%s changed: %s" % (obj, ', '.join(obj._changed_fields))) # Saving updates the daily hours for the duration of the period obj.save()
def _opening(period, weekday): return Opening(weekday=weekday, period=period, status=Status.CLOSED, week=2)