From 5a8a57523e1bd1ca1179b09ff653161c1d5bacb5 Mon Sep 17 00:00:00 2001 From: Adam Kelly Date: Wed, 15 Apr 2020 13:27:19 +0100 Subject: [PATCH] Create and store reading progress when shelving books. --- fedireads/outgoing.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/fedireads/outgoing.py b/fedireads/outgoing.py index 109d8cbed..6e808e0ce 100644 --- a/fedireads/outgoing.py +++ b/fedireads/outgoing.py @@ -1,4 +1,5 @@ ''' handles all the activity coming out of the server ''' +from datetime import datetime from urllib.parse import urlencode from django.db import IntegrityError, transaction @@ -138,6 +139,25 @@ def handle_shelve(user, book, shelf): status.status_type = 'Update' status.save() + if shelf.identifier == 'reading': + read = models.ReadThrough( + user=user, + book=book, + start_date=datetime.now()) + read.save() + elif shelf.identifier == 'read': + read = models.ReadThrough.objects.filter( + user=user, + book=book, + finish_date=None).order_by('-created_date').first() + if not read: + read = models.ReadThrough( + user=user, + book=book, + start_date=datetime.now()) + read.finish_date = datetime.now() + read.save() + activity = activitypub.get_status(status) create_activity = activitypub.get_create(user, activity)