From 7b30f5e7a4a9c4f7151a5fbae5cdd6cbadfd0e40 Mon Sep 17 00:00:00 2001 From: Ernesto Rico Schmidt <ernesto@helsinki.at> Date: Wed, 5 Apr 2023 19:14:15 -0400 Subject: [PATCH] Add type annotations --- program/services.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/program/services.py b/program/services.py index f11f64f4..37e9e986 100644 --- a/program/services.py +++ b/program/services.py @@ -72,12 +72,11 @@ class ProjectedEntry(TypedDict): start: str -class ConflictsData(TypedDict): - projected: list[ProjectedEntry] - solutions: dict[str, str] +class Conflicts(TypedDict): notes: dict playlists: dict - schedule: ScheduleData + projected: list[ProjectedEntry] + solutions: dict[str, str] # TODO: add type annotations @@ -411,7 +410,7 @@ def instantiate_upcoming_schedule( ) -def make_conflicts(data: ScheduleData, schedule_pk: int | None, show_pk: int): +def make_conflicts(data: ScheduleData, schedule_pk: int | None, show_pk: int) -> Conflicts: """ Retrieves POST vars Generates a schedule @@ -420,10 +419,10 @@ def make_conflicts(data: ScheduleData, schedule_pk: int | None, show_pk: int): """ # Generate schedule to be saved - schedule = instantiate_upcoming_schedule(data, show_pk, schedule_pk) + new_schedule = instantiate_upcoming_schedule(data, show_pk, schedule_pk) # Copy if first_date changes for generating timeslots - gen_schedule = schedule + schedule_copy = new_schedule # Generate timeslots @@ -431,17 +430,17 @@ def make_conflicts(data: ScheduleData, schedule_pk: int | None, show_pk: int): if schedule_pk is not None: existing_schedule = Schedule.objects.get(pk=schedule_pk) - if schedule.last_date > existing_schedule.last_date: + if new_schedule.last_date > existing_schedule.last_date: last_timeslot = ( TimeSlot.objects.filter(schedule=existing_schedule).order_by("start").reverse()[0] ) - gen_schedule.first_date = last_timeslot.start.date() + timedelta(days=1) + schedule_copy.first_date = last_timeslot.start.date() + timedelta(days=1) - timeslots = generate_timeslots(gen_schedule) + timeslots = generate_timeslots(schedule_copy) # Generate conflicts and add schedule conflicts = generate_conflicts(timeslots) - conflicts["schedule"] = model_to_dict(schedule) + conflicts["schedule"] = model_to_dict(new_schedule) return conflicts -- GitLab