From 3beebe4727aa84f5c3628fa79c3dfa9250d08842 Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Mon, 16 Nov 2020 22:33:04 -0800 Subject: [PATCH 01/36] Add initial draft of progress update --- bookwyrm/activitypub/note.py | 6 ++++++ bookwyrm/models/status.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/bookwyrm/activitypub/note.py b/bookwyrm/activitypub/note.py index ebc0cf3c..f4a22c41 100644 --- a/bookwyrm/activitypub/note.py +++ b/bookwyrm/activitypub/note.py @@ -63,3 +63,9 @@ class Quotation(Comment): ''' a quote and commentary on a book ''' quote: str type: str = 'Quotation' + +@dataclass(init=False) +class Progress(Comment): + ''' a progress update on a book ''' + quote: str + type: str = 'Progress' diff --git a/bookwyrm/models/status.py b/bookwyrm/models/status.py index 09ceda85..c56fa395 100644 --- a/bookwyrm/models/status.py +++ b/bookwyrm/models/status.py @@ -201,6 +201,35 @@ class Quotation(Status): activity_serializer = activitypub.Quotation pure_activity_serializer = activitypub.Note +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) + book = models.ForeignKey('Edition', on_delete=models.PROTECT) + + @property + def ap_pure_content(self): + ''' indicate the book in question for mastodon (or w/e) users ''' + if self.mode == ProgressMode.PAGE: + return 'on page %d of %d in "%s"' % ( + self.progress, + self.book.pages, + self.book.remote_id, + self.book.title, + ) + else: + return '%d%% of the way through "%s"' % ( + self.progress, + self.book.remote_id, + self.book.title, + ) + + activity_serializer = activitypub.Progress + pure_activity_serializer = activitypub.Note class Review(Status): ''' a book review ''' From 7ffc3114a6f4fcf3ef08de2df2911ed610dd5d6d Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Mon, 16 Nov 2020 22:47:55 -0800 Subject: [PATCH 02/36] Add display and form for existing pages_read Commented out the new update type because it was breaking and I don't need it quite yet --- bookwyrm/models/status.py | 58 ++++++++++++++++++------------------ bookwyrm/templates/book.html | 9 ++++++ bookwyrm/view_actions.py | 8 +++++ 3 files changed, 46 insertions(+), 29 deletions(-) diff --git a/bookwyrm/models/status.py b/bookwyrm/models/status.py index c56fa395..91906b13 100644 --- a/bookwyrm/models/status.py +++ b/bookwyrm/models/status.py @@ -201,35 +201,35 @@ class Quotation(Status): activity_serializer = activitypub.Quotation pure_activity_serializer = activitypub.Note -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) - book = models.ForeignKey('Edition', on_delete=models.PROTECT) - - @property - def ap_pure_content(self): - ''' indicate the book in question for mastodon (or w/e) users ''' - if self.mode == ProgressMode.PAGE: - return 'on page %d of %d in "%s"' % ( - self.progress, - self.book.pages, - self.book.remote_id, - self.book.title, - ) - else: - return '%d%% of the way through "%s"' % ( - self.progress, - self.book.remote_id, - self.book.title, - ) - - activity_serializer = activitypub.Progress - pure_activity_serializer = activitypub.Note +#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) +# book = models.ForeignKey('Edition', on_delete=models.PROTECT) +# +# @property +# def ap_pure_content(self): +# ''' indicate the book in question for mastodon (or w/e) users ''' +# if self.mode == ProgressMode.PAGE: +# return 'on page %d of %d in "%s"' % ( +# self.progress, +# self.book.pages, +# self.book.remote_id, +# self.book.title, +# ) +# else: +# return '%d%% of the way through "%s"' % ( +# self.progress, +# self.book.remote_id, +# self.book.title, +# ) +# +# activity_serializer = activitypub.Progress +# pure_activity_serializer = activitypub.Note class Review(Status): ''' a book review ''' diff --git a/bookwyrm/templates/book.html b/bookwyrm/templates/book.html index b0064e1f..db386442 100644 --- a/bookwyrm/templates/book.html +++ b/bookwyrm/templates/book.html @@ -74,6 +74,9 @@ {% if readthrough.finish_date %}
Finished reading:
{{ readthrough.finish_date | naturalday }}
+ {% elif readthrough.pages_read %} +
On page:
+
{{ readthrough.pages_read}} of {{ book.pages }}
{% endif %}
@@ -104,6 +107,12 @@
+
+ +
diff --git a/bookwyrm/views.py b/bookwyrm/views.py index 94d9366c..9748481a 100644 --- a/bookwyrm/views.py +++ b/bookwyrm/views.py @@ -581,6 +581,7 @@ def book_page(request, book_id): 'tags': tags, 'user_tags': user_tags, 'readthroughs': readthroughs, + 'show_progress': ('showprogress' in request.GET), 'path': '/book/%s' % book_id, 'info_fields': [ {'name': 'ISBN', 'value': book.isbn_13}, From a579ea52f48428ca09553997a8a9c40fbc4f3070 Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Thu, 19 Nov 2020 19:38:38 -0800 Subject: [PATCH 08/36] Add initial inline progress update Doesn't work yet --- bookwyrm/static/css/format.css | 13 +++++++++++++ bookwyrm/templates/snippets/progress_update.html | 5 +++++ bookwyrm/templates/snippets/shelve_button.html | 4 ++++ 3 files changed, 22 insertions(+) create mode 100644 bookwyrm/templates/snippets/progress_update.html diff --git a/bookwyrm/static/css/format.css b/bookwyrm/static/css/format.css index db3c20ef..9c116c7d 100644 --- a/bookwyrm/static/css/format.css +++ b/bookwyrm/static/css/format.css @@ -57,6 +57,19 @@ input.toggle-control:checked ~ .modal.toggle-content { content: '\e9d7'; } +/* progress update */ +.progress-update { + padding: 0 0.5rem; +} +.progress-update.is-small, +.progress-update input.is-small { + font-size: 0.75rem; +} + +.progress-update input { + width: 3em; +} + /* --- BOOK COVERS --- */ .cover-container { diff --git a/bookwyrm/templates/snippets/progress_update.html b/bookwyrm/templates/snippets/progress_update.html new file mode 100644 index 00000000..df9018a8 --- /dev/null +++ b/bookwyrm/templates/snippets/progress_update.html @@ -0,0 +1,5 @@ +
+ on page + + of +
diff --git a/bookwyrm/templates/snippets/shelve_button.html b/bookwyrm/templates/snippets/shelve_button.html index 3b924324..d8ed438f 100644 --- a/bookwyrm/templates/snippets/shelve_button.html +++ b/bookwyrm/templates/snippets/shelve_button.html @@ -63,6 +63,10 @@ {% endwith %} + + {% if active_shelf.identifier == 'reading' %} + {% include 'snippets/progress_update.html' %} + {% endif %} {% endif %} From f57d9ee45d9df20b8292dac91391d7476ea8a438 Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Fri, 20 Nov 2020 21:45:12 -0800 Subject: [PATCH 09/36] Rework to use bulma better --- bookwyrm/static/css/format.css | 14 -------------- bookwyrm/templates/snippets/progress_update.html | 10 ++++++---- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/bookwyrm/static/css/format.css b/bookwyrm/static/css/format.css index 9c116c7d..f14b06f2 100644 --- a/bookwyrm/static/css/format.css +++ b/bookwyrm/static/css/format.css @@ -57,20 +57,6 @@ input.toggle-control:checked ~ .modal.toggle-content { content: '\e9d7'; } -/* progress update */ -.progress-update { - padding: 0 0.5rem; -} -.progress-update.is-small, -.progress-update input.is-small { - font-size: 0.75rem; -} - -.progress-update input { - width: 3em; -} - - /* --- BOOK COVERS --- */ .cover-container { height: 250px; diff --git a/bookwyrm/templates/snippets/progress_update.html b/bookwyrm/templates/snippets/progress_update.html index df9018a8..a6def952 100644 --- a/bookwyrm/templates/snippets/progress_update.html +++ b/bookwyrm/templates/snippets/progress_update.html @@ -1,5 +1,7 @@ -
- on page - - of +
+
on page
+
+ +
+
of 100
From e7c036816821c46b65a74b83099018a01be5f9ee Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Wed, 25 Nov 2020 22:36:55 -0800 Subject: [PATCH 10/36] PR feedback --- bookwyrm/activitypub/note.py | 6 ------ bookwyrm/templates/snippets/progress_update.html | 2 +- bookwyrm/views.py | 3 ++- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/bookwyrm/activitypub/note.py b/bookwyrm/activitypub/note.py index f4a22c41..ebc0cf3c 100644 --- a/bookwyrm/activitypub/note.py +++ b/bookwyrm/activitypub/note.py @@ -63,9 +63,3 @@ class Quotation(Comment): ''' a quote and commentary on a book ''' quote: str type: str = 'Quotation' - -@dataclass(init=False) -class Progress(Comment): - ''' a progress update on a book ''' - quote: str - type: str = 'Progress' diff --git a/bookwyrm/templates/snippets/progress_update.html b/bookwyrm/templates/snippets/progress_update.html index a6def952..a93ac839 100644 --- a/bookwyrm/templates/snippets/progress_update.html +++ b/bookwyrm/templates/snippets/progress_update.html @@ -1,7 +1,7 @@
on page
- +
of 100
diff --git a/bookwyrm/views.py b/bookwyrm/views.py index 9748481a..19d3af97 100644 --- a/bookwyrm/views.py +++ b/bookwyrm/views.py @@ -563,7 +563,8 @@ def book_page(request, book_id): ).order_by('start_date') for readthrough in readthroughs: - readthrough.progress_updates = readthrough.progressupdate_set.all().order_by('date') + readthrough.progress_updates = \ + readthrough.progressupdate_set.all().order_by('date') rating = reviews.aggregate(Avg('rating')) tags = models.Tag.objects.filter( From 090cf2aea7ed459f9ea92c3fbb6f8e023782ca0f Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Wed, 25 Nov 2020 22:37:18 -0800 Subject: [PATCH 11/36] Make inline progress form actually work --- bookwyrm/models/book.py | 4 ++++ bookwyrm/templates/feed.html | 12 +++++++++++- bookwyrm/templates/snippets/progress_update.html | 15 +++++++++++---- bookwyrm/templates/snippets/shelve_button.html | 4 ---- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/bookwyrm/models/book.py b/bookwyrm/models/book.py index d0702a3e..0c81f059 100644 --- a/bookwyrm/models/book.py +++ b/bookwyrm/models/book.py @@ -74,6 +74,10 @@ class Book(ActivitypubMixin, BookWyrmModel): ''' reference the work via local id not remote ''' return self.parent_work.remote_id + @property + def latest_readthrough(self): + return self.readthrough_set.order_by('-updated_date').first() + activity_mappings = [ ActivityMapping('id', 'remote_id'), diff --git a/bookwyrm/templates/feed.html b/bookwyrm/templates/feed.html index ed1fea0f..474f4fbc 100644 --- a/bookwyrm/templates/feed.html +++ b/bookwyrm/templates/feed.html @@ -46,7 +46,17 @@ diff --git a/bookwyrm/templates/snippets/progress_update.html b/bookwyrm/templates/snippets/progress_update.html index a93ac839..51385b97 100644 --- a/bookwyrm/templates/snippets/progress_update.html +++ b/bookwyrm/templates/snippets/progress_update.html @@ -1,7 +1,14 @@ -
+
+ {% csrf_token %} +
on page
- +
-
of 100
-
+ {% if book.pages %} +
of {{ book.pages }}
+ {% endif %} +
+ +
+ diff --git a/bookwyrm/templates/snippets/shelve_button.html b/bookwyrm/templates/snippets/shelve_button.html index d8ed438f..3b924324 100644 --- a/bookwyrm/templates/snippets/shelve_button.html +++ b/bookwyrm/templates/snippets/shelve_button.html @@ -63,10 +63,6 @@
{% endwith %} - - {% if active_shelf.identifier == 'reading' %} - {% include 'snippets/progress_update.html' %} - {% endif %} {% endif %} From 64fb88cc101ba6b937d8ad8dfa7049821cbf936e Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Wed, 25 Nov 2020 22:56:41 -0800 Subject: [PATCH 12/36] ProgressUpdate doesn't need its own date field Just use the base model's created_date --- bookwyrm/migrations/0012_progressupdate.py | 1 - bookwyrm/models/status.py | 1 - bookwyrm/templates/book.html | 2 +- bookwyrm/views.py | 2 +- 4 files changed, 2 insertions(+), 4 deletions(-) diff --git a/bookwyrm/migrations/0012_progressupdate.py b/bookwyrm/migrations/0012_progressupdate.py index 6fec6ca5..13141971 100644 --- a/bookwyrm/migrations/0012_progressupdate.py +++ b/bookwyrm/migrations/0012_progressupdate.py @@ -21,7 +21,6 @@ class Migration(migrations.Migration): ('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)), - ('date', models.DateTimeField(auto_now_add=True)), ('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)), ], diff --git a/bookwyrm/models/status.py b/bookwyrm/models/status.py index d52a1008..934a8838 100644 --- a/bookwyrm/models/status.py +++ b/bookwyrm/models/status.py @@ -339,7 +339,6 @@ class ProgressUpdate(BookWyrmModel): readthrough = models.ForeignKey('ReadThrough', 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 ''' diff --git a/bookwyrm/templates/book.html b/bookwyrm/templates/book.html index fe2691f1..2bd9fc77 100644 --- a/bookwyrm/templates/book.html +++ b/bookwyrm/templates/book.html @@ -95,7 +95,7 @@ Progress Updates:
{% for progress_update in readthrough.progress_updates %} -
{{ progress_update.date | naturalday }}:
+
{{ progress_update.created_date | naturalday }}:
{{ progress_update.progress }} of {{ book.pages }}
{% endfor %}
diff --git a/bookwyrm/views.py b/bookwyrm/views.py index 19d3af97..5ccc343e 100644 --- a/bookwyrm/views.py +++ b/bookwyrm/views.py @@ -564,7 +564,7 @@ def book_page(request, book_id): for readthrough in readthroughs: readthrough.progress_updates = \ - readthrough.progressupdate_set.all().order_by('date') + readthrough.progressupdate_set.all().order_by('updated_date') rating = reviews.aggregate(Avg('rating')) tags = models.Tag.objects.filter( From 692aa0836478f99edaf080ec58e02be2b7f5f8c3 Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Wed, 25 Nov 2020 23:11:30 -0800 Subject: [PATCH 13/36] Remove unneeded class, wrap line --- bookwyrm/models/status.py | 32 ++++---------------------------- 1 file changed, 4 insertions(+), 28 deletions(-) diff --git a/bookwyrm/models/status.py b/bookwyrm/models/status.py index 934a8838..406de240 100644 --- a/bookwyrm/models/status.py +++ b/bookwyrm/models/status.py @@ -201,33 +201,6 @@ class Quotation(Status): activity_serializer = activitypub.Quotation pure_activity_serializer = activitypub.Note -#class Progress(Status): -# ''' an update of where a user is in a book, using page number or % ''' -# -# progress = models.IntegerField() -# mode = models.TextChoices(max_length=3, choices=ProgessMode.choices, default=ProgressMode.PAGE) -# book = models.ForeignKey('Edition', on_delete=models.PROTECT) -# -# @property -# def ap_pure_content(self): -# ''' indicate the book in question for mastodon (or w/e) users ''' -# if self.mode == ProgressMode.PAGE: -# return 'on page %d of %d in "%s"' % ( -# self.progress, -# self.book.pages, -# self.book.remote_id, -# self.book.title, -# ) -# else: -# return '%d%% of the way through "%s"' % ( -# self.progress, -# self.book.remote_id, -# self.book.title, -# ) -# -# activity_serializer = activitypub.Progress -# pure_activity_serializer = activitypub.Note - class Review(Status): ''' a book review ''' name = models.CharField(max_length=255, null=True) @@ -338,7 +311,10 @@ class ProgressUpdate(BookWyrmModel): user = models.ForeignKey('User', on_delete=models.PROTECT) readthrough = models.ForeignKey('ReadThrough', on_delete=models.PROTECT) progress = models.IntegerField() - mode = models.CharField(max_length=3, choices=ProgressMode.choices, default=ProgressMode.PAGE) + mode = models.CharField( + max_length=3, + choices=ProgressMode.choices, + default=ProgressMode.PAGE) def save(self, *args, **kwargs): ''' update user active time ''' From 97e49c4bd23d81b1c97201e9a2db04cee49bb490 Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Wed, 25 Nov 2020 23:12:05 -0800 Subject: [PATCH 14/36] Undo stray css edit --- bookwyrm/static/css/format.css | 1 + 1 file changed, 1 insertion(+) diff --git a/bookwyrm/static/css/format.css b/bookwyrm/static/css/format.css index f14b06f2..db3c20ef 100644 --- a/bookwyrm/static/css/format.css +++ b/bookwyrm/static/css/format.css @@ -57,6 +57,7 @@ input.toggle-control:checked ~ .modal.toggle-content { content: '\e9d7'; } + /* --- BOOK COVERS --- */ .cover-container { height: 250px; From 3b0b8f16f66dfbce89b6b947ba978b734f229a12 Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Fri, 27 Nov 2020 16:07:53 -0800 Subject: [PATCH 15/36] Merge migration branches Also add $@ to bw-dev migrations, and factor the shift 1 out --- bookwyrm/migrations/0014_merge_20201128_0007.py | 14 ++++++++++++++ bw-dev | 9 ++++----- 2 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 bookwyrm/migrations/0014_merge_20201128_0007.py diff --git a/bookwyrm/migrations/0014_merge_20201128_0007.py b/bookwyrm/migrations/0014_merge_20201128_0007.py new file mode 100644 index 00000000..e811fa7f --- /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/bw-dev b/bw-dev index 53c8e52d..a6a1f326 100755 --- a/bw-dev +++ b/bw-dev @@ -38,7 +38,9 @@ function initdb { execweb python manage.py initdb } -case "$1" in +CMD=$1 +shift +case "$CMD" in up) docker-compose up --build ;; @@ -57,11 +59,10 @@ case "$1" in clean ;; makemigrations) - execweb python manage.py makemigrations + execweb python manage.py makemigrations "$@" ;; migrate) execweb python manage.py rename_app fedireads bookwyrm - shift 1 execweb python manage.py migrate "$@" ;; bash) @@ -77,11 +78,9 @@ case "$1" in docker-compose restart celery_worker ;; test) - shift 1 execweb coverage run --source='.' --omit="*/test*,celerywyrm*,bookwyrm/migrations/*" manage.py test "$@" ;; pytest) - shift 1 execweb pytest "$@" ;; test_report) From 5f2ac6d9610876fbde25e03a6dc1711968b242d7 Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Fri, 27 Nov 2020 16:12:47 -0800 Subject: [PATCH 16/36] Rename fr_* to bw_* --- bookwyrm/tests/connectors/test_bookwyrm_connector.py | 6 +++--- bookwyrm/tests/data/{fr_edition.json => bw_edition.json} | 0 bookwyrm/tests/data/{fr_search.json => bw_search.json} | 0 bookwyrm/tests/data/{fr_work.json => bw_work.json} | 0 bookwyrm/tests/test_broadcast.py | 4 ++-- 5 files changed, 5 insertions(+), 5 deletions(-) rename bookwyrm/tests/data/{fr_edition.json => bw_edition.json} (100%) rename bookwyrm/tests/data/{fr_search.json => bw_search.json} (100%) rename bookwyrm/tests/data/{fr_work.json => bw_work.json} (100%) diff --git a/bookwyrm/tests/connectors/test_bookwyrm_connector.py b/bookwyrm/tests/connectors/test_bookwyrm_connector.py index c41b454c..94abd6c5 100644 --- a/bookwyrm/tests/connectors/test_bookwyrm_connector.py +++ b/bookwyrm/tests/connectors/test_bookwyrm_connector.py @@ -22,9 +22,9 @@ class BookWyrmConnector(TestCase): self.connector = Connector('example.com') work_file = pathlib.Path(__file__).parent.joinpath( - '../data/fr_work.json') + '../data/bw_work.json') edition_file = pathlib.Path(__file__).parent.joinpath( - '../data/fr_edition.json') + '../data/bw_edition.json') self.work_data = json.loads(work_file.read_bytes()) self.edition_data = json.loads(edition_file.read_bytes()) @@ -35,7 +35,7 @@ class BookWyrmConnector(TestCase): def test_format_search_result(self): - datafile = pathlib.Path(__file__).parent.joinpath('../data/fr_search.json') + datafile = pathlib.Path(__file__).parent.joinpath('../data/bw_search.json') search_data = json.loads(datafile.read_bytes()) results = self.connector.parse_search_data(search_data) self.assertIsInstance(results, list) diff --git a/bookwyrm/tests/data/fr_edition.json b/bookwyrm/tests/data/bw_edition.json similarity index 100% rename from bookwyrm/tests/data/fr_edition.json rename to bookwyrm/tests/data/bw_edition.json diff --git a/bookwyrm/tests/data/fr_search.json b/bookwyrm/tests/data/bw_search.json similarity index 100% rename from bookwyrm/tests/data/fr_search.json rename to bookwyrm/tests/data/bw_search.json diff --git a/bookwyrm/tests/data/fr_work.json b/bookwyrm/tests/data/bw_work.json similarity index 100% rename from bookwyrm/tests/data/fr_work.json rename to bookwyrm/tests/data/bw_work.json diff --git a/bookwyrm/tests/test_broadcast.py b/bookwyrm/tests/test_broadcast.py index 1112b3fa..addbd55e 100644 --- a/bookwyrm/tests/test_broadcast.py +++ b/bookwyrm/tests/test_broadcast.py @@ -24,14 +24,14 @@ class Book(TestCase): inbox='http://example.com/u/2/inbox') self.user.followers.add(no_inbox_follower) - non_fr_follower = models.User.objects.create_user( + non_bw_follower = models.User.objects.create_user( 'gerbil', 'gerb@mouse.mouse', 'gerbword', remote_id='http://example.com/u/3', outbox='http://example2.com/u/3/o', inbox='http://example2.com/u/3/inbox', shared_inbox='http://example2.com/inbox', bookwyrm_user=False, local=False) - self.user.followers.add(non_fr_follower) + self.user.followers.add(non_bw_follower) local_follower = models.User.objects.create_user( 'joe', 'joe@mouse.mouse', 'jeoword') From f86140c7e4926a5c2ff7a5ced00e57c1b48994e0 Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Fri, 27 Nov 2020 17:39:15 -0800 Subject: [PATCH 17/36] Move -x down to eliminate pointless noise --- bw-dev | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bw-dev b/bw-dev index a6a1f326..993520c4 100755 --- a/bw-dev +++ b/bw-dev @@ -12,9 +12,6 @@ trap showerr EXIT source .env trap - EXIT -# show commands as they're executed -set -x - function clean { docker-compose stop docker-compose rm -f @@ -40,6 +37,10 @@ function initdb { CMD=$1 shift + +# show commands as they're executed +set -x + case "$CMD" in up) docker-compose up --build From 6455cc7fe9cdc0cec7b19dd177f8610055e23eff Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Fri, 27 Nov 2020 18:06:24 -0800 Subject: [PATCH 18/36] Add initial tests and some fixes Make timezones aware, and create a progress update if we can upon starting a readthrough --- bookwyrm/tests/actions/test_readthrough.py | 60 ++++++++++++++++++++++ bookwyrm/view_actions.py | 13 ++++- 2 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 bookwyrm/tests/actions/test_readthrough.py diff --git a/bookwyrm/tests/actions/test_readthrough.py b/bookwyrm/tests/actions/test_readthrough.py new file mode 100644 index 00000000..1c5cddb8 --- /dev/null +++ b/bookwyrm/tests/actions/test_readthrough.py @@ -0,0 +1,60 @@ +from django.test import TestCase, Client +from django.utils import timezone +from datetime import datetime + +from bookwyrm import view_actions as actions, models + +class ReadThrough(TestCase): + def setUp(self): + self.client = Client() + + self.work = models.Work.objects.create( + title='Example Work' + ) + + self.edition = models.Edition.objects.create( + title='Example Edition', + parent_work=self.work + ) + self.work.default_edition = self.edition + self.work.save() + + self.user = models.User.objects.create() + + self.client.force_login(self.user) + + def test_create_basic_readthrough(self): + """A basic readthrough doesn't create a progress update""" + self.assertEqual(self.edition.readthrough_set.count(), 0) + + self.client.post('/start-reading/{}'.format(self.edition.id), { + 'start_date': '2020-11-27', + }) + + readthroughs = self.edition.readthrough_set.all() + self.assertEqual(len(readthroughs), 1) + self.assertEqual(readthroughs[0].progressupdate_set.count(), 0) + self.assertEqual(readthroughs[0].start_date, + datetime(2020, 11, 27, tzinfo=timezone.utc)) + self.assertEqual(readthroughs[0].pages_read, None) + self.assertEqual(readthroughs[0].finish_date, None) + + def test_create_progress_readthrough(self): + self.assertEqual(self.edition.readthrough_set.count(), 0) + + self.client.post('/start-reading/{}'.format(self.edition.id), { + 'start_date': '2020-11-27', + 'pages_read': 50, + }) + + readthroughs = self.edition.readthrough_set.all() + self.assertEqual(len(readthroughs), 1) + self.assertEqual(readthroughs[0].start_date, + datetime(2020, 11, 27, tzinfo=timezone.utc)) + self.assertEqual(readthroughs[0].pages_read, 50) + self.assertEqual(readthroughs[0].finish_date, None) + + progress_updates = readthroughs[0].progressupdate_set.all() + self.assertEqual(len(progress_updates), 1) + self.assertEqual(progress_updates[0].mode, models.ProgressMode.PAGE) + self.assertEqual(progress_updates[0].progress, 50) diff --git a/bookwyrm/view_actions.py b/bookwyrm/view_actions.py index 130af8f6..f5aee7a4 100644 --- a/bookwyrm/view_actions.py +++ b/bookwyrm/view_actions.py @@ -363,6 +363,13 @@ def start_reading(request, book_id): if readthrough.start_date: readthrough.save() + # create a progress update if we have a page + if readthrough.pages_read: + readthrough.progressupdate_set.create( + user=request.user, + progress=readthrough.pages_read, + mode=models.ProgressMode.PAGE) + # shelve the book if request.POST.get('reshelve', True): try: @@ -728,7 +735,8 @@ def update_readthrough(request, book=None, create=True): start_date = request.POST.get('start_date') if start_date: try: - start_date = dateutil.parser.parse(start_date) + start_date = timezone.make_aware( + dateutil.parser.parse(start_date)) readthrough.start_date = start_date except ParserError: pass @@ -736,7 +744,8 @@ def update_readthrough(request, book=None, create=True): finish_date = request.POST.get('finish_date') if finish_date: try: - finish_date = dateutil.parser.parse(finish_date) + finish_date = timezone.make_aware( + dateutil.parser.parse(finish_date)) readthrough.finish_date = finish_date except ParserError: pass From 9ed7d2300064610bca0d6c62aa6b003a75324105 Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Fri, 27 Nov 2020 18:17:32 -0800 Subject: [PATCH 19/36] Test updating a progress Also remove spurious whitespace change --- bookwyrm/models/status.py | 1 + bookwyrm/tests/actions/test_readthrough.py | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/bookwyrm/models/status.py b/bookwyrm/models/status.py index 732cdd62..b92685da 100644 --- a/bookwyrm/models/status.py +++ b/bookwyrm/models/status.py @@ -210,6 +210,7 @@ class Quotation(Status): activity_serializer = activitypub.Quotation pure_activity_serializer = activitypub.Note + class Review(Status): ''' a book review ''' name = models.CharField(max_length=255, null=True) diff --git a/bookwyrm/tests/actions/test_readthrough.py b/bookwyrm/tests/actions/test_readthrough.py index 1c5cddb8..ba8c2f00 100644 --- a/bookwyrm/tests/actions/test_readthrough.py +++ b/bookwyrm/tests/actions/test_readthrough.py @@ -58,3 +58,15 @@ class ReadThrough(TestCase): self.assertEqual(len(progress_updates), 1) self.assertEqual(progress_updates[0].mode, models.ProgressMode.PAGE) self.assertEqual(progress_updates[0].progress, 50) + + # Update progress + self.client.post('/edit-readthrough', { + 'id': readthroughs[0].id, + 'pages_read': 100, + }) + + progress_updates = readthroughs[0].progressupdate_set\ + .order_by('updated_date').all() + self.assertEqual(len(progress_updates), 2) + self.assertEqual(progress_updates[1].mode, models.ProgressMode.PAGE) + self.assertEqual(progress_updates[1].progress, 100) From 500f05266a3fb46308838169936d60debaa7c0a7 Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Sat, 28 Nov 2020 00:07:04 -0800 Subject: [PATCH 20/36] Add option for progress percentage And rework display on book page as well --- bookwyrm/models/status.py | 20 +++++-- bookwyrm/templates/book.html | 54 ++++++++++++++----- .../templates/snippets/progress_update.html | 23 ++++++-- bookwyrm/tests/actions/test_readthrough.py | 8 +-- bookwyrm/view_actions.py | 27 +++++----- bookwyrm/views.py | 2 +- 6 files changed, 95 insertions(+), 39 deletions(-) diff --git a/bookwyrm/models/status.py b/bookwyrm/models/status.py index b92685da..2a9a4be1 100644 --- a/bookwyrm/models/status.py +++ b/bookwyrm/models/status.py @@ -292,13 +292,21 @@ class Boost(Status): # unique_together = ('user', 'boosted_status') +class ProgressMode(models.TextChoices): + PAGE = 'PG', 'page' + PERCENT = 'PCT', 'percent' + class ReadThrough(BookWyrmModel): ''' 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( + progress = models.IntegerField( 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) @@ -312,9 +320,13 @@ class ReadThrough(BookWyrmModel): self.user.save() super().save(*args, **kwargs) -class ProgressMode(models.TextChoices): - PAGE = 'PG', 'page' - PERCENT = 'PCT', 'percent' + 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. ''' diff --git a/bookwyrm/templates/book.html b/bookwyrm/templates/book.html index 2bd9fc77..aeafaafb 100644 --- a/bookwyrm/templates/book.html +++ b/bookwyrm/templates/book.html @@ -74,9 +74,13 @@ {% if readthrough.finish_date %}
Finished reading:
{{ readthrough.finish_date | naturalday }}
- {% elif readthrough.pages_read %} -
On page:
-
{{ readthrough.pages_read }} of {{ book.pages }}
+ {% elif readthrough.progress %} +
Progress:
+ {% if readthrough.progress_mode == 'PG' %} +
on page {{ readthrough.progress }} of {{ book.pages }}
+ {% else %} +
{{ readthrough.progress }}%
+ {% endif %} {% endif %}
@@ -93,12 +97,22 @@
{% if show_progress %} Progress Updates: -
+
    + {% if readthrough.finish_date %} +
  • {{ readthrough.start_date | naturalday }}: finished
  • + {% endif %} {% for progress_update in readthrough.progress_updates %} -
    {{ progress_update.created_date | naturalday }}:
    -
    {{ progress_update.progress }} of {{ book.pages }}
    +
  • + {{ progress_update.created_date | naturalday }}: + {% if progress_update.mode == 'PG' %} + page {{ progress_update.progress }} of {{ book.pages }} + {% else %} + {{ progress_update.progress }}% + {% endif %} +
  • {% endfor %} -
+
  • {{ readthrough.start_date | naturalday }}: started
  • + {% elif readthrough.progress_updates|length %} Show {{ readthrough.progress_updates|length }} Progress Updates {% endif %} @@ -118,11 +132,27 @@ -
    - +
    +
    +
    + +
    +
    +
    +
    + + +
    +
    +{# Only show progress for editing existing readthroughs #} +{% if readthrough.id and not readthrough.finish_date %}
    @@ -29,6 +31,7 @@
    +{% endif %}
    -
    -
    - {% include 'snippets/shelve_button.html' with book=book %} - {% active_shelf book as active_shelf %} -
    - {% if active_shelf.identifier == 'reading' and book.latest_readthrough %} -
    - {% include 'snippets/progress_update.html' with readthrough=book.latest_readthrough %} -
    - {% endif %} -
    +
    +
    + {% 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 %}
    diff --git a/bookwyrm/templates/snippets/progress_update.html b/bookwyrm/templates/snippets/progress_update.html index 9de51b07..6936429d 100644 --- a/bookwyrm/templates/snippets/progress_update.html +++ b/bookwyrm/templates/snippets/progress_update.html @@ -12,7 +12,7 @@ + name="progress" size="3" value="{{ readthrough.progress|default:"" }}">
    {% if readthrough.progress_mode == 'PG' and book.pages %} From a4796cf5c5d87207f83ef1d7230edb4701fb431f Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Sun, 17 Jan 2021 03:14:26 -0800 Subject: [PATCH 25/36] Make the switching work, wows Layout's all wonky now, but hey --- .../templates/snippets/progress_update.html | 51 ++++++++++++------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/bookwyrm/templates/snippets/progress_update.html b/bookwyrm/templates/snippets/progress_update.html index 6936429d..79cbf159 100644 --- a/bookwyrm/templates/snippets/progress_update.html +++ b/bookwyrm/templates/snippets/progress_update.html @@ -1,25 +1,40 @@
    {% csrf_token %} -
    - {% if readthrough.progress_mode == 'PG' %} - on page - {% else %} - currently at - {% endif %} + +
    + +
    -
    - -
    -
    - {% if readthrough.progress_mode == 'PG' and book.pages %} - of {{ book.pages }} - {% else %} - % - {% endif %} +
    + +
    From 6e05dfde927fd6918f839005dab8a222b8ebcb76 Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Sun, 17 Jan 2021 12:40:24 -0800 Subject: [PATCH 26/36] Revert "Make the switching work, wows" Actually this is bad, switching on this page is not useful enough for the UI complexity. Users can switch percent/pages on the book page. This reverts commit a4796cf5c5d87207f83ef1d7230edb4701fb431f. --- .../templates/snippets/progress_update.html | 51 +++++++------------ 1 file changed, 18 insertions(+), 33 deletions(-) diff --git a/bookwyrm/templates/snippets/progress_update.html b/bookwyrm/templates/snippets/progress_update.html index 79cbf159..6936429d 100644 --- a/bookwyrm/templates/snippets/progress_update.html +++ b/bookwyrm/templates/snippets/progress_update.html @@ -1,40 +1,25 @@ {% csrf_token %} - -
    - - +
    + {% if readthrough.progress_mode == 'PG' %} + on page + {% else %} + currently at + {% endif %}
    -
    - - +
    + +
    +
    + {% if readthrough.progress_mode == 'PG' and book.pages %} + of {{ book.pages }} + {% else %} + % + {% endif %}
    From ef05ac1f6540e9d175a15d6274c9c0249b0643b6 Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Sun, 17 Jan 2021 12:48:10 -0800 Subject: [PATCH 27/36] Small fixes to old form --- bookwyrm/templates/snippets/progress_update.html | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/bookwyrm/templates/snippets/progress_update.html b/bookwyrm/templates/snippets/progress_update.html index 6936429d..834766c2 100644 --- a/bookwyrm/templates/snippets/progress_update.html +++ b/bookwyrm/templates/snippets/progress_update.html @@ -10,16 +10,14 @@
    + name="progress" size="3" value="{{ readthrough.progress|default:'' }}">
    - {% if readthrough.progress_mode == 'PG' and book.pages %} - of {{ book.pages }} - {% else %} - % - {% endif %} + {% if readthrough.progress_mode == 'PG' %} + {% if book.pages %} of {{ book.pages }} {% endif %} + {% else %} % {% endif %}
    From 49893f49e10234c097774a87e5390a2edc7df824 Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Sun, 17 Jan 2021 13:09:49 -0800 Subject: [PATCH 28/36] Merge fixes --- bookwyrm/tests/actions/test_readthrough.py | 2 +- bookwyrm/views/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bookwyrm/tests/actions/test_readthrough.py b/bookwyrm/tests/actions/test_readthrough.py index fb16edcb..b92c9b65 100644 --- a/bookwyrm/tests/actions/test_readthrough.py +++ b/bookwyrm/tests/actions/test_readthrough.py @@ -2,7 +2,7 @@ from django.test import TestCase, Client from django.utils import timezone from datetime import datetime -from bookwyrm import view_actions as actions, models +from bookwyrm import models class ReadThrough(TestCase): def setUp(self): diff --git a/bookwyrm/views/__init__.py b/bookwyrm/views/__init__.py index e1ffeda4..b8de5d6c 100644 --- a/bookwyrm/views/__init__.py +++ b/bookwyrm/views/__init__.py @@ -15,7 +15,7 @@ from .landing import About, Home, Feed, Discover from .notifications import Notifications from .outbox import Outbox from .reading import edit_readthrough, create_readthrough, delete_readthrough -from .reading import start_reading, finish_reading +from .reading import start_reading, finish_reading, delete_progressupdate from .password import PasswordResetRequest, PasswordReset, ChangePassword from .tag import Tag, AddTag, RemoveTag from .search import Search From 0af4863568b599fa2f7a822b64e2416806665947 Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Sun, 17 Jan 2021 13:20:49 -0800 Subject: [PATCH 29/36] Update merge migration --- ...036_merge_20210114_0348.py => 0037_merge_20210117_2106.py} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename bookwyrm/migrations/{0036_merge_20210114_0348.py => 0037_merge_20210117_2106.py} (64%) diff --git a/bookwyrm/migrations/0036_merge_20210114_0348.py b/bookwyrm/migrations/0037_merge_20210117_2106.py similarity index 64% rename from bookwyrm/migrations/0036_merge_20210114_0348.py rename to bookwyrm/migrations/0037_merge_20210117_2106.py index 6dd1a775..40e7a7e1 100644 --- a/bookwyrm/migrations/0036_merge_20210114_0348.py +++ b/bookwyrm/migrations/0037_merge_20210117_2106.py @@ -1,4 +1,4 @@ -# Generated by Django 3.0.7 on 2021-01-14 03:48 +# Generated by Django 3.0.7 on 2021-01-17 21:06 from django.db import migrations @@ -7,7 +7,7 @@ class Migration(migrations.Migration): dependencies = [ ('bookwyrm', '0015_auto_20201128_0734'), - ('bookwyrm', '0035_edition_edition_rank'), + ('bookwyrm', '0036_annualgoal'), ] operations = [ From 1ea8ea0c26e7431c7e69149d7c1c580b9ee40460 Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Sun, 17 Jan 2021 20:31:06 -0800 Subject: [PATCH 30/36] Temp commit to make test run verbose, to see what's happening --- .github/workflows/django-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/django-tests.yml b/.github/workflows/django-tests.yml index 3ce368ec..e734d18e 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 From 79e284e5bee986f38ffcab1fdda0f67f17432971 Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Mon, 18 Jan 2021 19:59:40 -0800 Subject: [PATCH 31/36] Just scootch the migration merge up --- bookwyrm/migrations/0037_merge_20210117_2106.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/migrations/0037_merge_20210117_2106.py b/bookwyrm/migrations/0037_merge_20210117_2106.py index 40e7a7e1..603ad0ce 100644 --- a/bookwyrm/migrations/0037_merge_20210117_2106.py +++ b/bookwyrm/migrations/0037_merge_20210117_2106.py @@ -7,7 +7,7 @@ class Migration(migrations.Migration): dependencies = [ ('bookwyrm', '0015_auto_20201128_0734'), - ('bookwyrm', '0036_annualgoal'), + ('bookwyrm', '0037_auto_20210118_1954'), ] operations = [ From 60b42827f4b9d8da2718a5ec6d82d6b6e1d08976 Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Mon, 18 Jan 2021 20:00:04 -0800 Subject: [PATCH 32/36] Mock the AP publishing to stop hanging tests --- bookwyrm/tests/actions/test_readthrough.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/bookwyrm/tests/actions/test_readthrough.py b/bookwyrm/tests/actions/test_readthrough.py index b92c9b65..bd24cec2 100644 --- a/bookwyrm/tests/actions/test_readthrough.py +++ b/bookwyrm/tests/actions/test_readthrough.py @@ -1,9 +1,11 @@ +from unittest.mock import patch from django.test import TestCase, Client from django.utils import timezone from datetime import datetime from bookwyrm import models +@patch('bookwyrm.broadcast.broadcast_task.delay') class ReadThrough(TestCase): def setUp(self): self.client = Client() @@ -25,7 +27,7 @@ class ReadThrough(TestCase): self.client.force_login(self.user) - def test_create_basic_readthrough(self): + def test_create_basic_readthrough(self, delay_mock): """A basic readthrough doesn't create a progress update""" self.assertEqual(self.edition.readthrough_set.count(), 0) @@ -40,8 +42,9 @@ class ReadThrough(TestCase): datetime(2020, 11, 27, tzinfo=timezone.utc)) self.assertEqual(readthroughs[0].progress, None) self.assertEqual(readthroughs[0].finish_date, None) + self.assertEqual(delay_mock.call_count, 1) - def test_create_progress_readthrough(self): + def test_create_progress_readthrough(self, delay_mock): self.assertEqual(self.edition.readthrough_set.count(), 0) self.client.post('/start-reading/{}'.format(self.edition.id), { @@ -60,6 +63,7 @@ class ReadThrough(TestCase): self.assertEqual(len(progress_updates), 1) self.assertEqual(progress_updates[0].mode, models.ProgressMode.PAGE) self.assertEqual(progress_updates[0].progress, 50) + self.assertEqual(delay_mock.call_count, 1) # Update progress self.client.post('/edit-readthrough', { @@ -72,3 +76,4 @@ class ReadThrough(TestCase): self.assertEqual(len(progress_updates), 2) self.assertEqual(progress_updates[1].mode, models.ProgressMode.PAGE) self.assertEqual(progress_updates[1].progress, 100) + self.assertEqual(delay_mock.call_count, 1) # Edit doesn't publish anything From 32346cf9a3675f8d627c00701827397b98c835c9 Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Tue, 19 Jan 2021 22:30:51 -0800 Subject: [PATCH 33/36] Cascade-delete progress updates Add a warning about it, and update test to confirm it works --- bookwyrm/models/readthrough.py | 2 +- bookwyrm/templates/snippets/components/modal.html | 7 +++---- .../templates/snippets/delete_readthrough_modal.html | 6 +++++- bookwyrm/tests/actions/test_readthrough.py | 9 +++++++++ 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/bookwyrm/models/readthrough.py b/bookwyrm/models/readthrough.py index 3afde306..8ec3c9c6 100644 --- a/bookwyrm/models/readthrough.py +++ b/bookwyrm/models/readthrough.py @@ -42,7 +42,7 @@ class ReadThrough(BookWyrmModel): 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.PROTECT) + readthrough = models.ForeignKey('ReadThrough', on_delete=models.CASCADE) progress = models.IntegerField() mode = models.CharField( max_length=3, diff --git a/bookwyrm/templates/snippets/components/modal.html b/bookwyrm/templates/snippets/components/modal.html index 3eec9efa..72402914 100644 --- a/bookwyrm/templates/snippets/components/modal.html +++ b/bookwyrm/templates/snippets/components/modal.html @@ -7,11 +7,10 @@ {% include 'snippets/toggle/toggle_button.html' with label="close" class="delete" nonbutton=True %} - {% block modal-form-open %}{% endblock %} - - {% block modal-body %}{% endblock %} - +
    {% block modal-footer %}{% endblock %}
    diff --git a/bookwyrm/templates/snippets/delete_readthrough_modal.html b/bookwyrm/templates/snippets/delete_readthrough_modal.html index 2155afb3..c04a1d90 100644 --- a/bookwyrm/templates/snippets/delete_readthrough_modal.html +++ b/bookwyrm/templates/snippets/delete_readthrough_modal.html @@ -1,6 +1,10 @@ {% extends 'snippets/components/modal.html' %} {% block modal-title %}Delete these read dates?{% endblock %} - +{% block modal-body %} +{% if readthrough.progress_updates|length > 0 %} +You are deleting this readthrough and its {{ readthrough.progress_updates|length }} associated progress updates. +{% endif %} +{% endblock %} {% block modal-footer %} {% csrf_token %} diff --git a/bookwyrm/tests/actions/test_readthrough.py b/bookwyrm/tests/actions/test_readthrough.py index bd24cec2..41d2eaa5 100644 --- a/bookwyrm/tests/actions/test_readthrough.py +++ b/bookwyrm/tests/actions/test_readthrough.py @@ -77,3 +77,12 @@ class ReadThrough(TestCase): self.assertEqual(progress_updates[1].mode, models.ProgressMode.PAGE) self.assertEqual(progress_updates[1].progress, 100) self.assertEqual(delay_mock.call_count, 1) # Edit doesn't publish anything + + self.client.post('/delete-readthrough', { + 'id': readthroughs[0].id, + }) + + readthroughs = self.edition.readthrough_set.all() + updates = self.user.progressupdate_set.all() + self.assertEqual(len(readthroughs), 0) + self.assertEqual(len(updates), 0) From edba55f7c2f8e39fe06a9ba644fbf5bdb48db400 Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Tue, 19 Jan 2021 23:04:08 -0800 Subject: [PATCH 34/36] Flatten and rework sidebar update --- bookwyrm/templates/feed.html | 16 +++----- .../templates/snippets/progress_update.html | 38 ++++++++++--------- 2 files changed, 25 insertions(+), 29 deletions(-) diff --git a/bookwyrm/templates/feed.html b/bookwyrm/templates/feed.html index 7da2a285..1368660b 100644 --- a/bookwyrm/templates/feed.html +++ b/bookwyrm/templates/feed.html @@ -47,17 +47,11 @@
    -
    -
    - {% 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/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 %}
    diff --git a/bookwyrm/templates/snippets/progress_update.html b/bookwyrm/templates/snippets/progress_update.html index 834766c2..a2b23404 100644 --- a/bookwyrm/templates/snippets/progress_update.html +++ b/bookwyrm/templates/snippets/progress_update.html @@ -1,25 +1,27 @@ - + {% csrf_token %} +
    - {% if readthrough.progress_mode == 'PG' %} - on page - {% else %} - currently at - {% endif %} +
    - -
    -
    - {% if readthrough.progress_mode == 'PG' %} - {% if book.pages %} of {{ book.pages }} {% endif %} - {% else %} % {% endif %} -
    -
    - +
    From 070fa04b63ad313fae9fe0b31f2819e90dfa18e3 Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Tue, 19 Jan 2021 23:40:11 -0800 Subject: [PATCH 35/36] Add validators and more tests I don't think these validators will do anything unless we use them or are submitting a form, but they're there nonetheless --- bookwyrm/models/readthrough.py | 4 +- .../tests/models/test_readthrough_model.py | 51 +++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 bookwyrm/tests/models/test_readthrough_model.py diff --git a/bookwyrm/models/readthrough.py b/bookwyrm/models/readthrough.py index 8ec3c9c6..7daafaaf 100644 --- a/bookwyrm/models/readthrough.py +++ b/bookwyrm/models/readthrough.py @@ -1,6 +1,7 @@ ''' progress in a book ''' from django.db import models from django.utils import timezone +from django.core import validators from .base_model import BookWyrmModel @@ -13,6 +14,7 @@ class ReadThrough(BookWyrmModel): user = models.ForeignKey('User', on_delete=models.PROTECT) book = models.ForeignKey('Edition', on_delete=models.PROTECT) progress = models.IntegerField( + validators=[validators.MinValueValidator(0)], null=True, blank=True) progress_mode = models.CharField( @@ -43,7 +45,7 @@ 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() + progress = models.IntegerField(validators=[validators.MinValueValidator(0)]) mode = models.CharField( max_length=3, choices=ProgressMode.choices, diff --git a/bookwyrm/tests/models/test_readthrough_model.py b/bookwyrm/tests/models/test_readthrough_model.py new file mode 100644 index 00000000..3fcdf1e4 --- /dev/null +++ b/bookwyrm/tests/models/test_readthrough_model.py @@ -0,0 +1,51 @@ +''' testing models ''' +from django.test import TestCase +from django.core.exceptions import ValidationError + +from bookwyrm import models, settings + + +class ReadThrough(TestCase): + ''' some activitypub oddness ahead ''' + def setUp(self): + ''' look, a shelf ''' + self.user = models.User.objects.create_user( + 'mouse', 'mouse@mouse.mouse', 'mouseword', + local=True, localname='mouse') + + self.work = models.Work.objects.create( + title='Example Work' + ) + + self.edition = models.Edition.objects.create( + title='Example Edition', + parent_work=self.work + ) + self.work.default_edition = self.edition + self.work.save() + + self.readthrough = models.ReadThrough.objects.create( + user=self.user, + book=self.edition) + + def test_progress_update(self): + ''' Test progress updates ''' + self.readthrough.create_update() # No-op, no progress yet + self.readthrough.progress = 10 + self.readthrough.create_update() + self.readthrough.progress = 20 + self.readthrough.progress_mode = models.ProgressMode.PERCENT + self.readthrough.create_update() + + updates = self.readthrough.progressupdate_set \ + .order_by('created_date').all() + self.assertEqual(len(updates), 2) + self.assertEqual(updates[0].progress, 10) + self.assertEqual(updates[0].mode, models.ProgressMode.PAGE) + self.assertEqual(updates[1].progress, 20) + self.assertEqual(updates[1].mode, models.ProgressMode.PERCENT) + + self.readthrough.progress = -10 + self.assertRaises(ValidationError, self.readthrough.clean_fields) + update = self.readthrough.create_update() + self.assertRaises(ValidationError, update.clean_fields) From 57607c3590f73eae2eb854dca53bd6fe667568e6 Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Tue, 19 Jan 2021 23:53:42 -0800 Subject: [PATCH 36/36] Regenerate merge migration --- ...037_merge_20210117_2106.py => 0039_merge_20210120_0753.py} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename bookwyrm/migrations/{0037_merge_20210117_2106.py => 0039_merge_20210120_0753.py} (64%) diff --git a/bookwyrm/migrations/0037_merge_20210117_2106.py b/bookwyrm/migrations/0039_merge_20210120_0753.py similarity index 64% rename from bookwyrm/migrations/0037_merge_20210117_2106.py rename to bookwyrm/migrations/0039_merge_20210120_0753.py index 603ad0ce..1af40ee9 100644 --- a/bookwyrm/migrations/0037_merge_20210117_2106.py +++ b/bookwyrm/migrations/0039_merge_20210120_0753.py @@ -1,4 +1,4 @@ -# Generated by Django 3.0.7 on 2021-01-17 21:06 +# Generated by Django 3.0.7 on 2021-01-20 07:53 from django.db import migrations @@ -6,8 +6,8 @@ from django.db import migrations class Migration(migrations.Migration): dependencies = [ + ('bookwyrm', '0038_auto_20210119_1534'), ('bookwyrm', '0015_auto_20201128_0734'), - ('bookwyrm', '0037_auto_20210118_1954'), ] operations = [