Add ability to manage long plays
This commit is contained in:
@ -1,9 +1,11 @@
|
||||
import logging
|
||||
from typing import Dict
|
||||
from typing import Optional
|
||||
from uuid import uuid4
|
||||
|
||||
from django.db import models
|
||||
from django.urls import reverse
|
||||
from django_extensions.db.models import TimeStampedModel
|
||||
from scrobbles.utils import get_scrobbles_for_media
|
||||
|
||||
BNULL = {"blank": True, "null": True}
|
||||
|
||||
@ -27,3 +29,19 @@ class ScrobblableMixin(TimeStampedModel):
|
||||
@classmethod
|
||||
def find_or_create(cls):
|
||||
logger.warn("find_or_create() not implemented yet")
|
||||
|
||||
|
||||
class LongPlayScrobblableMixin(ScrobblableMixin):
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
def get_longplay_finish_url(self):
|
||||
return reverse("scrobbles:longplay-finish", kwargs={"uuid": self.uuid})
|
||||
|
||||
def last_long_play_scrobble_for_user(self, user) -> Optional["Scrobble"]:
|
||||
return (
|
||||
get_scrobbles_for_media(self, user)
|
||||
.filter(long_play_complete=False)
|
||||
.order_by("-timestamp")
|
||||
.first()
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user