diff --git a/bookwyrm/models/__init__.py b/bookwyrm/models/__init__.py index d147197d2..f16864cc1 100644 --- a/bookwyrm/models/__init__.py +++ b/bookwyrm/models/__init__.py @@ -7,7 +7,7 @@ from .connector import Connector from .relationship import UserFollows, UserFollowRequest, UserBlocks from .shelf import Shelf, ShelfBook 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 .user import User from .federated_server import FederatedServer diff --git a/bookwyrm/models/status.py b/bookwyrm/models/status.py index 91906b13d..e5395bffd 100644 --- a/bookwyrm/models/status.py +++ b/bookwyrm/models/status.py @@ -203,9 +203,6 @@ class Quotation(Status): #class Progress(Status): # ''' 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() # mode = models.TextChoices(max_length=3, choices=ProgessMode.choices, default=ProgressMode.PAGE) @@ -313,7 +310,7 @@ class Boost(Status): 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) book = models.ForeignKey('Book', on_delete=models.PROTECT) pages_read = models.IntegerField( @@ -332,6 +329,24 @@ class ReadThrough(BookWyrmModel): self.user.save() 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', diff --git a/bookwyrm/view_actions.py b/bookwyrm/view_actions.py index 83dbb4f44..6a01ac5de 100644 --- a/bookwyrm/view_actions.py +++ b/bookwyrm/view_actions.py @@ -426,6 +426,15 @@ def edit_readthrough(request): return HttpResponseBadRequest() 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', '/'))