From 6280671d921ad3dc91c037e02a7521e152bef908 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 16 Aug 2021 13:04:34 -0700 Subject: [PATCH] Create comments when commentary is provided --- .../templates/snippets/reading_modals/form.html | 1 + bookwyrm/views/reading.py | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/bookwyrm/templates/snippets/reading_modals/form.html b/bookwyrm/templates/snippets/reading_modals/form.html index 00cb4088..d1ba916f 100644 --- a/bookwyrm/templates/snippets/reading_modals/form.html +++ b/bookwyrm/templates/snippets/reading_modals/form.html @@ -11,4 +11,5 @@ {% block initial_fields %} + {% endblock %} diff --git a/bookwyrm/views/reading.py b/bookwyrm/views/reading.py index 1c897ab3..39066265 100644 --- a/bookwyrm/views/reading.py +++ b/bookwyrm/views/reading.py @@ -12,7 +12,7 @@ from django.utils.decorators import method_decorator from django.views import View from django.views.decorators.http import require_POST -from bookwyrm import models +from bookwyrm import forms, models from .helpers import get_edition, handle_reading_status @@ -76,8 +76,17 @@ class ReadingStatus(View): # post about it (if you want) if request.POST.get("post-status"): - privacy = request.POST.get("privacy") - handle_reading_status(request.user, desired_shelf, book, privacy) + # is it a comment? + if request.POST.get("content"): + form = forms.CommentForm(request.POST) + if form.is_valid(): + form.save() + else: + # uh oh + raise Exception("Invalid form") + else: + privacy = request.POST.get("privacy") + handle_reading_status(request.user, desired_shelf, book, privacy) return redirect(request.headers.get("Referer", "/"))