diff --git a/bookwyrm/static/js/status_cache.js b/bookwyrm/static/js/status_cache.js index b3e345b1..2a50bfcb 100644 --- a/bookwyrm/static/js/status_cache.js +++ b/bookwyrm/static/js/status_cache.js @@ -141,8 +141,10 @@ let StatusCache = new class { modal.getElementsByClassName("modal-close")[0].click(); // Update shelve buttons - document.querySelectorAll("[data-shelve-button-book='" + form.book.value +"']") - .forEach(button => this.cycleShelveButtons(button, form.reading_status.value)); + if (form.reading_status) { + document.querySelectorAll("[data-shelve-button-book='" + form.book.value +"']") + .forEach(button => this.cycleShelveButtons(button, form.reading_status.value)); + } return; } diff --git a/bookwyrm/templates/snippets/reading_modals/finish_reading_modal.html b/bookwyrm/templates/snippets/reading_modals/finish_reading_modal.html index b041b70a..96e4da9b 100644 --- a/bookwyrm/templates/snippets/reading_modals/finish_reading_modal.html +++ b/bookwyrm/templates/snippets/reading_modals/finish_reading_modal.html @@ -11,6 +11,7 @@ Finish "{{ book_title }}" {% block modal-form-open %}
{% csrf_token %} + {% endblock %} diff --git a/bookwyrm/templates/snippets/reading_modals/form.html b/bookwyrm/templates/snippets/reading_modals/form.html index 382407ba..4a7ac3a5 100644 --- a/bookwyrm/templates/snippets/reading_modals/form.html +++ b/bookwyrm/templates/snippets/reading_modals/form.html @@ -5,12 +5,13 @@ {% block content_label %} {% trans "Comment:" %} +{% if optional %} {% trans "(Optional)" %} +{% endif %} {% endblock %} {% block initial_fields %} - {% endblock %} diff --git a/bookwyrm/templates/snippets/reading_modals/layout.html b/bookwyrm/templates/snippets/reading_modals/layout.html index 0f5dedb0..95010b37 100644 --- a/bookwyrm/templates/snippets/reading_modals/layout.html +++ b/bookwyrm/templates/snippets/reading_modals/layout.html @@ -13,14 +13,18 @@ {% trans "Post to feed" %}
- {% include "snippets/reading_modals/form.html" with optional=True %} + {% comparison_bool controls_text "progress_update" True as optional %} + {% include "snippets/reading_modals/form.html" with optional=optional %}
{% endwith %} diff --git a/bookwyrm/templates/snippets/reading_modals/progress_update_modal.html b/bookwyrm/templates/snippets/reading_modals/progress_update_modal.html index fb52432c..713dad8d 100644 --- a/bookwyrm/templates/snippets/reading_modals/progress_update_modal.html +++ b/bookwyrm/templates/snippets/reading_modals/progress_update_modal.html @@ -6,8 +6,9 @@ {% endblock %} {% block modal-form-open %} - + {% csrf_token %} + {% endblock %} {% block reading-dates %} diff --git a/bookwyrm/templates/snippets/shelve_button/shelve_button.html b/bookwyrm/templates/snippets/shelve_button/shelve_button.html index 0af16a93..b70ba1b9 100644 --- a/bookwyrm/templates/snippets/shelve_button/shelve_button.html +++ b/bookwyrm/templates/snippets/shelve_button/shelve_button.html @@ -25,7 +25,7 @@ {% include 'snippets/reading_modals/finish_reading_modal.html' with book=active_shelf.book controls_text="finish_reading" controls_uid=uuid readthrough=readthrough %} -{% include 'snippets/reading_modals/progress_update_modal.html' with book=active_shelf_book.book controls_text="progress_update" controls_uid=uuid readthrough=readthrough %} +{% include 'snippets/reading_modals/progress_update_modal.html' with book=active_shelf.book controls_text="progress_update" controls_uid=uuid readthrough=readthrough %} {% endwith %} {% endif %} diff --git a/bookwyrm/templatetags/utilities.py b/bookwyrm/templatetags/utilities.py index 76b4cd3f..d31f0e4d 100644 --- a/bookwyrm/templatetags/utilities.py +++ b/bookwyrm/templatetags/utilities.py @@ -36,8 +36,10 @@ def get_title(book, too_short=5): @register.simple_tag(takes_context=False) -def comparison_bool(str1, str2): +def comparison_bool(str1, str2, reverse=False): """idk why I need to write a tag for this, it returns a bool""" + if reverse: + return str1 != str2 return str1 == str2 diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 7d9ab312..360f147f 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -370,6 +370,11 @@ urlpatterns = [ re_path(r"^create-readthrough/?$", views.create_readthrough), re_path(r"^delete-progressupdate/?$", views.delete_progressupdate), # shelve actions + re_path( + r"^reading-status/update/(?P\d+)/?$", + views.update_progress, + name="reading-status-update", + ), re_path( r"^reading-status/(?Pwant|start|finish)/(?P\d+)/?$", views.ReadingStatus.as_view(), diff --git a/bookwyrm/views/__init__.py b/bookwyrm/views/__init__.py index e5b083d0..be59d59c 100644 --- a/bookwyrm/views/__init__.py +++ b/bookwyrm/views/__init__.py @@ -59,7 +59,7 @@ from .search import Search from .shelf import Shelf from .shelf import create_shelf, delete_shelf from .shelf import shelve, unshelve -from .status import CreateStatus, DeleteStatus, DeleteAndRedraft +from .status import CreateStatus, DeleteStatus, DeleteAndRedraft, update_progress from .updates import get_notification_count, get_unread_status_count from .user import User, Followers, Following, hide_suggestions from .wellknown import * diff --git a/bookwyrm/views/status.py b/bookwyrm/views/status.py index 3da8c725..3292bfa7 100644 --- a/bookwyrm/views/status.py +++ b/bookwyrm/views/status.py @@ -10,6 +10,7 @@ from django.shortcuts import get_object_or_404, redirect from django.template.response import TemplateResponse from django.utils.decorators import method_decorator from django.views import View +from django.views.decorators.http import require_POST from markdown import markdown from bookwyrm import forms, models @@ -135,6 +136,15 @@ class DeleteAndRedraft(View): return TemplateResponse(request, "compose.html", data) +@login_required +@require_POST +def update_progress(request, book_id): + """Either it's just a progress update, or it's a comment with a progress update""" + if request.POST.get("post-status"): + return CreateStatus.as_view()(request, "comment") + return edit_readthrough(request) + + def find_mentions(content): """detect @mentions in raw status content""" if not content: