[tasks] Allow scrobbling tasks from URLs

This commit is contained in:
2024-10-05 15:08:38 -04:00
parent 342e86d7fb
commit c251c5f413
4 changed files with 74 additions and 24 deletions

View File

@ -7,14 +7,10 @@ from django.db import models
from django.urls import reverse
from scrobbles.dataclasses import LongPlayLogData
from scrobbles.mixins import LongPlayScrobblableMixin
from scrobbles.constants import TASK_SOURCE_URL_PATTERNS
BNULL = {"blank": True, "null": True}
TASK_SOURCE_URL_PATTERNS = [
("https://app.shortcut.com/sure/story/{id}", "Shortcut"),
("https://app.todoist.com/app/task/{id}", "Todoist"),
]
@dataclass
class TaskLogData(LongPlayLogData):
@ -66,7 +62,7 @@ class Task(LongPlayScrobblableMixin):
@classmethod
def find_or_create(cls, title: str) -> "Task":
return cls.objects.filter(title=title).first()
return cls.objects.get_or_create(title=title)[0]
def scrobbles(self, user_id):
Scrobble = apps.get_model("scrobbles", "Scrobble")