From 6d81cc361eed9add9d48f8c4ffbaa0b58c8d3480 Mon Sep 17 00:00:00 2001 From: Ivan Popov Date: Wed, 16 Oct 2024 21:16:56 +0300 Subject: [PATCH] add block_title --- backend/yet_another_calendar/web/api/netology/schema.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/backend/yet_another_calendar/web/api/netology/schema.py b/backend/yet_another_calendar/web/api/netology/schema.py index 6f38d55..90c3de5 100644 --- a/backend/yet_another_calendar/web/api/netology/schema.py +++ b/backend/yet_another_calendar/web/api/netology/schema.py @@ -54,6 +54,7 @@ class BaseLesson(BaseModel): lesson_id: int type: str title: str + block_title: str class LessonWebinar(BaseLesson): @@ -126,21 +127,23 @@ class NetologyProgram(BaseModel): class CalendarResponse(BaseModel): lessons: list[NetologyProgram] + block_title: str = Field(alias="title") @staticmethod def filter_lessons( + block_title: str, program: NetologyProgram, time_min: datetime.datetime, time_max: datetime.datetime, ) -> tuple[list[LessonTask], list[LessonWebinar]]: """Filter lessons by time and status.""" homework_events, webinars = [], [] for lesson in program.lesson_items: if lesson['type'] in ["task", "test"]: - homework = LessonTask(**lesson) + homework = LessonTask(**lesson, block_title=block_title) if homework.is_suitable_time(time_min, time_max): homework_events.append(homework) continue if lesson['type'] == "webinar": - webinar = LessonWebinar(**lesson) + webinar = LessonWebinar(**lesson, block_title=block_title) if webinar.is_suitable_time(time_min, time_max): webinars.append(webinar) continue @@ -152,7 +155,7 @@ def get_serialized_lessons(self, body: ModeusTimeBody) -> tuple[list[Any], list[ time_min = body.time_min time_max = body.time_max for lesson in self.lessons: - homework_events, webinars_events = self.filter_lessons(lesson, time_min, time_max) + homework_events, webinars_events = self.filter_lessons(self.block_title, lesson, time_min, time_max) filtered_homework.extend(homework_events) filtered_webinars.extend(webinars_events) return filtered_homework, filtered_webinars