From a2811b6c1b60f981ce2887ed9a07f89ad41309ac Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sun, 5 Sep 2021 15:14:57 -0700 Subject: [PATCH] Fixes redirects in fallback post modal --- 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 9100e1d4..70dc2147 100644 --- a/bookwyrm/views/reading.py +++ b/bookwyrm/views/reading.py @@ -31,6 +31,7 @@ class ReadingStatus(View): }.get(status) if not template: return HttpResponseNotFound() + # redirect if we're already on this shelf return TemplateResponse(request, f"reading_progress/{template}", {"book": book}) def post(self, request, status, book_id): @@ -58,11 +59,15 @@ class ReadingStatus(View): ) .first() ) + + referer = request.headers.get("Referer", "/") + if "reading-status" in referer: + referer = "/" if current_status_shelfbook is not None: if current_status_shelfbook.shelf.identifier != desired_shelf.identifier: current_status_shelfbook.delete() else: # It already was on the shelf - return redirect(request.headers.get("Referer", "/")) + return redirect(referer) models.ShelfBook.objects.create( book=book, shelf=desired_shelf, user=request.user @@ -87,8 +92,7 @@ class ReadingStatus(View): else: privacy = request.POST.get("privacy") handle_reading_status(request.user, desired_shelf, book, privacy) - - return redirect(request.headers.get("Referer", "/")) + return redirect(referer) @login_required