[scrobbles] Clean up dataclass inheritence
This commit is contained in:
@ -30,9 +30,34 @@ class JSONDataclass(JSONWizard):
|
|||||||
def json(self):
|
def json(self):
|
||||||
return json.dumps(self.asdict)
|
return json.dumps(self.asdict)
|
||||||
|
|
||||||
|
|
||||||
class LongPlayLogData(JSONDataclass):
|
class LongPlayLogData(JSONDataclass):
|
||||||
serial_scrobble_id: Optional[int]
|
serial_scrobble_id: Optional[int]
|
||||||
long_play_complete: Optional[bool]
|
long_play_complete: bool = False
|
||||||
|
|
||||||
|
|
||||||
|
class WithOthersLogData(JSONDataclass):
|
||||||
|
with_user_ids: Optional[list[int]] = None
|
||||||
|
with_names_str: Optional[list[str]] = None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def with_names(self) -> list[str]:
|
||||||
|
with_names = []
|
||||||
|
if self.with_user_ids:
|
||||||
|
with_names += [u.full_name for u in self.with_users if u]
|
||||||
|
if self.with_names_str:
|
||||||
|
with_names += [u for u in self.with_names_str]
|
||||||
|
return with_names
|
||||||
|
|
||||||
|
@property
|
||||||
|
def with_users(self) -> list[User]:
|
||||||
|
with_users = []
|
||||||
|
if self.with_user_ids:
|
||||||
|
with_users = [
|
||||||
|
User.objects.filter(id=i).first() for i in self.with_user_ids
|
||||||
|
]
|
||||||
|
return with_users
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class BoardGameScoreLogData(JSONDataclass):
|
class BoardGameScoreLogData(JSONDataclass):
|
||||||
@ -73,6 +98,8 @@ class BoardGameScoreLogData(JSONDataclass):
|
|||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class BoardGameLogData(LongPlayLogData):
|
class BoardGameLogData(LongPlayLogData):
|
||||||
|
serial_scrobble_id: Optional[int]
|
||||||
|
long_play_complete: bool = False
|
||||||
players: Optional[list[BoardGameScoreLogData]] = None
|
players: Optional[list[BoardGameScoreLogData]] = None
|
||||||
location: Optional[str] = None
|
location: Optional[str] = None
|
||||||
geo_location_id: Optional[int] = None
|
geo_location_id: Optional[int] = None
|
||||||
@ -96,45 +123,31 @@ class BookPageLogData(JSONDataclass):
|
|||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class BookLogData(LongPlayLogData):
|
class BookLogData(LongPlayLogData):
|
||||||
koreader_hash: Optional[str]
|
|
||||||
pages_read: Optional[int]
|
|
||||||
page_data: Optional[list[BookPageLogData]]
|
|
||||||
page_end: Optional[int]
|
|
||||||
page_start: Optional[int]
|
|
||||||
serial_scrobble_id: Optional[int]
|
serial_scrobble_id: Optional[int]
|
||||||
|
long_play_complete: bool = False
|
||||||
|
koreader_hash: Optional[str] = None
|
||||||
|
pages_read: Optional[int] = None
|
||||||
|
page_data: Optional[list[BookPageLogData]] = None
|
||||||
|
page_end: Optional[int] = None
|
||||||
|
page_start: Optional[int] = None
|
||||||
|
serial_scrobble_id: Optional[int] = None
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class LifeEventLogData(JSONDataclass):
|
class LifeEventLogData(WithOthersLogData):
|
||||||
participant_user_ids: Optional[list[int]] = None
|
with_user_ids: Optional[list[int]] = None
|
||||||
participant_names: Optional[list[str]] = None
|
with_names_str: Optional[list[str]] = None
|
||||||
location: Optional[str] = None
|
location: Optional[str] = None
|
||||||
geo_location_id: Optional[int] = None
|
geo_location_id: Optional[int] = None
|
||||||
details: Optional[str] = None
|
details: Optional[str] = None
|
||||||
|
|
||||||
def participants(self) -> list[str]:
|
|
||||||
participants = []
|
|
||||||
if self.participant_user_ids:
|
|
||||||
participants += [u.full_name for u in self.participant_users]
|
|
||||||
if self.participant_names:
|
|
||||||
participants += self.participant_names
|
|
||||||
return participants
|
|
||||||
|
|
||||||
@property
|
|
||||||
def participant_users(self) -> list[User]:
|
|
||||||
participants = []
|
|
||||||
if self.participant_user_ids:
|
|
||||||
for id in self.participant_user_ids:
|
|
||||||
participants.append(User.objects.filter(id=id).first())
|
|
||||||
return participants
|
|
||||||
|
|
||||||
def geo_location(self):
|
def geo_location(self):
|
||||||
return GeoLocation.objects.filter(id=self.geo_location_id).first()
|
return GeoLocation.objects.filter(id=self.geo_location_id).first()
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class MoodLogData(JSONDataclass):
|
class MoodLogData(JSONDataclass):
|
||||||
reasons: Optional[str]
|
reasons: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@ -144,23 +157,27 @@ class VideoLogData(JSONDataclass):
|
|||||||
run_time_seconds: int
|
run_time_seconds: int
|
||||||
kind: str
|
kind: str
|
||||||
year: Optional[int]
|
year: Optional[int]
|
||||||
episode_number: Optional[int]
|
episode_number: Optional[int] = None
|
||||||
source_url: Optional[str]
|
source_url: Optional[str] = None
|
||||||
imdbID: Optional[str]
|
imdbID: Optional[str] = None
|
||||||
season_number: Optional[int]
|
season_number: Optional[int] = None
|
||||||
cover_url = Optional[str]
|
cover_url: Optional[str] = None
|
||||||
next_imdb_id: Optional[int]
|
next_imdb_id: Optional[int] = None
|
||||||
tv_series_id: Optional[str]
|
tv_series_id: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class VideoGameLogData(LongPlayLogData):
|
class VideoGameLogData(LongPlayLogData):
|
||||||
|
serial_scrobble_id: Optional[int]
|
||||||
|
long_play_complete: bool = False
|
||||||
|
console: str = ""
|
||||||
emulated: bool = False
|
emulated: bool = False
|
||||||
console: Optional[str] = None
|
|
||||||
emulator: Optional[str] = None
|
emulator: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class BrickSetLogData(LongPlayLogData):
|
class BrickSetLogData(LongPlayLogData, WithOthersLogData):
|
||||||
built_with_names: Optional[list[str]]
|
serial_scrobble_id: Optional[int]
|
||||||
built_with_user_ids: Optional[list[str]]
|
long_play_complete: bool = False
|
||||||
|
with_user_ids: Optional[list[int]] = None
|
||||||
|
with_names_str: Optional[list[str]] = None
|
||||||
|
|||||||
Reference in New Issue
Block a user