From 375c5a87899dcecf2640b8d9de792ed128920513 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 26 May 2022 11:33:31 -0700 Subject: [PATCH] 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 9d8f9f39..4aa1e575 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 00000000..6ce2f89a --- /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 ceb8e0b6..5a13fa47 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 d0d679da..7a89947d 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 571a9ec5..8e5ae7d6 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 }}"
    - +