Merge branch 'main' into production

This commit is contained in:
Mouse Reeve 2021-01-18 16:55:28 -08:00
commit 1eb979f05d
2 changed files with 7 additions and 6 deletions

View file

@ -75,7 +75,7 @@
<div class="hidden box mb-5" id="edit-shelf-form">
<h2 class="title is-4">Edit shelf</h2>
<form name="create-shelf" action="/edit-shelf/{{ shelf.id }}" method="post">
<form name="create-shelf" action="{{ shelf.local_path }}" method="post">
{% csrf_token %}
<input type="hidden" name="user" value="{{ request.user.id }}">
{% if shelf.editable %}

View file

@ -65,12 +65,13 @@ class Shelf(View):
return TemplateResponse(request, 'shelf.html', data)
@method_decorator(login_required, name='dispatch')
def post(self, request, username, shelf_id):
''' user generated shelves '''
if not request.user.username == username:
return HttpResponseBadRequest()
def post(self, request, username, shelf_identifier):
''' edit a shelf '''
try:
shelf = request.user.shelf_set.get(identifier=shelf_identifier)
except models.Shelf.DoesNotExist:
return HttpResponseNotFound()
shelf = get_object_or_404(models.Shelf, id=shelf_id)
if request.user != shelf.user:
return HttpResponseBadRequest()
if not shelf.editable and request.POST.get('name') != shelf.name: