From 168a2488e2bbcbdd5198a4f6d1a75f370365fe68 Mon Sep 17 00:00:00 2001
From: Hugh Rundle
Date: Mon, 15 Nov 2021 20:59:22 +1100
Subject: [PATCH 01/42] refactor shelf activity on book page
- disallow moving from custom shelf to a reading status shelf with shelf_selector
- always use shelve_button for moving books from a reading status shelf
- redesign shelf information as a list of boxes
---
bookwyrm/templates/book/book.html | 21 +++++++++++++++----
.../templates/snippets/shelf_selector.html | 4 ++++
bookwyrm/templatetags/bookwyrm_tags.py | 11 ++++++++++
3 files changed, 32 insertions(+), 4 deletions(-)
diff --git a/bookwyrm/templates/book/book.html b/bookwyrm/templates/book/book.html
index 36241ee26..a1a73135a 100644
--- a/bookwyrm/templates/book/book.html
+++ b/bookwyrm/templates/book/book.html
@@ -153,12 +153,25 @@
{# user's relationship to the book #}
+ {% if user_shelfbooks.count > 0 %}
+
+ {% trans "You have shelved this edition in:" %}
+
+
{% for shelf in user_shelfbooks %}
-
- {% blocktrans with path=shelf.shelf.local_path shelf_name=shelf.shelf.name %}This edition is on your {{ shelf_name }} shelf.{% endblocktrans %}
- {% include 'snippets/shelf_selector.html' with current=shelf.shelf %}
-
+
+ {% blocktrans with path=shelf.shelf.local_path shelf_name=shelf.shelf.name %}{{ shelf_name }}{% endblocktrans %}
+ {% if shelf.shelf.identifier|is_shelf_type:"readthrough" %}
+ {% include 'snippets/shelve_button/shelve_button.html' %}
+ {% else %}
+
+ {% include 'snippets/shelf_selector.html' with current=shelf.shelf class="is-small" %}
+
+ {% endif %}
+
{% endfor %}
+
+ {% endif %}
{% for shelf in other_edition_shelves %}
{% blocktrans with book_path=shelf.book.local_path shelf_path=shelf.shelf.local_path shelf_name=shelf.shelf.name %}A different edition of this book is on your {{ shelf_name }} shelf.{% endblocktrans %}
diff --git a/bookwyrm/templates/snippets/shelf_selector.html b/bookwyrm/templates/snippets/shelf_selector.html
index ca5a39f6e..ef5bf5bcd 100644
--- a/bookwyrm/templates/snippets/shelf_selector.html
+++ b/bookwyrm/templates/snippets/shelf_selector.html
@@ -1,5 +1,7 @@
{% extends 'components/dropdown.html' %}
{% load i18n %}
+{% load bookwyrm_tags %}
+
{% block dropdown-trigger %}
{% trans "Move book" %}
@@ -7,6 +9,7 @@
{% block dropdown-list %}
{% for shelf in user_shelves %}
+{% if shelf.identifier|is_shelf_type:"custom" %}
+{% endif %}
{% endfor %}
diff --git a/bookwyrm/templatetags/bookwyrm_tags.py b/bookwyrm/templatetags/bookwyrm_tags.py
index bccd8c75a..992f584a0 100644
--- a/bookwyrm/templatetags/bookwyrm_tags.py
+++ b/bookwyrm/templatetags/bookwyrm_tags.py
@@ -41,6 +41,17 @@ def get_book_description(book):
return book.description or book.parent_work.description
+@register.filter(name="is_shelf_type")
+def shelf_type(current_shelf, shelf_type):
+ """is this shelf a readthrough shelf?"""
+ readthrough = current_shelf in ["to-read", "reading", "read"]
+ if shelf_type == "readthrough" and readthrough == True:
+ return True
+ if shelf_type == "custom" and readthrough == False:
+ return True
+ return False
+
+
@register.filter(name="next_shelf")
def get_next_shelf(current_shelf):
"""shelf you'd use to update reading progress"""
From eab2ec0ffd0a2734bd6732386f524c59ad21bcc2 Mon Sep 17 00:00:00 2001
From: Hugh Rundle
Date: Mon, 15 Nov 2021 21:19:16 +1100
Subject: [PATCH 02/42] code cleanup in is_shelf_type template tag
---
bookwyrm/templatetags/bookwyrm_tags.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/bookwyrm/templatetags/bookwyrm_tags.py b/bookwyrm/templatetags/bookwyrm_tags.py
index 992f584a0..c7ecbe4d6 100644
--- a/bookwyrm/templatetags/bookwyrm_tags.py
+++ b/bookwyrm/templatetags/bookwyrm_tags.py
@@ -42,12 +42,12 @@ def get_book_description(book):
@register.filter(name="is_shelf_type")
-def shelf_type(current_shelf, shelf_type):
+def is_shelf_type(current_shelf, shelf_type):
"""is this shelf a readthrough shelf?"""
readthrough = current_shelf in ["to-read", "reading", "read"]
- if shelf_type == "readthrough" and readthrough == True:
+ if shelf_type == "readthrough" and bool(readthrough):
return True
- if shelf_type == "custom" and readthrough == False:
+ if shelf_type == "custom" and not readthrough:
return True
return False
From ec39346e67228b1e4d8fb0b84f6f74b679d2441a Mon Sep 17 00:00:00 2001
From: Hugh Rundle
Date: Tue, 16 Nov 2021 19:26:49 +1100
Subject: [PATCH 03/42] check shelf.editable instead of custom filter
---
bookwyrm/templates/book/book.html | 10 +++++-----
bookwyrm/templates/snippets/shelf_selector.html | 2 +-
bookwyrm/templatetags/bookwyrm_tags.py | 11 -----------
3 files changed, 6 insertions(+), 17 deletions(-)
diff --git a/bookwyrm/templates/book/book.html b/bookwyrm/templates/book/book.html
index a1a73135a..936212bee 100644
--- a/bookwyrm/templates/book/book.html
+++ b/bookwyrm/templates/book/book.html
@@ -161,12 +161,12 @@
{% for shelf in user_shelfbooks %}
{% blocktrans with path=shelf.shelf.local_path shelf_name=shelf.shelf.name %}{{ shelf_name }}{% endblocktrans %}
- {% if shelf.shelf.identifier|is_shelf_type:"readthrough" %}
- {% include 'snippets/shelve_button/shelve_button.html' %}
+ {% if shelf.shelf.editable %}
+
+ {% include 'snippets/shelf_selector.html' with current=shelf.shelf class="is-small" %}
+
{% else %}
-
- {% include 'snippets/shelf_selector.html' with current=shelf.shelf class="is-small" %}
-
+ {% include 'snippets/shelve_button/shelve_button.html' %}
{% endif %}
{% endfor %}
diff --git a/bookwyrm/templates/snippets/shelf_selector.html b/bookwyrm/templates/snippets/shelf_selector.html
index ef5bf5bcd..e43d8ca1d 100644
--- a/bookwyrm/templates/snippets/shelf_selector.html
+++ b/bookwyrm/templates/snippets/shelf_selector.html
@@ -9,7 +9,7 @@
{% block dropdown-list %}
{% for shelf in user_shelves %}
-{% if shelf.identifier|is_shelf_type:"custom" %}
+{% if shelf.editable %}
+
+{% include 'snippets/reading_modals/want_to_read_modal.html' with book=active_shelf.book controls_text="want_to_read" controls_uid=uuid move_from=current.id %}
+
+{% include 'snippets/reading_modals/start_reading_modal.html' with book=active_shelf.book controls_text="start_reading" controls_uid=uuid move_from=current.id %}
+
+{% include 'snippets/reading_modals/finish_reading_modal.html' with book=active_shelf.book controls_text="finish_reading" controls_uid=uuid move_from=current.id readthrough=readthrough %}
+
+{% include 'snippets/reading_modals/progress_update_modal.html' with book=active_shelf.book controls_text="progress_update" controls_uid=uuid move_from=current.id readthrough=readthrough %}
+
+{% endwith %}
{% endblock %}
diff --git a/bookwyrm/views/reading.py b/bookwyrm/views/reading.py
index 54427ffb9..a96ccbc09 100644
--- a/bookwyrm/views/reading.py
+++ b/bookwyrm/views/reading.py
@@ -9,6 +9,7 @@ from django.views import View
from django.views.decorators.http import require_POST
from bookwyrm import models
+from bookwyrm.views.shelf.shelf_actions import unshelve
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
@@ -85,12 +86,20 @@ class ReadingStatus(View):
if request.POST.get("post-status"):
# is it a comment?
if request.POST.get("content"):
+ # BUG: there is a problem posting statuses for finishing
+ # check whether it existed before.
return CreateStatus.as_view()(request, "comment")
privacy = request.POST.get("privacy")
handle_reading_status(request.user, desired_shelf, book, privacy)
+ if bool(request.POST.get("shelf")):
+ if current_status_shelfbook is None:
+ return unshelve(request, referer=referer, book_id=book_id)
+ return HttpResponse(headers={"forceReload" : "true"})
+
if is_api_request(request):
return HttpResponse()
+
return redirect(referer)
diff --git a/bookwyrm/views/shelf/shelf_actions.py b/bookwyrm/views/shelf/shelf_actions.py
index 702b72c13..8240055e2 100644
--- a/bookwyrm/views/shelf/shelf_actions.py
+++ b/bookwyrm/views/shelf/shelf_actions.py
@@ -1,6 +1,7 @@
""" shelf views """
from django.db import IntegrityError, transaction
from django.contrib.auth.decorators import login_required
+from django.http.response import HttpResponse
from django.shortcuts import get_object_or_404, redirect
from django.views.decorators.http import require_POST
@@ -91,13 +92,15 @@ def shelve(request):
@login_required
@require_POST
-def unshelve(request):
+def unshelve(request, referer=None, book_id=False):
"""remove a book from a user's shelf"""
- book = get_object_or_404(models.Edition, id=request.POST.get("book"))
+ id = book_id if book_id else request.POST.get("book")
+ book = get_object_or_404(models.Edition, id=id)
shelf_book = get_object_or_404(
models.ShelfBook, book=book, shelf__id=request.POST["shelf"]
)
shelf_book.raise_not_deletable(request.user)
-
shelf_book.delete()
+ if bool(referer):
+ return HttpResponse(headers={"forceReload" : "true"})
return redirect(request.headers.get("Referer", "/"))
From 6951b523652fb26ab9a435475f83da50447fa87e Mon Sep 17 00:00:00 2001
From: Hugh Rundle
Date: Sat, 20 Nov 2021 08:18:43 +1100
Subject: [PATCH 05/42] disallow moving to shelf already used
---
bookwyrm/templates/snippets/shelf_selector.html | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/bookwyrm/templates/snippets/shelf_selector.html b/bookwyrm/templates/snippets/shelf_selector.html
index eca7a1d0a..34077dc1e 100644
--- a/bookwyrm/templates/snippets/shelf_selector.html
+++ b/bookwyrm/templates/snippets/shelf_selector.html
@@ -12,13 +12,7 @@
{% with book.id|uuid as uuid %}
{% active_shelf book as active_shelf %}
{% for shelf in user_shelves %}
-
{% if shelf.editable %}
@@ -26,10 +20,11 @@
-
+
{% else%}
+{% comparison_bool shelf.identifier active_shelf.shelf.identifier as is_current %}
{% with button_class="is-fullwidth is-small shelf-option is-radiusless is-white" %}
{% if shelf.identifier == 'reading' %}
From a0821219304f4fa66ac5ed8a7c8a7b50afe185f8 Mon Sep 17 00:00:00 2001
From: Hugh Rundle
Date: Sat, 20 Nov 2021 08:55:43 +1100
Subject: [PATCH 06/42] fix shelves not being unshelved if any shelf is
read-status
---
bookwyrm/views/reading.py | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/bookwyrm/views/reading.py b/bookwyrm/views/reading.py
index a96ccbc09..8e6ef9a1e 100644
--- a/bookwyrm/views/reading.py
+++ b/bookwyrm/views/reading.py
@@ -86,15 +86,19 @@ class ReadingStatus(View):
if request.POST.get("post-status"):
# is it a comment?
if request.POST.get("content"):
- # BUG: there is a problem posting statuses for finishing
- # check whether it existed before.
+ # BUG: there is a problem posting statuses with comments (doesn't force reload)
+ # there is a DIFFERENT problem *updating* read statuses/comments
return CreateStatus.as_view()(request, "comment")
privacy = request.POST.get("privacy")
handle_reading_status(request.user, desired_shelf, book, privacy)
+ # if the request includes a "shelf" value we are using the 'move' button
if bool(request.POST.get("shelf")):
- if current_status_shelfbook is None:
+ # unshelve the existing shelf
+ this_shelf = request.POST.get("shelf")
+ if int(this_shelf) not in [1,2,3]:
return unshelve(request, referer=referer, book_id=book_id)
+ # don't try to unshelve a read status shelf: it has already been deleted.
return HttpResponse(headers={"forceReload" : "true"})
if is_api_request(request):
From 373cc2c762060b93b1edbeec04528d5632f4f65b Mon Sep 17 00:00:00 2001
From: Hugh Rundle
Date: Sat, 20 Nov 2021 09:58:34 +1100
Subject: [PATCH 07/42] active_shelf should always be a reading status shelf
---
bookwyrm/templatetags/bookwyrm_tags.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/bookwyrm/templatetags/bookwyrm_tags.py b/bookwyrm/templatetags/bookwyrm_tags.py
index bccd8c75a..425ecc158 100644
--- a/bookwyrm/templatetags/bookwyrm_tags.py
+++ b/bookwyrm/templatetags/bookwyrm_tags.py
@@ -77,7 +77,8 @@ def related_status(notification):
def active_shelf(context, book):
"""check what shelf a user has a book on, if any"""
if hasattr(book, "current_shelves"):
- return book.current_shelves[0] if len(book.current_shelves) else {"book": book}
+ read_shelves = [s for s in book.current_shelves if s.shelf.identifier in models.Shelf.READ_STATUS_IDENTIFIERS]
+ return read_shelves[0] if len(read_shelves) else {"book": book}
shelf = (
models.ShelfBook.objects.filter(
From c6a2de3bbca83411b92b817f5796e2dd7e3ca298 Mon Sep 17 00:00:00 2001
From: Hugh Rundle
Date: Sat, 20 Nov 2021 10:29:17 +1100
Subject: [PATCH 08/42] pass readthrough id to shelf_selector
- allows user to move book from a shelf to the 'Read' shelf using the move button.
---
bookwyrm/templates/book/book.html | 2 +-
bookwyrm/templates/snippets/shelf_selector.html | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/bookwyrm/templates/book/book.html b/bookwyrm/templates/book/book.html
index c8c509784..1eb08001d 100644
--- a/bookwyrm/templates/book/book.html
+++ b/bookwyrm/templates/book/book.html
@@ -162,7 +162,7 @@
{% blocktrans with path=shelf.shelf.local_path shelf_name=shelf.shelf.name %}{{ shelf_name }}{% endblocktrans %}
- {% include 'snippets/shelf_selector.html' with current=shelf.shelf class="is-small" %}
+ {% include 'snippets/shelf_selector.html' with current=shelf.shelf class="is-small" readthrough=readthrough %}
{% endfor %}
diff --git a/bookwyrm/templates/snippets/shelf_selector.html b/bookwyrm/templates/snippets/shelf_selector.html
index 34077dc1e..1a2c46d01 100644
--- a/bookwyrm/templates/snippets/shelf_selector.html
+++ b/bookwyrm/templates/snippets/shelf_selector.html
@@ -11,6 +11,8 @@
{% block dropdown-list %}
{% with book.id|uuid as uuid %}
{% active_shelf book as active_shelf %}
+{% latest_read_through book request.user as readthrough %}
+
{% for shelf in user_shelves %}
{% if shelf.editable %}
@@ -67,7 +69,5 @@
{% include 'snippets/reading_modals/finish_reading_modal.html' with book=active_shelf.book controls_text="finish_reading" controls_uid=uuid move_from=current.id readthrough=readthrough %}
-{% include 'snippets/reading_modals/progress_update_modal.html' with book=active_shelf.book controls_text="progress_update" controls_uid=uuid move_from=current.id readthrough=readthrough %}
-
{% endwith %}
{% endblock %}
From 41862e854cdc95d1d6a1f8d71700d057c43ec661 Mon Sep 17 00:00:00 2001
From: Hugh Rundle
Date: Sat, 20 Nov 2021 13:57:37 +1100
Subject: [PATCH 09/42] move from reading to editable shelf with logic that
actually works
---
bookwyrm/views/reading.py | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/bookwyrm/views/reading.py b/bookwyrm/views/reading.py
index 8e6ef9a1e..c4064d97c 100644
--- a/bookwyrm/views/reading.py
+++ b/bookwyrm/views/reading.py
@@ -96,7 +96,11 @@ class ReadingStatus(View):
if bool(request.POST.get("shelf")):
# unshelve the existing shelf
this_shelf = request.POST.get("shelf")
- if int(this_shelf) not in [1,2,3]:
+ if (
+ bool(current_status_shelfbook) and
+ int(this_shelf) != int(current_status_shelfbook.shelf.id) and
+ current_status_shelfbook.shelf.identifier != desired_shelf.identifier
+ ):
return unshelve(request, referer=referer, book_id=book_id)
# don't try to unshelve a read status shelf: it has already been deleted.
return HttpResponse(headers={"forceReload" : "true"})
From af9768a2e31d4652b8afd5da85ec333a15f942ef Mon Sep 17 00:00:00 2001
From: Hugh Rundle
Date: Sat, 20 Nov 2021 14:59:59 +1100
Subject: [PATCH 10/42] force page reload when adding status from move button
---
bookwyrm/views/status.py | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/bookwyrm/views/status.py b/bookwyrm/views/status.py
index 8e487bf97..cd8d27049 100644
--- a/bookwyrm/views/status.py
+++ b/bookwyrm/views/status.py
@@ -117,12 +117,16 @@ class CreateStatus(View):
status.save(created=created)
- # update a readthorugh, if needed
+ # update a readthrough, if needed
try:
edit_readthrough(request)
except Http404:
pass
+ # force page reload if this was triggered from 'move' button
+ if bool(request.POST.get("shelf")):
+ return HttpResponse(headers={"forceReload" : "true"})
+
if is_api_request(request):
return HttpResponse()
return redirect("/")
@@ -157,6 +161,8 @@ def update_progress(request, book_id): # pylint: disable=unused-argument
@require_POST
def edit_readthrough(request):
"""can't use the form because the dates are too finnicky"""
+ # BUG when triggering finish reading with comments and no previous readthroughs
+ # this will 404
readthrough = get_object_or_404(models.ReadThrough, id=request.POST.get("id"))
readthrough.raise_not_editable(request.user)
From 12810d8e341a7d00faca4c6179b3055df3b2a604 Mon Sep 17 00:00:00 2001
From: Hugh Rundle
Date: Sat, 20 Nov 2021 16:03:46 +1100
Subject: [PATCH 11/42] don't try to update non-existent readthroughs
---
bookwyrm/views/reading.py | 2 --
bookwyrm/views/status.py | 9 +++++----
2 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/bookwyrm/views/reading.py b/bookwyrm/views/reading.py
index c4064d97c..04074b3db 100644
--- a/bookwyrm/views/reading.py
+++ b/bookwyrm/views/reading.py
@@ -86,8 +86,6 @@ class ReadingStatus(View):
if request.POST.get("post-status"):
# is it a comment?
if request.POST.get("content"):
- # BUG: there is a problem posting statuses with comments (doesn't force reload)
- # there is a DIFFERENT problem *updating* read statuses/comments
return CreateStatus.as_view()(request, "comment")
privacy = request.POST.get("privacy")
handle_reading_status(request.user, desired_shelf, book, privacy)
diff --git a/bookwyrm/views/status.py b/bookwyrm/views/status.py
index cd8d27049..8488b21e0 100644
--- a/bookwyrm/views/status.py
+++ b/bookwyrm/views/status.py
@@ -118,10 +118,11 @@ class CreateStatus(View):
status.save(created=created)
# update a readthrough, if needed
- try:
- edit_readthrough(request)
- except Http404:
- pass
+ if bool(request.POST.get("id")):
+ try:
+ edit_readthrough(request)
+ except Http404:
+ pass
# force page reload if this was triggered from 'move' button
if bool(request.POST.get("shelf")):
From b273123708c3c2ee4a74d0722edaaba99f0e4eaf Mon Sep 17 00:00:00 2001
From: Hugh Rundle
Date: Sat, 20 Nov 2021 16:06:16 +1100
Subject: [PATCH 12/42] code style
---
bookwyrm/static/js/status_cache.js | 1 +
bookwyrm/templatetags/bookwyrm_tags.py | 6 +++++-
bookwyrm/views/reading.py | 13 +++++++------
bookwyrm/views/shelf/shelf_actions.py | 2 +-
bookwyrm/views/status.py | 2 +-
5 files changed, 15 insertions(+), 9 deletions(-)
diff --git a/bookwyrm/static/js/status_cache.js b/bookwyrm/static/js/status_cache.js
index c59e23ee4..49f1c1295 100644
--- a/bookwyrm/static/js/status_cache.js
+++ b/bookwyrm/static/js/status_cache.js
@@ -192,6 +192,7 @@ let StatusCache = new class {
.forEach(item => BookWyrm.addRemoveClass(item, "is-hidden", false));
// Remove existing disabled states
+ // BUG: this affects all shelves, not just shelving status shelves
button.querySelectorAll("[data-shelf-dropdown-identifier] button")
.forEach(item => item.disabled = false);
diff --git a/bookwyrm/templatetags/bookwyrm_tags.py b/bookwyrm/templatetags/bookwyrm_tags.py
index 425ecc158..9d84d1ff8 100644
--- a/bookwyrm/templatetags/bookwyrm_tags.py
+++ b/bookwyrm/templatetags/bookwyrm_tags.py
@@ -77,7 +77,11 @@ def related_status(notification):
def active_shelf(context, book):
"""check what shelf a user has a book on, if any"""
if hasattr(book, "current_shelves"):
- read_shelves = [s for s in book.current_shelves if s.shelf.identifier in models.Shelf.READ_STATUS_IDENTIFIERS]
+ read_shelves = [
+ s
+ for s in book.current_shelves
+ if s.shelf.identifier in models.Shelf.READ_STATUS_IDENTIFIERS
+ ]
return read_shelves[0] if len(read_shelves) else {"book": book}
shelf = (
diff --git a/bookwyrm/views/reading.py b/bookwyrm/views/reading.py
index 04074b3db..334235b34 100644
--- a/bookwyrm/views/reading.py
+++ b/bookwyrm/views/reading.py
@@ -91,17 +91,18 @@ class ReadingStatus(View):
handle_reading_status(request.user, desired_shelf, book, privacy)
# if the request includes a "shelf" value we are using the 'move' button
- if bool(request.POST.get("shelf")):
+ if bool(request.POST.get("shelf")):
# unshelve the existing shelf
this_shelf = request.POST.get("shelf")
if (
- bool(current_status_shelfbook) and
- int(this_shelf) != int(current_status_shelfbook.shelf.id) and
- current_status_shelfbook.shelf.identifier != desired_shelf.identifier
- ):
+ bool(current_status_shelfbook)
+ and int(this_shelf) != int(current_status_shelfbook.shelf.id)
+ and current_status_shelfbook.shelf.identifier
+ != desired_shelf.identifier
+ ):
return unshelve(request, referer=referer, book_id=book_id)
# don't try to unshelve a read status shelf: it has already been deleted.
- return HttpResponse(headers={"forceReload" : "true"})
+ return HttpResponse(headers={"forceReload": "true"})
if is_api_request(request):
return HttpResponse()
diff --git a/bookwyrm/views/shelf/shelf_actions.py b/bookwyrm/views/shelf/shelf_actions.py
index 8240055e2..f431c1fab 100644
--- a/bookwyrm/views/shelf/shelf_actions.py
+++ b/bookwyrm/views/shelf/shelf_actions.py
@@ -102,5 +102,5 @@ def unshelve(request, referer=None, book_id=False):
shelf_book.raise_not_deletable(request.user)
shelf_book.delete()
if bool(referer):
- return HttpResponse(headers={"forceReload" : "true"})
+ return HttpResponse(headers={"forceReload": "true"})
return redirect(request.headers.get("Referer", "/"))
diff --git a/bookwyrm/views/status.py b/bookwyrm/views/status.py
index 8488b21e0..eafe0680e 100644
--- a/bookwyrm/views/status.py
+++ b/bookwyrm/views/status.py
@@ -126,7 +126,7 @@ class CreateStatus(View):
# force page reload if this was triggered from 'move' button
if bool(request.POST.get("shelf")):
- return HttpResponse(headers={"forceReload" : "true"})
+ return HttpResponse(headers={"forceReload": "true"})
if is_api_request(request):
return HttpResponse()
From 4b6f5c9f5179abc3d000d1424edd7c1af39ac51d Mon Sep 17 00:00:00 2001
From: Hugh Rundle
Date: Sat, 20 Nov 2021 19:03:57 +1100
Subject: [PATCH 13/42] remove out of date comment
---
bookwyrm/views/status.py | 2 --
1 file changed, 2 deletions(-)
diff --git a/bookwyrm/views/status.py b/bookwyrm/views/status.py
index eafe0680e..588dcf6ac 100644
--- a/bookwyrm/views/status.py
+++ b/bookwyrm/views/status.py
@@ -162,8 +162,6 @@ def update_progress(request, book_id): # pylint: disable=unused-argument
@require_POST
def edit_readthrough(request):
"""can't use the form because the dates are too finnicky"""
- # BUG when triggering finish reading with comments and no previous readthroughs
- # this will 404
readthrough = get_object_or_404(models.ReadThrough, id=request.POST.get("id"))
readthrough.raise_not_editable(request.user)
From b406a0353301d74cb380411049b67262e4074205 Mon Sep 17 00:00:00 2001
From: Hugh Rundle
Date: Sat, 20 Nov 2021 19:04:51 +1100
Subject: [PATCH 14/42] don't persist form state in firefox
Fixes shelves not being disabled in dropdowns.
See https://stackoverflow.com/questions/5985839/bug-with-firefox-disabled-attribute-of-input-not-resetting-when-refreshing
---
.../snippets/shelve_button/shelve_button_dropdown_options.html | 2 +-
bookwyrm/templates/snippets/toggle/toggle_button.html | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
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 32319f863..8c1881ce9 100644
--- a/bookwyrm/templates/snippets/shelve_button/shelve_button_dropdown_options.html
+++ b/bookwyrm/templates/snippets/shelve_button/shelve_button_dropdown_options.html
@@ -32,7 +32,7 @@
{% elif shelf.editable %}
-
+
{% csrf_token %}
diff --git a/bookwyrm/views/books/edit_book.py b/bookwyrm/views/books/edit_book.py
index 1445dc011..0bacd6074 100644
--- a/bookwyrm/views/books/edit_book.py
+++ b/bookwyrm/views/books/edit_book.py
@@ -43,12 +43,12 @@ class EditBook(View):
if not form.is_valid():
return TemplateResponse(request, "book/edit/edit_book.html", data)
- add_author = request.POST.get("add_author")
+ add_author = request.POST.getlist("add_author")
# we're adding an author through a free text field
if add_author:
data["add_author"] = add_author
data["author_matches"] = []
- for author in add_author.split(","):
+ for author in add_author:
if not author:
continue
# check for existing authors
From a0093a8a2e63c42fa89e09c0d1061b8e4f41dda5 Mon Sep 17 00:00:00 2001
From: Joachim
Date: Mon, 22 Nov 2021 00:25:47 +0100
Subject: [PATCH 18/42] Add status type filters
---
bookwyrm/forms.py | 23 ++++++++++++
bookwyrm/models/user.py | 9 ++++-
bookwyrm/templates/feed/feed.html | 21 +++++++++++
.../widgets/checkbox_select_horizontal.html | 11 ++++++
.../checkbox_select_horizontal_option.html | 4 +++
bookwyrm/views/feed.py | 35 +++++++++++++++++--
6 files changed, 100 insertions(+), 3 deletions(-)
create mode 100644 bookwyrm/templates/widgets/checkbox_select_horizontal.html
create mode 100644 bookwyrm/templates/widgets/checkbox_select_horizontal_option.html
diff --git a/bookwyrm/forms.py b/bookwyrm/forms.py
index 847ca05c0..fc8f018d0 100644
--- a/bookwyrm/forms.py
+++ b/bookwyrm/forms.py
@@ -174,6 +174,29 @@ class UserGroupForm(CustomForm):
fields = ["groups"]
+class CheckboxSelectMultipleHorizontal(widgets.CheckboxSelectMultiple):
+ template_name = "widgets/checkbox_select_horizontal.html"
+ option_template_name = "widgets/checkbox_select_horizontal_option.html"
+
+
+class FeedStatusTypes(CustomForm):
+ class Meta:
+ model = models.User
+ fields = ["feed_status_types"]
+ help_texts = {f: None for f in fields}
+ labels = {"feed_status_types": ""}
+ widgets = {
+ "feed_status_types": CheckboxSelectMultipleHorizontal(
+ choices=[
+ ("review", _("Reviews")),
+ ("comment", _("Comments")),
+ ("quotation", _("Quotations")),
+ ("everything", _("Everything else")),
+ ],
+ ),
+ }
+
+
class CoverForm(CustomForm):
class Meta:
model = models.Book
diff --git a/bookwyrm/models/user.py b/bookwyrm/models/user.py
index d7945843f..7ca92e4f2 100644
--- a/bookwyrm/models/user.py
+++ b/bookwyrm/models/user.py
@@ -4,7 +4,7 @@ from urllib.parse import urlparse
from django.apps import apps
from django.contrib.auth.models import AbstractUser, Group
-from django.contrib.postgres.fields import CICharField
+from django.contrib.postgres.fields import ArrayField, CICharField
from django.core.validators import MinValueValidator
from django.dispatch import receiver
from django.db import models, transaction
@@ -128,6 +128,13 @@ class User(OrderedCollectionPageMixin, AbstractUser):
show_suggested_users = models.BooleanField(default=True)
discoverable = fields.BooleanField(default=False)
+ # feed options
+ feed_status_types = ArrayField(
+ models.CharField(max_length=10, blank=False),
+ size=8,
+ default=list(["review", "comment", "quotation", "everything"]),
+ )
+
preferred_timezone = models.CharField(
choices=[(str(tz), str(tz)) for tz in pytz.all_timezones],
default=str(pytz.utc),
diff --git a/bookwyrm/templates/feed/feed.html b/bookwyrm/templates/feed/feed.html
index a6175199d..9783e2126 100644
--- a/bookwyrm/templates/feed/feed.html
+++ b/bookwyrm/templates/feed/feed.html
@@ -16,6 +16,27 @@
+
+
+
+ What to display?
+ {% if settings_saved %}
+ Saved!
+ {% endif %}
+
+
+{% endif %}
{% include 'snippets/reading_modals/want_to_read_modal.html' with book=active_shelf.book controls_text="want_to_read" controls_uid=uuid move_from=current.id %}
From b91915d31680b71864ba14cc686442fb58a2c9c1 Mon Sep 17 00:00:00 2001
From: Hugh Rundle
Date: Thu, 25 Nov 2021 08:20:34 +1100
Subject: [PATCH 32/42] change shelf var for shelf_selector in book view
---
bookwyrm/templates/book/book.html | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/bookwyrm/templates/book/book.html b/bookwyrm/templates/book/book.html
index 1eb08001d..713e7abee 100644
--- a/bookwyrm/templates/book/book.html
+++ b/bookwyrm/templates/book/book.html
@@ -162,7 +162,7 @@
{% blocktrans with path=shelf.shelf.local_path shelf_name=shelf.shelf.name %}{{ shelf_name }}{% endblocktrans %}
- {% include 'snippets/shelf_selector.html' with current=shelf.shelf class="is-small" readthrough=readthrough %}
+ {% include 'snippets/shelf_selector.html' with shelf=shelf.shelf class="is-small" readthrough=readthrough %}
{% endfor %}
From 5b67226571d85d281e3ccedc2710084ffceb2201 Mon Sep 17 00:00:00 2001
From: Hugh Rundle
Date: Thu, 25 Nov 2021 19:12:03 +1100
Subject: [PATCH 33/42] forceReload prevents ajax submission
...instead of weird hacky workarounds forcing refreshes later.
---
bookwyrm/static/js/status_cache.js | 8 +-------
bookwyrm/views/reading.py | 2 --
bookwyrm/views/shelf/shelf_actions.py | 2 --
bookwyrm/views/status.py | 4 ----
4 files changed, 1 insertion(+), 15 deletions(-)
diff --git a/bookwyrm/static/js/status_cache.js b/bookwyrm/static/js/status_cache.js
index f179aa7d9..1ec72b3cb 100644
--- a/bookwyrm/static/js/status_cache.js
+++ b/bookwyrm/static/js/status_cache.js
@@ -74,7 +74,7 @@ let StatusCache = new class {
// This allows the form to submit in the old fashioned way if there's a problem
- if (!trigger || !form) {
+ if (!trigger || !form || response.headers.get("forceReload")) {
return;
}
@@ -90,12 +90,6 @@ let StatusCache = new class {
trigger.removeAttribute('disabled');
})
.then(response => {
- if (response.headers.get("forceReload")) {
- BookWyrm.addRemoveClass(form, 'is-processing', true);
- trigger.setAttribute('disabled', null);
-
- return location.reload();
- }
if (!response.ok) {
throw new Error();
diff --git a/bookwyrm/views/reading.py b/bookwyrm/views/reading.py
index 75a45f245..a91fa8e7a 100644
--- a/bookwyrm/views/reading.py
+++ b/bookwyrm/views/reading.py
@@ -102,8 +102,6 @@ class ReadingStatus(View):
!= desired_shelf.identifier
):
return unshelve(request, referer=referer, book_id=book_id)
- # don't try to unshelve a read status shelf: it has already been deleted.
- return HttpResponse(headers={"forceReload": "true"})
if is_api_request(request):
return HttpResponse()
diff --git a/bookwyrm/views/shelf/shelf_actions.py b/bookwyrm/views/shelf/shelf_actions.py
index 77053f534..3fff92a6a 100644
--- a/bookwyrm/views/shelf/shelf_actions.py
+++ b/bookwyrm/views/shelf/shelf_actions.py
@@ -101,6 +101,4 @@ def unshelve(request, referer=None, book_id=False):
)
shelf_book.raise_not_deletable(request.user)
shelf_book.delete()
- if bool(referer):
- return HttpResponse(headers={"forceReload": "true"})
return redirect(request.headers.get("Referer", "/"))
diff --git a/bookwyrm/views/status.py b/bookwyrm/views/status.py
index 144408b50..bb69d30c0 100644
--- a/bookwyrm/views/status.py
+++ b/bookwyrm/views/status.py
@@ -125,10 +125,6 @@ class CreateStatus(View):
except Http404:
pass
- # force page reload if this was triggered from 'move' button
- if bool(request.POST.get("shelf")):
- return HttpResponse(headers={"forceReload": "true"})
-
if is_api_request(request):
return HttpResponse()
return redirect("/")
From 951eb43aa657d9ced537b078bf14286520b18a66 Mon Sep 17 00:00:00 2001
From: Hugh Rundle
Date: Fri, 26 Nov 2021 17:16:26 +1100
Subject: [PATCH 34/42] bypass ajax for shelf_selector statuses
---
bookwyrm/static/js/status_cache.js | 3 +--
.../snippets/reading_modals/finish_reading_modal.html | 2 +-
.../snippets/reading_modals/start_reading_modal.html | 2 +-
.../snippets/reading_modals/want_to_read_modal.html | 2 +-
bookwyrm/templates/snippets/shelf_selector.html | 6 +++---
5 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/bookwyrm/static/js/status_cache.js b/bookwyrm/static/js/status_cache.js
index 1ec72b3cb..418b7dee2 100644
--- a/bookwyrm/static/js/status_cache.js
+++ b/bookwyrm/static/js/status_cache.js
@@ -74,7 +74,7 @@ let StatusCache = new class {
// This allows the form to submit in the old fashioned way if there's a problem
- if (!trigger || !form || response.headers.get("forceReload")) {
+ if (!trigger || !form) {
return;
}
@@ -90,7 +90,6 @@ let StatusCache = new class {
trigger.removeAttribute('disabled');
})
.then(response => {
-
if (!response.ok) {
throw new Error();
}
diff --git a/bookwyrm/templates/snippets/reading_modals/finish_reading_modal.html b/bookwyrm/templates/snippets/reading_modals/finish_reading_modal.html
index 79542b29a..a35ed9e0b 100644
--- a/bookwyrm/templates/snippets/reading_modals/finish_reading_modal.html
+++ b/bookwyrm/templates/snippets/reading_modals/finish_reading_modal.html
@@ -9,7 +9,7 @@ Finish "{{ book_title }}"
{% endblock %}
{% block modal-form-open %}
-
{% url 'prefs-profile' as path %}
{% blocktrans with path=path %}You can opt-out at any time in your profile settings.{% endblocktrans %}
@@ -28,7 +28,7 @@
{% trans "Dismiss message" as button_text %}
- Dismiss message
+ {% trans "Dismiss message" %}