56 lines
1.2 KiB
Python
56 lines
1.2 KiB
Python
import json
|
|
from dataclasses import asdict, dataclass
|
|
from typing import Optional
|
|
|
|
from dataclass_wizard import JSONWizard
|
|
from django.contrib.auth import get_user_model
|
|
from locations.models import GeoLocation
|
|
from people.models import Person
|
|
|
|
User = get_user_model()
|
|
|
|
|
|
class ScrobbleLogDataEncoder(json.JSONEncoder):
|
|
def default(self, o):
|
|
return o.__dict__
|
|
|
|
|
|
class ScrobbleLogDataDecoder(json.JSONDecoder):
|
|
def default(self, o):
|
|
return o.__dict__
|
|
|
|
|
|
class JSONDataclass(JSONWizard):
|
|
@property
|
|
def asdict(self):
|
|
return asdict(self)
|
|
|
|
@property
|
|
def json(self):
|
|
return json.dumps(self.asdict)
|
|
|
|
|
|
@dataclass
|
|
class BaseLogData(JSONDataclass):
|
|
details: Optional[str] = None
|
|
notes: Optional[str] = None
|
|
|
|
|
|
@dataclass
|
|
class LongPlayLogData(JSONDataclass):
|
|
complete: Optional[bool] = None
|
|
serial_scrobble_id: Optional[int] = None
|
|
|
|
|
|
@dataclass
|
|
class WithPeopleLogData(JSONDataclass):
|
|
with_people_ids: Optional[list[int]] = None
|
|
|
|
@property
|
|
def with_people(self) -> list["Person"]:
|
|
from people.models import Person
|
|
|
|
if not self.with_people_ids:
|
|
return []
|
|
return [Person.objects.filter(id=pid) for pid in self.with_people_ids]
|