From 3db0de3dd46c1d8291efb2d480b1edf414bdd731 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 22 Jan 2021 09:19:02 -0800 Subject: [PATCH 1/6] Makes pages/percents toggle-able in sidebar --- .../migrations/0040_auto_20210122_0057.py | 36 +++++++++++++++++++ .../templates/snippets/progress_update.html | 26 +++++++------- 2 files changed, 49 insertions(+), 13 deletions(-) create mode 100644 bookwyrm/migrations/0040_auto_20210122_0057.py diff --git a/bookwyrm/migrations/0040_auto_20210122_0057.py b/bookwyrm/migrations/0040_auto_20210122_0057.py new file mode 100644 index 00000000..8e528a89 --- /dev/null +++ b/bookwyrm/migrations/0040_auto_20210122_0057.py @@ -0,0 +1,36 @@ +# Generated by Django 3.0.7 on 2021-01-22 00:57 + +import bookwyrm.models.fields +import django.core.validators +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('bookwyrm', '0039_merge_20210120_0753'), + ] + + operations = [ + migrations.AlterField( + model_name='progressupdate', + name='progress', + field=models.IntegerField(validators=[django.core.validators.MinValueValidator(0)]), + ), + migrations.AlterField( + model_name='progressupdate', + name='readthrough', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='bookwyrm.ReadThrough'), + ), + migrations.AlterField( + model_name='progressupdate', + name='remote_id', + field=bookwyrm.models.fields.RemoteIdField(max_length=255, null=True, validators=[bookwyrm.models.fields.validate_remote_id]), + ), + migrations.AlterField( + model_name='readthrough', + name='progress', + field=models.IntegerField(blank=True, null=True, validators=[django.core.validators.MinValueValidator(0)]), + ), + ] diff --git a/bookwyrm/templates/snippets/progress_update.html b/bookwyrm/templates/snippets/progress_update.html index a2b23404..dbe5cb75 100644 --- a/bookwyrm/templates/snippets/progress_update.html +++ b/bookwyrm/templates/snippets/progress_update.html @@ -1,27 +1,27 @@
{% csrf_token %} - -
-
+ -
- + {% if readthrough.progress_mode == 'PG' and book.pages %} +

of {{ book.pages }} pages

+ {% endif %}
From 806b781f1577d40129a0f53a8590f044a002f44f Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 22 Jan 2021 09:21:58 -0800 Subject: [PATCH 2/6] Adds html form validator for min value --- bookwyrm/templates/snippets/progress_update.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/templates/snippets/progress_update.html b/bookwyrm/templates/snippets/progress_update.html index dbe5cb75..92a7573a 100644 --- a/bookwyrm/templates/snippets/progress_update.html +++ b/bookwyrm/templates/snippets/progress_update.html @@ -7,7 +7,7 @@
From 69c5bf71ed7ca81b0241cb041c1069af99c69126 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 22 Jan 2021 12:51:23 -0800 Subject: [PATCH 3/6] Uses javascript show/hide for reading progress updates --- bookwyrm/templates/snippets/readthrough.html | 104 ++++++++----------- 1 file changed, 46 insertions(+), 58 deletions(-) diff --git a/bookwyrm/templates/snippets/readthrough.html b/bookwyrm/templates/snippets/readthrough.html index 79248891..618433b5 100644 --- a/bookwyrm/templates/snippets/readthrough.html +++ b/bookwyrm/templates/snippets/readthrough.html @@ -1,67 +1,55 @@ {% load humanize %}
-
- {% if readthrough.start_date %} -
-
Started reading:
-
{{ readthrough.start_date | naturalday }}
+
+
+ Progress Updates: +
+
    + {% if readthrough.finish_date %} +
  • {{ readthrough.start_date | naturalday }}: finished
  • + {% endif %} + {% if readthrough.progress %} +
  • {% if readthrough.progress_mode == 'PG' %}on page {{ readthrough.progress }}{% if book.pages %} of {{ book.pages }}{% endif %} + {% else %}{{ readthrough.progress }}%{% endif %} + {% include 'snippets/toggle/toggle_button.html' with text="Show all updates" controls_text="updates" controls_uid=readthrough.id class="is-small" %} + +
  • + {% endif %} +
  • {{ readthrough.start_date | naturalday }}: started
  • +
- {% endif %} - {% if readthrough.finish_date %} -
-
Finished reading:
-
{{ readthrough.finish_date | naturalday }}
-
- {% elif readthrough.progress %} -
-
Progress:
- {% if readthrough.progress_mode == 'PG' %} -
on page {{ readthrough.progress }} of {{ book.pages }}
- {% else %} -
{{ readthrough.progress }}%
- {% endif %} -
- {% endif %} - -
-
- {% include 'snippets/toggle/toggle_button.html' with class="is-small" text="Edit read dates" icon="pencil" controls_text="edit-readthrough" controls_uid=readthrough.id focus="edit-readthrough" %} -
-
- {% include 'snippets/toggle/toggle_button.html' with class="is-small" text="Delete these read dates" icon="x" controls_text="delete-readthrough" controls_uid=readthrough.id focus="modal-title-delete-readthrough" %} +
+
+
+ {% include 'snippets/toggle/toggle_button.html' with class="is-small" text="Edit read dates" icon="pencil" controls_text="edit-readthrough" controls_uid=readthrough.id focus="edit-readthrough" %} +
+
+ {% include 'snippets/toggle/toggle_button.html' with class="is-small" text="Delete these read dates" icon="x" controls_text="delete-readthrough" controls_uid=readthrough.id focus="modal-title-delete-readthrough" %} +
+
- {% if show_progress %} - Progress Updates: -
    - {% if readthrough.finish_date %} -
  • {{ readthrough.start_date | naturalday }}: finished
  • - {% endif %} - {% for progress_update in readthrough.progress_updates %} -
  • -
    - {% csrf_token %} - {{ 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 %}
From 12c23836b711644b4906a516972f9f4439f50bc6 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 22 Jan 2021 12:54:25 -0800 Subject: [PATCH 4/6] Fixes display of finish date --- bookwyrm/templates/snippets/readthrough.html | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/bookwyrm/templates/snippets/readthrough.html b/bookwyrm/templates/snippets/readthrough.html index 618433b5..e0b25d8b 100644 --- a/bookwyrm/templates/snippets/readthrough.html +++ b/bookwyrm/templates/snippets/readthrough.html @@ -6,12 +6,9 @@ Progress Updates:
    - {% if readthrough.finish_date %} -
  • {{ readthrough.start_date | naturalday }}: finished
  • - {% endif %} {% if readthrough.progress %} -
  • {% if readthrough.progress_mode == 'PG' %}on page {{ readthrough.progress }}{% if book.pages %} of {{ book.pages }}{% endif %} - {% else %}{{ readthrough.progress }}%{% endif %} +
  • {% if readthrough.finish_date %} {{ readthrough.finish_date | naturalday }}: finished {% else %}{% if readthrough.progress_mode == 'PG' %}on page {{ readthrough.progress }}{% if book.pages %} of {{ book.pages }}{% endif %} + {% else %}{{ readthrough.progress }}%{% endif %}{% endif %} {% include 'snippets/toggle/toggle_button.html' with text="Show all updates" controls_text="updates" controls_uid=readthrough.id class="is-small" %}
{# Only show progress for editing existing readthroughs #} {% if readthrough.id and not readthrough.finish_date %} -
-
-
- -
+ +
+
+
-
-
- - -
+
+
{% endif %} From 20758b662dbe42244656cd31c5bd145ce94176ad Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 22 Jan 2021 14:33:03 -0800 Subject: [PATCH 6/6] don't need the showprogress get param any longer --- bookwyrm/views/books.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bookwyrm/views/books.py b/bookwyrm/views/books.py index a6e2667f..52704560 100644 --- a/bookwyrm/views/books.py +++ b/bookwyrm/views/books.py @@ -74,7 +74,8 @@ class Book(View): for readthrough in readthroughs: readthrough.progress_updates = \ - readthrough.progressupdate_set.all().order_by('-updated_date') + readthrough.progressupdate_set.all() \ + .order_by('-updated_date') user_shelves = models.ShelfBook.objects.filter( added_by=request.user, book=book @@ -98,7 +99,6 @@ class Book(View): 'user_shelves': user_shelves, 'other_edition_shelves': other_edition_shelves, 'readthroughs': readthroughs, - 'show_progress': ('showprogress' in request.GET), 'path': '/book/%s' % book_id, } return TemplateResponse(request, 'book.html', data)