Bladeren bron

[tasks] Make tasks use user profile string

Colin Powell 6 maanden geleden
bovenliggende
commit
88a3831975

+ 1 - 1
vrobbler/apps/profiles/models.py

@@ -56,7 +56,7 @@ class UserProfile(TimeStampedModel):
         return pytz.timezone(self.timezone)
 
     @cached_property
-    def task_context_tags(self) -> list:
+    def task_context_tags(self) -> list[str]:
         tag_list = [
             t.strip().capitalize()
             for t in self.task_context_tags_str.split(",")

+ 4 - 11
vrobbler/apps/scrobbles/scrobblers.py

@@ -34,10 +34,6 @@ from videos.models import Video
 from tasks.utils import get_title_from_labels
 from webpages.models import WebPage
 
-from vrobbler.apps.tasks.constants import (
-    TODOIST_TITLE_LABELS
-)
-
 logger = logging.getLogger(__name__)
 
 
@@ -413,9 +409,9 @@ def todoist_scrobble_task(
     user_id: int,
     started: bool = False,
     stopped: bool = False,
+    context_list: list = [],
 ) -> Scrobble:
-
-    title = get_title_from_labels(todoist_task.get("todoist_label_list", []))
+    title = get_title_from_labels(todoist_task.get("todoist_label_list", []), context_list)
     task = Task.find_or_create(title)
 
     timestamp = pendulum.parse(todoist_task.get("updated_at", timezone.now()))
@@ -537,13 +533,10 @@ def emacs_scrobble_task(
     user_id: int,
     started: bool = False,
     stopped: bool = False,
+    context_list: list[str] = [],
 ) -> Scrobble | None:
-
-    prefix = ""
-    suffix = ""
-
     source_id = task_data.get("source_id")
-    title = get_title_from_labels(task_data.get("labels", []))
+    title = get_title_from_labels(task_data.get("labels", []), context_list)
 
     task = Task.find_or_create(title)
 

+ 0 - 15
vrobbler/apps/tasks/constants.py

@@ -1,15 +0,0 @@
-DEFAULT_TASK_CONTEXT_LABELS = [
-    "bug",
-    "feature",
-    "errand",
-    "chore",
-    "admin",
-    "computer",
-    "farm",
-    "baking",
-    "meeting",
-    "habit",
-    "research",
-    "exercise",
-    "lifeevent",
-]

+ 2 - 6
vrobbler/apps/tasks/webhooks.py

@@ -90,16 +90,12 @@ def todoist_webhook(request):
         )
         return Response({}, status=status.HTTP_304_NOT_MODIFIED)
 
-    user_id = (
-        UserProfile.objects.filter(todoist_user_id=post_data.get("user_id"))
-        .first()
-        .user_id
-    )
+    user_profile = UserProfile.objects.filter(todoist_user_id=post_data.get("user_id")).first()
 
     scrobble = None
     if todoist_task:
         scrobble = todoist_scrobble_task(
-            todoist_task, user_id, stopped=task_stopped
+            todoist_task, user_profile.user_id, stopped=task_stopped, context_list=user_profile.task_context_tags
         )
 
     if todoist_note: