From 88a38319759e764eb89c2281e4ccbf64dc122bb3 Mon Sep 17 00:00:00 2001 From: Colin Powell Date: Fri, 27 Jun 2025 10:48:05 -0400 Subject: [PATCH] [tasks] Make tasks use user profile string --- vrobbler/apps/profiles/models.py | 2 +- vrobbler/apps/scrobbles/scrobblers.py | 15 ++++----------- vrobbler/apps/tasks/constants.py | 15 --------------- vrobbler/apps/tasks/webhooks.py | 8 ++------ 4 files changed, 7 insertions(+), 33 deletions(-) delete mode 100644 vrobbler/apps/tasks/constants.py diff --git a/vrobbler/apps/profiles/models.py b/vrobbler/apps/profiles/models.py index 3b660bc..4d7f83c 100644 --- a/vrobbler/apps/profiles/models.py +++ b/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(",") diff --git a/vrobbler/apps/scrobbles/scrobblers.py b/vrobbler/apps/scrobbles/scrobblers.py index 41a58ae..baefea4 100644 --- a/vrobbler/apps/scrobbles/scrobblers.py +++ b/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) diff --git a/vrobbler/apps/tasks/constants.py b/vrobbler/apps/tasks/constants.py deleted file mode 100644 index 4fca01c..0000000 --- a/vrobbler/apps/tasks/constants.py +++ /dev/null @@ -1,15 +0,0 @@ -DEFAULT_TASK_CONTEXT_LABELS = [ - "bug", - "feature", - "errand", - "chore", - "admin", - "computer", - "farm", - "baking", - "meeting", - "habit", - "research", - "exercise", - "lifeevent", -] diff --git a/vrobbler/apps/tasks/webhooks.py b/vrobbler/apps/tasks/webhooks.py index 538ed4a..6971a3b 100644 --- a/vrobbler/apps/tasks/webhooks.py +++ b/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: