Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add frontend logic #45

Merged
merged 4 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions backend/yet_another_calendar/web/api/bulk/integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ def export_to_ics(calendar: schema.CalendarResponse) -> Iterable[bytes]:
description=netology_lesson.title,
url=netology_lesson.webinar_url)
ics_calendar.add_component(event)
for netology_homework in calendar.netology.homework:
if not netology_homework.deadline:
continue
dt_end = netology_homework.deadline + datetime.timedelta(hours=18)
dt_start = dt_end - datetime.timedelta(hours=2)
event = create_ics_event(title=f"Netology ДЗ: {netology_homework.block_title}", starts_at=dt_start,
ends_at=dt_end, lesson_id=netology_homework.id,
description=netology_homework.title,
url=netology_homework.url)
ics_calendar.add_component(event)
for modeus_lesson in calendar.utmn.modeus_events:
event = create_ics_event(title=f"Modeus: {modeus_lesson.course_name}", starts_at=modeus_lesson.start_time,
ends_at=modeus_lesson.end_time, lesson_id=modeus_lesson.id,
Expand Down
21 changes: 18 additions & 3 deletions backend/yet_another_calendar/web/api/modeus/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ def id(self) -> uuid.UUID:


class EventLinks(BaseModel):
course_unit_realization: Href = Field(alias="course-unit-realization")
course_unit_realization: Optional[Href] = Field(alias="course-unit-realization", default=None)
cycle_realization: Optional[Href] = Field(alias="cycle-realization", default=None)


class EventWithLinks(Event):
Expand All @@ -140,17 +141,25 @@ class Course(BaseModel):
name: str


class CycleRealization(BaseModel):
id: uuid.UUID
name: str
code: str


class CalendarEmbedded(BaseModel):
events: list[EventWithLinks] = Field(alias="events")
locations: list[Location] = Field(alias="event-locations")
attendees: list[Attender] = Field(alias="event-attendees")
people: list[ShortPerson] = Field(alias="persons")
courses: list[Course] = Field(alias="course-unit-realizations")
cycle_realizations: list[CycleRealization] = Field(alias="cycle-realizations")


class FullEvent(Event, Location):
teacher_full_name: str
course_name: str
cycle_realization: CycleRealization


class ModeusCalendar(BaseModel):
Expand All @@ -163,23 +172,29 @@ def serialize_modeus_response(self) -> list[FullEvent]:
locations = {location.id: location for location in self.embedded.locations}
teachers = {teacher.id: teacher for teacher in self.embedded.people}
courses = {course.id: course for course in self.embedded.courses}
cycle_realizations = {cycle_realization.id: cycle_realization for cycle_realization in
self.embedded.cycle_realizations}
teachers_with_events = {teacher.links.event.id: teacher.links for teacher in self.embedded.attendees}
full_events = []
for event in self.embedded.events:
course_id = event.links.course_unit_realization.id
course_id = event.links.course_unit_realization.id if event.links.course_unit_realization else None
cycle_id = event.links.cycle_realization.id if event.links.cycle_realization else None
try:
course_name = courses[course_id].name
cycle_realization = cycle_realizations[cycle_id] if cycle_id else 'unknown'
course_name = courses[course_id].name if course_id else 'unknown'
teacher_event = teachers_with_events[event.id]
teacher = teachers[teacher_event.person.id]
teacher_full_name = teacher.full_name
except KeyError:
cycle_realization = 'unknown'
course_name = 'unknown'
teacher_full_name = 'unknown'
location = locations[event.id]
if location.is_lxp:
continue
full_events.append(FullEvent(**{
"teacher_full_name": teacher_full_name, "course_name": course_name,
"cycle_realization": cycle_realization,
**event.model_dump(by_alias=True), **location.model_dump(by_alias=True),
}))
return full_events
Expand Down
9 changes: 6 additions & 3 deletions backend/yet_another_calendar/web/api/netology/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,12 @@ def deadline_validation(cls, data: Any) -> Any:
match = re.search(_DATE_PATTERN, data.get('title', ''))
if not match:
return data
date = match.group(0)
data['deadline'] = datetime.datetime.strptime(date, "%d.%m.%y").astimezone(datetime.timezone.utc)
return data
try:
date = match.group(0).replace('00.', '01.')
data['deadline'] = datetime.datetime.strptime(date, "%d.%m.%y").astimezone(datetime.timezone.utc)
return data
except Exception:
return data

def is_suitable_time(self, time_min: datetime.datetime, time_max: datetime.datetime) -> bool:
"""Check if lesson have suitable time"""
Expand Down
Loading
Loading