From 23c60193400da3ea35b1cca5d822419cc5a37ea8 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 26 May 2022 10:23:32 -0700 Subject: [PATCH 01/14] Adds merge migration --- bookwyrm/migrations/0149_merge_20220526_1716.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 bookwyrm/migrations/0149_merge_20220526_1716.py diff --git a/bookwyrm/migrations/0149_merge_20220526_1716.py b/bookwyrm/migrations/0149_merge_20220526_1716.py new file mode 100644 index 000000000..b42bccd3b --- /dev/null +++ b/bookwyrm/migrations/0149_merge_20220526_1716.py @@ -0,0 +1,13 @@ +# Generated by Django 3.2.13 on 2022-05-26 17:16 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0148_alter_user_preferred_language"), + ("bookwyrm", "0148_merge_20220326_2006"), + ] + + operations = [] From 007751c8cb92e0645bb3a72666d90f03c1186369 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 26 May 2022 10:58:11 -0700 Subject: [PATCH 02/14] Adds error logging to status views --- bookwyrm/views/reading.py | 5 +++++ bookwyrm/views/status.py | 10 ++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/bookwyrm/views/reading.py b/bookwyrm/views/reading.py index 3cd153d2f..2aa9136d0 100644 --- a/bookwyrm/views/reading.py +++ b/bookwyrm/views/reading.py @@ -1,4 +1,5 @@ """ the good stuff! the books! """ +import logging from django.contrib.auth.decorators import login_required from django.core.cache import cache from django.db import transaction @@ -15,6 +16,8 @@ from .status import CreateStatus from .helpers import get_edition, handle_reading_status, is_api_request from .helpers import load_date_in_user_tz_as_utc +logger = logging.getLogger(__name__) + # pylint: disable=no-self-use # pylint: disable=too-many-return-statements @@ -36,6 +39,7 @@ class ReadingStatus(View): # redirect if we're already on this shelf return TemplateResponse(request, f"reading_progress/{template}", {"book": book}) + @transaction.atomic def post(self, request, status, book_id): """Change the state of a book by shelving it and adding reading dates""" identifier = { @@ -45,6 +49,7 @@ class ReadingStatus(View): "stop": models.Shelf.STOPPED_READING, }.get(status) if not identifier: + logger.exception("Invalid reading status type: %s", status) return HttpResponseBadRequest() # invalidate related caches diff --git a/bookwyrm/views/status.py b/bookwyrm/views/status.py index af15064fd..670ea5717 100644 --- a/bookwyrm/views/status.py +++ b/bookwyrm/views/status.py @@ -1,5 +1,6 @@ """ what are we here for if not for posting """ import re +import logging from urllib.parse import urlparse from django.contrib.auth.decorators import login_required @@ -21,6 +22,8 @@ from bookwyrm.utils import regex from .helpers import handle_remote_webfinger, is_api_request from .helpers import load_date_in_user_tz_as_utc +logger = logging.getLogger(__name__) + # pylint: disable= no-self-use @method_decorator(login_required, name="dispatch") @@ -72,11 +75,14 @@ class CreateStatus(View): form = getattr(forms, f"{status_type}Form")( request.POST, instance=existing_status ) - except AttributeError: + except AttributeError as err: + logger.exception(err) return HttpResponseBadRequest() + if not form.is_valid(): if is_api_request(request): - return HttpResponse(status=500) + logger.exception(form.errors) + return HttpResponseBadRequest() return redirect(request.headers.get("Referer", "/")) status = form.save(commit=False) From 6848616ff14421e7399425e5cbf6bc064c370bfc Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 26 May 2022 11:09:11 -0700 Subject: [PATCH 03/14] Fixes reading status field in stop modal The value of the reading status needs to match one of the database options for `reading_status` in the `Comment` model --- .../templates/snippets/reading_modals/stop_reading_modal.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/templates/snippets/reading_modals/stop_reading_modal.html b/bookwyrm/templates/snippets/reading_modals/stop_reading_modal.html index 80fb2d5b3..571a9ec59 100644 --- a/bookwyrm/templates/snippets/reading_modals/stop_reading_modal.html +++ b/bookwyrm/templates/snippets/reading_modals/stop_reading_modal.html @@ -12,7 +12,7 @@ Stop Reading "{{ book_title }}"
{% csrf_token %} - + {% endblock %} From 92dbfec5f8d11cc93c1a5460238b411a23af64fd Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 26 May 2022 11:10:14 -0700 Subject: [PATCH 04/14] Adds status header for stopped reading statuses --- .../status/headers/stopped_reading.html | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 bookwyrm/templates/snippets/status/headers/stopped_reading.html diff --git a/bookwyrm/templates/snippets/status/headers/stopped_reading.html b/bookwyrm/templates/snippets/status/headers/stopped_reading.html new file mode 100644 index 000000000..3b6a314e1 --- /dev/null +++ b/bookwyrm/templates/snippets/status/headers/stopped_reading.html @@ -0,0 +1,23 @@ +{% spaceless %} +{% load i18n %} +{% load utilities %} +{% load status_display %} + +{% load_book status as book %} +{% if book.authors.exists %} + +{% with author=book.authors.first %} +{% blocktrans trimmed with book_path=book.local_path book=book|book_title author_name=author.name author_path=author.local_path %} +stopped reading {{ book }} by {{ author_name }} +{% endblocktrans %} +{% endwith %} + +{% else %} + +{% blocktrans trimmed with book_path=book.local_path book=book|book_title %} +stopped reading {{ book }} +{% endblocktrans %} + +{% endif %} +{% endspaceless %} + From 9b4a49866114cef37802a82f48a6db4e1d38e14d Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 26 May 2022 11:19:49 -0700 Subject: [PATCH 05/14] Don't show a button for the shelf a book is currently on This will lead to nonsensical modal states --- .../snippets/shelve_button/shelve_button_dropdown_options.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bookwyrm/templates/snippets/shelve_button/shelve_button_dropdown_options.html b/bookwyrm/templates/snippets/shelve_button/shelve_button_dropdown_options.html index 50d3e2574..bc5ff24ad 100644 --- a/bookwyrm/templates/snippets/shelve_button/shelve_button_dropdown_options.html +++ b/bookwyrm/templates/snippets/shelve_button/shelve_button_dropdown_options.html @@ -6,6 +6,7 @@ {% for shelf in shelves %} {% comparison_bool shelf.identifier active_shelf.shelf.identifier as is_current %} + {% if not is_current %} + {% endif %} {% endfor %} {% if readthrough and active_shelf.shelf.identifier != 'read' %} From 1f6fbd8d29c297f266179e06f8ad8831902a6649 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 26 May 2022 11:28:54 -0700 Subject: [PATCH 06/14] Fixes stopped reading button logic The stopped state is similar to finished --- .../shelve_button/shelve_button_options.html | 16 +++++++++------- bookwyrm/templatetags/shelf_tags.py | 2 ++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/bookwyrm/templates/snippets/shelve_button/shelve_button_options.html b/bookwyrm/templates/snippets/shelve_button/shelve_button_options.html index fb7ee452c..891f58630 100644 --- a/bookwyrm/templates/snippets/shelve_button/shelve_button_options.html +++ b/bookwyrm/templates/snippets/shelve_button/shelve_button_options.html @@ -13,6 +13,15 @@ +
+ +
+ {% for shelf in shelves %}
Date: Thu, 26 May 2022 11:33:31 -0700 Subject: [PATCH 07/14] Adds stopped date separate from finish date on readthrough --- bookwyrm/forms/forms.py | 7 ++++++- .../0150_readthrough_stopped_date.py | 18 ++++++++++++++++++ bookwyrm/models/readthrough.py | 1 + .../readthrough/readthrough_list.html | 2 ++ .../reading_modals/stop_reading_modal.html | 4 ++-- 5 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 bookwyrm/migrations/0150_readthrough_stopped_date.py diff --git a/bookwyrm/forms/forms.py b/bookwyrm/forms/forms.py index 9d8f9f392..4aa1e5758 100644 --- a/bookwyrm/forms/forms.py +++ b/bookwyrm/forms/forms.py @@ -53,7 +53,12 @@ class ReadThroughForm(CustomForm): self.add_error( "finish_date", _("Reading finish date cannot be before start date.") ) + stopped_date = cleaned_data.get("stopped_date") + if start_date and stopped_date and start_date > stopped_date: + self.add_error( + "stopped_date", _("Reading stopped date cannot be before start date.") + ) class Meta: model = models.ReadThrough - fields = ["user", "book", "start_date", "finish_date"] + fields = ["user", "book", "start_date", "finish_date", "stopped_date"] diff --git a/bookwyrm/migrations/0150_readthrough_stopped_date.py b/bookwyrm/migrations/0150_readthrough_stopped_date.py new file mode 100644 index 000000000..6ce2f89a9 --- /dev/null +++ b/bookwyrm/migrations/0150_readthrough_stopped_date.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.13 on 2022-05-26 18:33 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0149_merge_20220526_1716"), + ] + + operations = [ + migrations.AddField( + model_name="readthrough", + name="stopped_date", + field=models.DateTimeField(blank=True, null=True), + ), + ] diff --git a/bookwyrm/models/readthrough.py b/bookwyrm/models/readthrough.py index ceb8e0b6e..5a13fa473 100644 --- a/bookwyrm/models/readthrough.py +++ b/bookwyrm/models/readthrough.py @@ -27,6 +27,7 @@ class ReadThrough(BookWyrmModel): ) start_date = models.DateTimeField(blank=True, null=True) finish_date = models.DateTimeField(blank=True, null=True) + stopped_date = models.DateTimeField(blank=True, null=True) is_active = models.BooleanField(default=True) def save(self, *args, **kwargs): diff --git a/bookwyrm/templates/readthrough/readthrough_list.html b/bookwyrm/templates/readthrough/readthrough_list.html index d0d679da7..7a89947d6 100644 --- a/bookwyrm/templates/readthrough/readthrough_list.html +++ b/bookwyrm/templates/readthrough/readthrough_list.html @@ -12,6 +12,8 @@
  • {% if readthrough.finish_date %} {{ readthrough.finish_date | localtime | naturalday }}: {% trans "finished" %} + {% elif readthrough.stopped_date %} + {{ readthrough.stopped_date | localtime | naturalday }}: {% trans "stopped" %} {% else %} {% if readthrough.progress_mode == 'PG' %} diff --git a/bookwyrm/templates/snippets/reading_modals/stop_reading_modal.html b/bookwyrm/templates/snippets/reading_modals/stop_reading_modal.html index 571a9ec59..8e5ae7d65 100644 --- a/bookwyrm/templates/snippets/reading_modals/stop_reading_modal.html +++ b/bookwyrm/templates/snippets/reading_modals/stop_reading_modal.html @@ -29,9 +29,9 @@ Stop Reading "{{ book_title }}"
    - +
  • From dfe0656eb4d9e85d2d9140111928d0e4f3889525 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 26 May 2022 11:38:36 -0700 Subject: [PATCH 08/14] Typo fix --- bookwyrm/templatetags/shelf_tags.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/templatetags/shelf_tags.py b/bookwyrm/templatetags/shelf_tags.py index b4f53e482..57cd02259 100644 --- a/bookwyrm/templatetags/shelf_tags.py +++ b/bookwyrm/templatetags/shelf_tags.py @@ -31,7 +31,7 @@ def get_next_shelf(current_shelf): if current_shelf == "read": return "complete" if current_shelf == "stopped-reading": - return "stopped-readingt" + return "stopped-reading" return "to-read" From 4c5d2570abc9bbf0b503174e792bc04e7a96cb81 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 26 May 2022 11:53:33 -0700 Subject: [PATCH 09/14] Save and display stopped date in readthrough --- bookwyrm/models/readthrough.py | 2 +- bookwyrm/templates/readthrough/readthrough_form.html | 1 + bookwyrm/templates/readthrough/readthrough_list.html | 2 +- bookwyrm/views/reading.py | 7 +++++-- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/bookwyrm/models/readthrough.py b/bookwyrm/models/readthrough.py index 5a13fa473..314b40a5c 100644 --- a/bookwyrm/models/readthrough.py +++ b/bookwyrm/models/readthrough.py @@ -35,7 +35,7 @@ class ReadThrough(BookWyrmModel): cache.delete(f"latest_read_through-{self.user.id}-{self.book.id}") self.user.update_active_date() # an active readthrough must have an unset finish date - if self.finish_date: + if self.finish_date or self.stopped_date: self.is_active = False super().save(*args, **kwargs) diff --git a/bookwyrm/templates/readthrough/readthrough_form.html b/bookwyrm/templates/readthrough/readthrough_form.html index 1558dada4..45c92043a 100644 --- a/bookwyrm/templates/readthrough/readthrough_form.html +++ b/bookwyrm/templates/readthrough/readthrough_form.html @@ -19,6 +19,7 @@ {% include "snippets/progress_field.html" with id=field_id %} {% endif %} +