Add progress updates as their own table

This commit is contained in:
Joel Bradshaw 2020-11-16 23:29:32 -08:00
parent 7ffc3114a6
commit 13229ea937
3 changed files with 29 additions and 5 deletions

View file

@ -7,7 +7,7 @@ from .connector import Connector
from .relationship import UserFollows, UserFollowRequest, UserBlocks from .relationship import UserFollows, UserFollowRequest, UserBlocks
from .shelf import Shelf, ShelfBook from .shelf import Shelf, ShelfBook
from .status import Status, GeneratedNote, Review, Comment, Quotation from .status import Status, GeneratedNote, Review, Comment, Quotation
from .status import Favorite, Boost, Notification, ReadThrough from .status import Favorite, Boost, Notification, ReadThrough, ProgressMode, ProgressUpdate
from .tag import Tag from .tag import Tag
from .user import User from .user import User
from .federated_server import FederatedServer from .federated_server import FederatedServer

View file

@ -203,9 +203,6 @@ class Quotation(Status):
#class Progress(Status): #class Progress(Status):
# ''' an update of where a user is in a book, using page number or % ''' # ''' an update of where a user is in a book, using page number or % '''
# class ProgressMode(models.TextChoices):
# PAGE = 'PG', 'page'
# PERCENT = 'PCT', 'percent'
# #
# progress = models.IntegerField() # progress = models.IntegerField()
# mode = models.TextChoices(max_length=3, choices=ProgessMode.choices, default=ProgressMode.PAGE) # mode = models.TextChoices(max_length=3, choices=ProgessMode.choices, default=ProgressMode.PAGE)
@ -313,7 +310,7 @@ class Boost(Status):
class ReadThrough(BookWyrmModel): class ReadThrough(BookWyrmModel):
''' Store progress through a book in the database. ''' ''' Store a read through a book in the database. '''
user = models.ForeignKey('User', on_delete=models.PROTECT) user = models.ForeignKey('User', on_delete=models.PROTECT)
book = models.ForeignKey('Book', on_delete=models.PROTECT) book = models.ForeignKey('Book', on_delete=models.PROTECT)
pages_read = models.IntegerField( pages_read = models.IntegerField(
@ -332,6 +329,24 @@ class ReadThrough(BookWyrmModel):
self.user.save() self.user.save()
super().save(*args, **kwargs) super().save(*args, **kwargs)
class ProgressMode(models.TextChoices):
PAGE = 'PG', 'page'
PERCENT = 'PCT', 'percent'
class ProgressUpdate(BookWyrmModel):
''' Store progress through a book in the database. '''
user = models.ForeignKey('User', on_delete=models.PROTECT)
book = models.ForeignKey('Book', on_delete=models.PROTECT)
progress = models.IntegerField()
mode = models.CharField(max_length=3, choices=ProgressMode.choices, default=ProgressMode.PAGE)
date = models.DateTimeField(auto_now_add=True)
def save(self, *args, **kwargs):
''' update user active time '''
self.user.last_active_date = timezone.now()
self.user.save()
super().save(*args, **kwargs)
NotificationType = models.TextChoices( NotificationType = models.TextChoices(
'NotificationType', 'NotificationType',

View file

@ -426,6 +426,15 @@ def edit_readthrough(request):
return HttpResponseBadRequest() return HttpResponseBadRequest()
readthrough.save() readthrough.save()
# record the progress update individually
# use default now for date field
progress_update = models.ProgressUpdate(
user=request.user,
book=readthrough.book,
progress=readthrough.pages_read,
mode=models.ProgressMode.PAGE)
progress_update.save()
return redirect(request.headers.get('Referer', '/')) return redirect(request.headers.get('Referer', '/'))