database/schedule_models.py
def create_weekly_schedules(timings: List[List[int]], survey: Survey) -> bool:
        """ Creates new WeeklySchedule objects from a frontend-style list of seconds into the day. """

        if survey.deleted or not timings:
            survey.weekly_schedules.all().delete()
            return False

        # asserts are not bypassed in production. Keep.
        if len(timings) != 7:
            raise Exception(
                f"Must have schedule for every day of the week, found {len(timings)} instead."
            )
        survey.weekly_schedules.all().delete()

        duplicated = False
        for day in range(7):
            for seconds in timings[day]:
                # should be all ints, use integer division.
                hour = seconds // 3600
                minute = seconds % 3600 // 60
                # using get_or_create to catch duplicate schedules
                _, created = WeeklySchedule.objects.get_or_create(
                    survey=survey, day_of_week=day, hour=hour, minute=minute
                )
                if not created:
                    duplicated = True

        return duplicated
 Creates new WeeklySchedule objects from a frontend-style list of seconds into the day. 
Creates new WeeklySchedule objects from a frontend-style list of seconds into the day.
Creates new WeeklySchedule objects from a frontend - style list of seconds into the day .
def create_weekly_schedules(timings: List[List[int]], survey: Survey) -> bool:
        if survey.deleted or not timings:
            survey.weekly_schedules.all().delete()
            return False
        if len(timings) != 7:
            raise Exception(
                f"Must have schedule for every day of the week, found {len(timings)} instead."
            )
        survey.weekly_schedules.all().delete()
        duplicated = False
        for day in range(7):
            for seconds in timings[day]:
                hour = seconds // 3600
                minute = seconds % 3600 // 60
                _, created = WeeklySchedule.objects.get_or_create(
                    survey=survey, day_of_week=day, hour=hour, minute=minute
                )
                if not created:
                    duplicated = True
        return duplicated
def create_weekly_schedules ( timings : List [ List [ int ] ] , survey : Survey ) -> bool : if survey . deleted or not timings : survey . weekly_schedules . all ( ) . delete ( ) return False if len ( timings ) != 7 : raise Exception ( f"Must have schedule for every day of the week, found {len(timings)} instead." ) survey . weekly_schedules . all ( ) . delete ( ) duplicated = False for day in range ( 7 ) : for seconds in timings [ day ] : hour = seconds // 3600 minute = seconds % 3600 // 60 _ , created = WeeklySchedule . objects . get_or_create ( survey = survey , day_of_week = day , hour = hour , minute = minute ) if not created : duplicated = True return duplicated
Creates new WeeklySchedule objects from a frontend-style list of seconds into the day.
Creates new WeeklySchedule objects from a frontend - style list of seconds into the day .
""" Creates new WeeklySchedule objects from a frontend-style list of seconds into the day. """ # asserts are not bypassed in production. Keep.
 # should be all ints, use integer division.
 # using get_or_create to catch duplicate schedules

timings
List[List[int]]
survey
Survey