diff --git a/.github/workflows/django-tests.yml b/.github/workflows/django-tests.yml
index 3ce368ecd..e734d18ec 100644
--- a/.github/workflows/django-tests.yml
+++ b/.github/workflows/django-tests.yml
@@ -65,4 +65,4 @@ jobs:
EMAIL_HOST_PASSWORD: ""
EMAIL_USE_TLS: true
run: |
- python manage.py test
+ python manage.py test -v 3
diff --git a/bookwyrm/migrations/0012_progressupdate.py b/bookwyrm/migrations/0012_progressupdate.py
new file mode 100644
index 000000000..131419712
--- /dev/null
+++ b/bookwyrm/migrations/0012_progressupdate.py
@@ -0,0 +1,31 @@
+# Generated by Django 3.0.7 on 2020-11-17 07:36
+
+from django.conf import settings
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('bookwyrm', '0011_auto_20201113_1727'),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='ProgressUpdate',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('created_date', models.DateTimeField(auto_now_add=True)),
+ ('updated_date', models.DateTimeField(auto_now=True)),
+ ('remote_id', models.CharField(max_length=255, null=True)),
+ ('progress', models.IntegerField()),
+ ('mode', models.CharField(choices=[('PG', 'page'), ('PCT', 'percent')], default='PG', max_length=3)),
+ ('readthrough', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='bookwyrm.ReadThrough')),
+ ('user', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)),
+ ],
+ options={
+ 'abstract': False,
+ },
+ ),
+ ]
diff --git a/bookwyrm/migrations/0014_merge_20201128_0007.py b/bookwyrm/migrations/0014_merge_20201128_0007.py
new file mode 100644
index 000000000..e811fa7ff
--- /dev/null
+++ b/bookwyrm/migrations/0014_merge_20201128_0007.py
@@ -0,0 +1,14 @@
+# Generated by Django 3.0.7 on 2020-11-28 00:07
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('bookwyrm', '0013_book_origin_id'),
+ ('bookwyrm', '0012_progressupdate'),
+ ]
+
+ operations = [
+ ]
diff --git a/bookwyrm/migrations/0015_auto_20201128_0734.py b/bookwyrm/migrations/0015_auto_20201128_0734.py
new file mode 100644
index 000000000..c6eb78150
--- /dev/null
+++ b/bookwyrm/migrations/0015_auto_20201128_0734.py
@@ -0,0 +1,23 @@
+# Generated by Django 3.0.7 on 2020-11-28 07:34
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('bookwyrm', '0014_merge_20201128_0007'),
+ ]
+
+ operations = [
+ migrations.RenameField(
+ model_name='readthrough',
+ old_name='pages_read',
+ new_name='progress',
+ ),
+ migrations.AddField(
+ model_name='readthrough',
+ name='progress_mode',
+ field=models.CharField(choices=[('PG', 'page'), ('PCT', 'percent')], default='PG', max_length=3),
+ ),
+ ]
diff --git a/bookwyrm/migrations/0039_merge_20210120_0753.py b/bookwyrm/migrations/0039_merge_20210120_0753.py
new file mode 100644
index 000000000..1af40ee93
--- /dev/null
+++ b/bookwyrm/migrations/0039_merge_20210120_0753.py
@@ -0,0 +1,14 @@
+# Generated by Django 3.0.7 on 2021-01-20 07:53
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('bookwyrm', '0038_auto_20210119_1534'),
+ ('bookwyrm', '0015_auto_20201128_0734'),
+ ]
+
+ operations = [
+ ]
diff --git a/bookwyrm/models/__init__.py b/bookwyrm/models/__init__.py
index e71a150ba..b232e98fa 100644
--- a/bookwyrm/models/__init__.py
+++ b/bookwyrm/models/__init__.py
@@ -13,7 +13,7 @@ from .status import Boost
from .attachment import Image
from .favorite import Favorite
from .notification import Notification
-from .readthrough import ReadThrough
+from .readthrough import ReadThrough, ProgressUpdate, ProgressMode
from .tag import Tag, UserTag
diff --git a/bookwyrm/models/book.py b/bookwyrm/models/book.py
index 3f2285f74..ea7049774 100644
--- a/bookwyrm/models/book.py
+++ b/bookwyrm/models/book.py
@@ -72,6 +72,10 @@ class Book(BookDataModel):
''' format a list of authors '''
return ', '.join(a.name for a in self.authors.all())
+ @property
+ def latest_readthrough(self):
+ return self.readthrough_set.order_by('-updated_date').first()
+
@property
def edition_info(self):
''' properties of this edition, as a string '''
diff --git a/bookwyrm/models/readthrough.py b/bookwyrm/models/readthrough.py
index 61cac7e6a..7daafaaff 100644
--- a/bookwyrm/models/readthrough.py
+++ b/bookwyrm/models/readthrough.py
@@ -1,17 +1,26 @@
''' progress in a book '''
from django.db import models
from django.utils import timezone
+from django.core import validators
from .base_model import BookWyrmModel
+class ProgressMode(models.TextChoices):
+ PAGE = 'PG', 'page'
+ PERCENT = 'PCT', 'percent'
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('Edition', on_delete=models.PROTECT)
- pages_read = models.IntegerField(
+ progress = models.IntegerField(
+ validators=[validators.MinValueValidator(0)],
null=True,
blank=True)
+ progress_mode = models.CharField(
+ max_length=3,
+ choices=ProgressMode.choices,
+ default=ProgressMode.PAGE)
start_date = models.DateTimeField(
blank=True,
null=True)
@@ -24,3 +33,26 @@ class ReadThrough(BookWyrmModel):
self.user.last_active_date = timezone.now()
self.user.save()
super().save(*args, **kwargs)
+
+ def create_update(self):
+ if self.progress:
+ return self.progressupdate_set.create(
+ user=self.user,
+ progress=self.progress,
+ mode=self.progress_mode)
+
+class ProgressUpdate(BookWyrmModel):
+ ''' Store progress through a book in the database. '''
+ user = models.ForeignKey('User', on_delete=models.PROTECT)
+ readthrough = models.ForeignKey('ReadThrough', on_delete=models.CASCADE)
+ progress = models.IntegerField(validators=[validators.MinValueValidator(0)])
+ mode = models.CharField(
+ max_length=3,
+ choices=ProgressMode.choices,
+ default=ProgressMode.PAGE)
+
+ def save(self, *args, **kwargs):
+ ''' update user active time '''
+ self.user.last_active_date = timezone.now()
+ self.user.save()
+ super().save(*args, **kwargs)
diff --git a/bookwyrm/templates/feed.html b/bookwyrm/templates/feed.html
index 58acfe985..1368660bc 100644
--- a/bookwyrm/templates/feed.html
+++ b/bookwyrm/templates/feed.html
@@ -48,6 +48,10 @@
{% include 'snippets/shelve_button.html' with book=book %}
+ {% active_shelf book as active_shelf %}
+ {% if active_shelf.shelf.identifier == 'reading' and book.latest_readthrough %}
+ {% include 'snippets/progress_update.html' with readthrough=book.latest_readthrough %}
+ {% endif %}
{% include 'snippets/create_status.html' with book=book %}