From c106da54bac23424156928f218a8c911993308d6 Mon Sep 17 00:00:00 2001 From: Ernesto Rico Schmidt <ernesto@helsinki.at> Date: Fri, 9 Jun 2023 11:10:51 -0400 Subject: [PATCH] fix: update remaining APIs to camelCase notation Closes #152 --- program/views.py | 53 ++++++++++++++++++++++-------------------------- 1 file changed, 24 insertions(+), 29 deletions(-) diff --git a/program/views.py b/program/views.py index 8e60e1c2..407911e7 100644 --- a/program/views.py +++ b/program/views.py @@ -92,40 +92,37 @@ logger = logging.getLogger(__name__) def timeslot_entry(*, timeslot: TimeSlot) -> dict: """return a timeslot entry as a dict""" - show = timeslot.show schedule = timeslot.schedule + show = timeslot.schedule.show playlist_id = timeslot.playlist_id title = show_name = f"{show.name} {_('REP')}" if schedule.is_repetition else show.name + # we start and end as timezone naive datetime objects + start = timezone.make_naive(timeslot.start).strftime("%Y-%m-%dT%H:%M:%S") + end = timezone.make_naive(timeslot.end).strftime("%Y-%m-%dT%H:%M:%S") return { + "end": end, "id": timeslot.id, - # we need start & end as timezone naive datetime objects - "start": timezone.make_naive(timeslot.start).strftime("%Y-%m-%dT%H:%M:%S"), - "end": timezone.make_naive(timeslot.end).strftime("%Y-%m-%dT%H:%M:%S"), - "title": title, - "schedule_id": schedule.id, + "playlistId": playlist_id, # `Timeslot.repetition_of` is a foreign key that can be null - "is_repetition": timeslot.repetition_of.id if timeslot.repetition_of else False, - "playlist_id": playlist_id, - "schedule_default_playlist_id": schedule.default_playlist_id, - "show_default_playlist_id": show.default_playlist_id, - "show_id": show.id, - "show_name": show_name, - "show_hosts": ", ".join(show.hosts.values_list("name", flat=True)), - # `Show.type` is a foreign key that can be null - "show_type": show.type.name if show.type_id else "", - "show_categories": ", ".join(show.category.values_list("name", flat=True)), - "show_topics": ", ".join(show.topic.values_list("name", flat=True)), - # TODO: replace `show_musicfocus` with `show_music_focus` when engine is updated - "show_musicfocus": ", ".join(show.music_focus.values_list("name", flat=True)), - "show_languages": ", ".join(show.language.values_list("name", flat=True)), - # TODO: replace `show_fundingcategory` with `show_funding_category` when engine is - # updated + "repetitionOfId": timeslot.repetition_of.id if timeslot.repetition_of else "", + "scheduleDefaultPlaylistId": schedule.default_playlist_id, + "scheduleId": schedule.id, + "showCategories": ", ".join(show.category.values_list("name", flat=True)), + "showDefaultPlaylistId": show.default_playlist_id, # `Show.funding_category` is a foreign key can be null - "show_fundingcategory": show.funding_category.name if show.funding_category_id else "", - "memo": timeslot.memo, - "className": "danger" if playlist_id is None or playlist_id == 0 else "default", + "showFundingCategory": show.funding_category.name if show.funding_category_id else "", + "showHosts": ", ".join(show.hosts.values_list("name", flat=True)), + "showId": show.id, + "showLanguages": ", ".join(show.language.values_list("name", flat=True)), + "showMusicFocus": ", ".join(show.music_focus.values_list("name", flat=True)), + "showName": show_name, + "showTopics": ", ".join(show.topic.values_list("name", flat=True)), + # `Show.type` is a foreign key that can be null + "showType": show.type.name if show.type_id else "", + "start": start, + "title": title, } @@ -133,8 +130,8 @@ def gap_entry(*, gap_start: datetime, gap_end: datetime) -> dict: """return a virtual timeslot to fill the gap in between `gap_start` and `gap_end` as a dict""" return { - "start": gap_start.strftime("%Y-%m-%dT%H:%M:%S"), "end": gap_end.strftime("%Y-%m-%dT%H:%M:%S"), + "start": gap_start.strftime("%Y-%m-%dT%H:%M:%S"), "virtual": True, } @@ -151,7 +148,6 @@ def json_day_schedule(request, year=None, month=None, day=None): timeslots = ( TimeSlot.objects.get_timerange_timeslots(start, end) .select_related("schedule") - .select_related("show") ) schedule = [] @@ -203,12 +199,11 @@ def json_playout(request): datetime.combine(parse_date(request.GET.get("end")) + timedelta(days=1), time(0, 0)) ) - include_virtual = request.GET.get("includeVirtual") == "true" + include_virtual = request.GET.get("include_virtual") == "true" timeslots = ( TimeSlot.objects.get_timerange_timeslots(schedule_start, schedule_end) .select_related("schedule") - .select_related("show") ) schedule = [] -- GitLab