Create and store reading progress when shelving books.

This commit is contained in:
Adam Kelly 2020-04-15 13:27:19 +01:00
parent 8e12071b99
commit 5a8a57523e

View file

@ -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)