-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into init-frontend
- Loading branch information
Showing
54 changed files
with
590 additions
and
19,756 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import datetime | ||
import uuid | ||
from typing import Optional | ||
|
||
from pydantic import BaseModel, Field, computed_field | ||
|
||
|
||
class NetologyCreds(BaseModel): | ||
"""Netology creds.""" | ||
|
||
username: str | ||
password: str | ||
|
||
|
||
class ModeusCreds(BaseModel): | ||
"""Modeus creds.""" | ||
|
||
username: str | ||
password: str | ||
|
||
|
||
class ModeusSearchEvents(BaseModel): | ||
"""Modeus search events body.""" | ||
size: int = Field(examples=[50], default=50) | ||
time_min: datetime.datetime = Field(alias="timeMin", examples=[datetime.datetime.now()]) | ||
time_max: datetime.datetime = Field(alias="timeMax", | ||
examples=[datetime.datetime.now() - datetime.timedelta(days=7)]) | ||
attendee_person_id: list[str] = Field(alias="attendeePersonId", default="d69c87c8-aece-4f39-b6a2-7b467b968211") | ||
|
||
|
||
class Location(BaseModel): | ||
id: uuid.UUID = Field(alias="eventId") | ||
custom_location: str = Field(alias="customLocation") | ||
|
||
@computed_field # type: ignore | ||
@property | ||
def is_lxp(self) -> float: | ||
return self.custom_location == 'LXP' | ||
|
||
|
||
class Event(BaseModel): | ||
name: str = Field(alias="name") | ||
name_short: str = Field(alias="nameShort") | ||
description: Optional[str] = Field(alias="description") | ||
start_time: datetime.datetime = Field(alias="start") | ||
end_time: datetime.datetime = Field(alias="end") | ||
id: uuid.UUID | ||
|
||
|
||
class Href(BaseModel): | ||
href: str | ||
|
||
@computed_field # type: ignore | ||
@property | ||
def id(self) -> uuid.UUID: | ||
return uuid.UUID(self.href.replace('/', '')) | ||
|
||
class Link(BaseModel): | ||
self: Href | ||
event: Href | ||
person: Href | ||
|
||
class Attender(BaseModel): | ||
links: Link = Field(alias="_links") | ||
|
||
|
||
class Teacher(BaseModel): | ||
id: uuid.UUID | ||
full_name: str = Field(alias="fullName") | ||
|
||
|
||
class Embedded(BaseModel): | ||
events: list[Event] = Field(alias="events") | ||
locations: list[Location] = Field(alias="event-locations") | ||
attendees: list[Attender] = Field(alias="event-attendees") | ||
teacher: list[Teacher] = Field(alias="persons") | ||
|
||
|
||
class FullEvent(Event, Location): | ||
teacher_full_name: str | ||
|
||
|
||
class ModeusCalendar(BaseModel): | ||
"""Modeus calendar response.""" | ||
|
||
embedded: Embedded = Field(alias="_embedded") | ||
|
||
def parse_modeus_response(self) -> list[FullEvent]: | ||
locations = {location.id: location for location in self.embedded.locations} | ||
teachers = {teacher.id: teacher for teacher in self.embedded.teacher} | ||
teachers_with_events = {teacher.links.event.id: teacher.links for teacher in self.embedded.attendees} | ||
full_events = [] | ||
for event in self.embedded.events: | ||
try: | ||
teacher_event = teachers_with_events[event.id] | ||
teacher = teachers[teacher_event.person.id] | ||
teacher_full_name = teacher.full_name | ||
except KeyError: | ||
teacher_full_name = 'unknown' | ||
location = locations[event.id] | ||
full_events.append(FullEvent(**{ | ||
"teacher_full_name": teacher_full_name, | ||
**event.model_dump(by_alias=True), **location.model_dump(by_alias=True), | ||
})) | ||
return full_events |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.