[tasks] Add user id to Profile
This commit is contained in:
@ -0,0 +1,18 @@
|
||||
# Generated by Django 4.2.16 on 2024-10-15 18:47
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("profiles", "0017_userprofile_todoist_auth_key_and_more"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="userprofile",
|
||||
name="todoist_user_id",
|
||||
field=models.CharField(blank=True, max_length=100, null=True),
|
||||
),
|
||||
]
|
||||
@ -33,6 +33,7 @@ class UserProfile(TimeStampedModel):
|
||||
|
||||
todoist_auth_key = EncryptedField(**BNULL)
|
||||
todoist_state = EncryptedField(**BNULL)
|
||||
todoist_user_id = models.CharField(max_length=100, **BNULL)
|
||||
|
||||
redirect_to_webpage = models.BooleanField(default=True)
|
||||
|
||||
|
||||
@ -0,0 +1,25 @@
|
||||
# Generated by Django 4.2.16 on 2024-10-15 18:47
|
||||
|
||||
from django.db import migrations, models
|
||||
import scrobbles.dataclasses
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("scrobbles", "0064_scrobble_task_alter_scrobble_media_type"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="scrobble",
|
||||
name="log",
|
||||
field=models.JSONField(
|
||||
blank=True,
|
||||
decoder=scrobbles.dataclasses.ScrobbleLogDataDecoder,
|
||||
default=dict,
|
||||
encoder=scrobbles.dataclasses.ScrobbleLogDataEncoder,
|
||||
null=True,
|
||||
),
|
||||
),
|
||||
]
|
||||
@ -1246,9 +1246,8 @@ class Scrobble(TimeStampedModel):
|
||||
|
||||
# Set our playback seconds, and calc long play seconds
|
||||
self.playback_position_seconds = seconds_elapsed
|
||||
past_seconds = 0
|
||||
if self.previous:
|
||||
past_seconds = self.previous.long_play_seconds
|
||||
past_seconds = self.previous.long_play_seconds or 0
|
||||
|
||||
self.long_play_seconds = past_seconds + seconds_elapsed
|
||||
|
||||
|
||||
@ -0,0 +1,21 @@
|
||||
# Generated by Django 4.2.16 on 2024-10-15 18:47
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("tasks", "0002_task_source_task_source_url_pattern"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name="task",
|
||||
name="source",
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name="task",
|
||||
name="source_url_pattern",
|
||||
),
|
||||
]
|
||||
@ -10,6 +10,7 @@ from scrobbles.scrobblers import (
|
||||
todoist_scrobble_task,
|
||||
todoist_scrobble_task_finish,
|
||||
)
|
||||
from profiles.models import UserProfile
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -51,11 +52,20 @@ 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
|
||||
)
|
||||
# TODO huge hack, find a way to populate user id from Todoist
|
||||
if not user_id:
|
||||
user_id = 1
|
||||
|
||||
scrobble = None
|
||||
if "completed" in todoist_task["todoist_event"]:
|
||||
scrobble = todoist_scrobble_task_finish(todoist_task, request.user.id)
|
||||
scrobble = todoist_scrobble_task_finish(todoist_task, user_id)
|
||||
elif "inprogress" in todoist_task["todoist_label_list"]:
|
||||
scrobble = todoist_scrobble_task(todoist_task, request.user.id)
|
||||
scrobble = todoist_scrobble_task(todoist_task, user_id)
|
||||
|
||||
if not scrobble:
|
||||
return Response({}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
Reference in New Issue
Block a user