[videogames] Add log data to VideoGame model
This commit is contained in:
@ -19,9 +19,11 @@ def boardgame_scrobble():
|
|||||||
board_game=BoardGame.objects.create(title="Test Board Game"),
|
board_game=BoardGame.objects.create(title="Test Board Game"),
|
||||||
media_type="BoardGame",
|
media_type="BoardGame",
|
||||||
played_to_completion=True,
|
played_to_completion=True,
|
||||||
log='{"players": [{"user_id": '
|
log={
|
||||||
+ str(user.id)
|
"players": [
|
||||||
+ ', "win": true, "score": 30, "color": "Blue"}]}',
|
{"user_id": user.id, "win": True, "score": 30, "color": "Blue"}
|
||||||
|
]
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -132,7 +132,7 @@ class MoodLogData(JSONDataclass):
|
|||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class VideoMetadata(JSONDataclass):
|
class VideoLogData(JSONDataclass):
|
||||||
title: str
|
title: str
|
||||||
video_type: str
|
video_type: str
|
||||||
run_time_seconds: int
|
run_time_seconds: int
|
||||||
@ -145,3 +145,10 @@ class VideoMetadata(JSONDataclass):
|
|||||||
cover_url = Optional[str]
|
cover_url = Optional[str]
|
||||||
next_imdb_id: Optional[int]
|
next_imdb_id: Optional[int]
|
||||||
tv_series_id: Optional[str]
|
tv_series_id: Optional[str]
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class VideoGameLogData(JSONDataclass):
|
||||||
|
emulated: bool = False
|
||||||
|
console: Optional[str] = None
|
||||||
|
emulator: Optional[str] = None
|
||||||
|
|||||||
@ -606,7 +606,15 @@ class Scrobble(TimeStampedModel):
|
|||||||
)
|
)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return self.media_obj.logdata_cls.from_dict(json.loads(self.log))
|
log_dict = self.log
|
||||||
|
if isinstance(self.log, str):
|
||||||
|
# There's nothing stopping django from saving a string ina JSONField :(
|
||||||
|
logger.warning(
|
||||||
|
"[scrobbles] Received string in JSON data in log",
|
||||||
|
extra={"log": self.log},
|
||||||
|
)
|
||||||
|
log_dict = json.loads(self.log)
|
||||||
|
return self.media_obj.logdata_cls.from_dict(log_dict)
|
||||||
|
|
||||||
def redirect_url(self, user_id) -> str:
|
def redirect_url(self, user_id) -> str:
|
||||||
user = User.objects.filter(id=user_id).first()
|
user = User.objects.filter(id=user_id).first()
|
||||||
|
|||||||
@ -8,6 +8,7 @@ from django.urls import reverse
|
|||||||
from django_extensions.db.models import TimeStampedModel
|
from django_extensions.db.models import TimeStampedModel
|
||||||
from imagekit.models import ImageSpecField
|
from imagekit.models import ImageSpecField
|
||||||
from imagekit.processors import ResizeToFit
|
from imagekit.processors import ResizeToFit
|
||||||
|
from scrobbles.dataclasses import VideoGameLogData
|
||||||
from scrobbles.mixins import LongPlayScrobblableMixin
|
from scrobbles.mixins import LongPlayScrobblableMixin
|
||||||
from scrobbles.utils import get_scrobbles_for_media
|
from scrobbles.utils import get_scrobbles_for_media
|
||||||
from videogames.igdb import lookup_game_id_from_gdb
|
from videogames.igdb import lookup_game_id_from_gdb
|
||||||
@ -167,6 +168,10 @@ class VideoGame(LongPlayScrobblableMixin):
|
|||||||
def get_start_url(self):
|
def get_start_url(self):
|
||||||
return reverse("scrobbles:start", kwargs={"uuid": self.uuid})
|
return reverse("scrobbles:start", kwargs={"uuid": self.uuid})
|
||||||
|
|
||||||
|
@property
|
||||||
|
def logdata_cls(self):
|
||||||
|
return VideoGameLogData
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def seconds_for_completion(self) -> int:
|
def seconds_for_completion(self) -> int:
|
||||||
completion_time = self.run_time_ticks
|
completion_time = self.run_time_ticks
|
||||||
|
|||||||
Reference in New Issue
Block a user