From ee59c64a1014c568b29633a78571691e58700a6a Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Tue, 10 Nov 2020 20:11:21 -0800 Subject: [PATCH] Edit shelf --- bookwyrm/templates/shelf.html | 66 ++++++++++++++----- .../templates/snippets/privacy_select.html | 16 +++-- bookwyrm/urls.py | 1 + bookwyrm/view_actions.py | 16 ++++- 4 files changed, 78 insertions(+), 21 deletions(-) diff --git a/bookwyrm/templates/shelf.html b/bookwyrm/templates/shelf.html index f8e0e35b..571578cf 100644 --- a/bookwyrm/templates/shelf.html +++ b/bookwyrm/templates/shelf.html @@ -31,18 +31,21 @@ {% if is_self %}
-
{% endif %} - + {% if is_self %}
- - - Edit shelf - - + +
{% endif %} + + +
{% include 'snippets/shelf.html' with shelf=shelf ratings=ratings %} diff --git a/bookwyrm/templates/snippets/privacy_select.html b/bookwyrm/templates/snippets/privacy_select.html index 83ea9bea..c8d974c0 100644 --- a/bookwyrm/templates/snippets/privacy_select.html +++ b/bookwyrm/templates/snippets/privacy_select.html @@ -5,10 +5,18 @@ {% endif %} {% endwith %}
diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 82726c66..d55c6f61 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -121,6 +121,7 @@ urlpatterns = [ re_path(r'^delete-status/?$', actions.delete_status), re_path(r'^create-shelf/?$', actions.create_shelf), + re_path(r'^edit-shelf/(?P\d+)?$', actions.edit_shelf), re_path(r'^shelve/?$', actions.shelve), re_path(r'^unshelve/?$', actions.unshelve), re_path(r'^start-reading/?$', actions.start_reading), diff --git a/bookwyrm/view_actions.py b/bookwyrm/view_actions.py index ee035c5c..518aa271 100644 --- a/bookwyrm/view_actions.py +++ b/bookwyrm/view_actions.py @@ -11,7 +11,7 @@ from django.contrib.auth.decorators import login_required, permission_required from django.core.exceptions import PermissionDenied from django.core.files.base import ContentFile from django.http import HttpResponseBadRequest, HttpResponseNotFound -from django.shortcuts import redirect +from django.shortcuts import get_object_or_404, redirect from django.template.response import TemplateResponse from django.utils import timezone @@ -276,6 +276,20 @@ def upload_cover(request, book_id): def create_shelf(request): ''' user generated shelves ''' form = forms.ShelfForm(request.POST) + if not form.is_valid(): + return redirect(request.headers.get('Referer', '/')) + + shelf = form.save() + return redirect('/user/%s/shelf/%s' % \ + (request.user.localname, shelf.identifier)) + + +@login_required +def edit_shelf(request, shelf_id): + ''' user generated shelves ''' + shelf = get_object_or_404(models.Shelf, id=shelf_id) + + form = forms.ShelfForm(request.POST, instance=shelf) if not form.is_valid(): return redirect(request.headers.get('Referer', '/')) shelf = form.save()