From 03020542b6d4c4306d0f7618f9ed6c47276ccd89 Mon Sep 17 00:00:00 2001 From: Ernesto Rico Schmidt <ernesto@helsinki.at> Date: Wed, 22 May 2024 17:11:30 -0400 Subject: [PATCH] feat: simplify code to get optional data --- program/services.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/program/services.py b/program/services.py index 690ef5f9..59c5b86b 100644 --- a/program/services.py +++ b/program/services.py @@ -176,8 +176,6 @@ def resolve_conflicts(data: ScheduleCreateUpdateData, schedule_pk: int | None, s errors[timeslot["hash"]] = _("Given solution is not accepted for this conflict.") continue - """Conflict resolution""" - existing = timeslot["collisions"][0] solution = solutions[timeslot["hash"]] @@ -374,24 +372,22 @@ def instantiate_upcoming_schedule( rrule = RRule.objects.get(pk=data["rrule_id"]) show = Show.objects.get(pk=show_pk) - is_repetition = data["is_repetition"] if "is_repetition" in data else False + is_repetition = data.get("is_repetition", False) - # default is `False` - add_business_days_only = ( - data["add_business_days_only"] if "add_business_days_only" in data else False - ) + add_business_days_only = data.get("add_business_days_only", False) # default is `None` add_days_no = data.get("add_days_no") by_weekday = data.get("by_weekday") default_playlist_id = data.get("default_playlist_id") + # required first_date = parse_date(data["first_date"]) start_time = parse_time(data["start_time"]) end_time = parse_time(data["end_time"]) - # last_date may not be present in data - last_date = parse_date(data["last_date"]) if data.get("last_date") is not None else None + # last_date may not be present in data, parse_date returns `None` in this case + last_date = parse_date(data.get("last_date")) return Schedule( pk=pk, -- GitLab