[logdata] Janky fix to people and platform ids
This commit is contained in:
@ -3,8 +3,6 @@ from typing import Union, get_args, get_origin
|
|||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
|
|
||||||
from people.models import Person
|
|
||||||
|
|
||||||
|
|
||||||
class ExportScrobbleForm(forms.Form):
|
class ExportScrobbleForm(forms.Form):
|
||||||
"""Provide options for downloading scrobbles"""
|
"""Provide options for downloading scrobbles"""
|
||||||
@ -76,10 +74,16 @@ def django_form_field_from_type(field_type, required=True):
|
|||||||
|
|
||||||
def form_from_dataclass(dataclass):
|
def form_from_dataclass(dataclass):
|
||||||
form_fields = {}
|
form_fields = {}
|
||||||
# Override notes field
|
override_fields = {}
|
||||||
|
for klass in dataclass.mro():
|
||||||
|
if hasattr(klass, "override_fields"):
|
||||||
|
print(klass, ": ", klass.override_fields())
|
||||||
|
override_fields.update(klass.override_fields())
|
||||||
|
print("overrides: ", override_fields)
|
||||||
for f in fields(dataclass):
|
for f in fields(dataclass):
|
||||||
if f.name in dataclass.override_fields():
|
print(f)
|
||||||
form_fields[f.name] = dataclass.override_fields()[f.name]
|
if f.name in override_fields:
|
||||||
|
form_fields[f.name] = override_fields[f.name]
|
||||||
continue
|
continue
|
||||||
|
|
||||||
required = f.default is None and f.default_factory is None
|
required = f.default is None and f.default_factory is None
|
||||||
|
|||||||
@ -969,11 +969,14 @@ class ScrobbleDetailView(DetailView):
|
|||||||
original_value = (self.object.log or {}).get(field_name)
|
original_value = (self.object.log or {}).get(field_name)
|
||||||
data[field_name] = original_value
|
data[field_name] = original_value
|
||||||
|
|
||||||
if "with_people_ids" in data:
|
if data.get("with_people_ids", False):
|
||||||
data["with_people_ids"] = [
|
data["with_people_ids"] = [
|
||||||
p.id for p in data["with_people_ids"]
|
p.id for p in data["with_people_ids"]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
if data.get("platform_id", False):
|
||||||
|
data["platform_id"] = data["platform_id"].id
|
||||||
|
|
||||||
self.object.log = data
|
self.object.log = data
|
||||||
self.object.save(update_fields=["log"])
|
self.object.save(update_fields=["log"])
|
||||||
return redirect(self.object.get_absolute_url())
|
return redirect(self.object.get_absolute_url())
|
||||||
|
|||||||
@ -39,20 +39,13 @@ class VideoGameLogData(BaseLogData, LongPlayLogData, WithPeopleLogData):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def override_fields(cls) -> dict:
|
def override_fields(cls) -> dict:
|
||||||
fields = {}
|
return {
|
||||||
for base in cls.mro()[1:]:
|
|
||||||
if hasattr(base, "override_fields"):
|
|
||||||
base_fields = base.override_fields()
|
|
||||||
fields.update(base_fields)
|
|
||||||
custom_fields = {
|
|
||||||
"platform_id": forms.ModelChoiceField(
|
"platform_id": forms.ModelChoiceField(
|
||||||
queryset=VideoGamePlatform.objects.all(),
|
queryset=VideoGamePlatform.objects.all(),
|
||||||
required=False,
|
required=False,
|
||||||
widget=forms.Select(),
|
widget=forms.Select(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
fields.update(custom_fields)
|
|
||||||
return fields
|
|
||||||
|
|
||||||
|
|
||||||
class VideoGamePlatform(TimeStampedModel):
|
class VideoGamePlatform(TimeStampedModel):
|
||||||
@ -70,19 +63,6 @@ class VideoGamePlatform(TimeStampedModel):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class VideoGameLogData(BaseLogData, LongPlayLogData, WithPeopleLogData):
|
|
||||||
platform_id: Optional[int] = None
|
|
||||||
emulated: Optional[bool] = False
|
|
||||||
emulator: Optional[str] = None
|
|
||||||
|
|
||||||
@property
|
|
||||||
def platform(self) -> VideoGamePlatform | None:
|
|
||||||
if not self.platform_id:
|
|
||||||
return
|
|
||||||
return VideoGamePlatform.objects.filter(id=self.platform_id).first()
|
|
||||||
|
|
||||||
|
|
||||||
class VideoGameCollection(TimeStampedModel):
|
class VideoGameCollection(TimeStampedModel):
|
||||||
name = models.CharField(max_length=255)
|
name = models.CharField(max_length=255)
|
||||||
uuid = models.UUIDField(default=uuid4, editable=False, **BNULL)
|
uuid = models.UUIDField(default=uuid4, editable=False, **BNULL)
|
||||||
|
|||||||
Reference in New Issue
Block a user