forked from mirrors/bookwyrm
commit
e34ae35e0f
3 changed files with 61 additions and 3 deletions
|
@ -106,6 +106,8 @@
|
|||
<label class="label" for="id_name">Name:</label>
|
||||
<input type="text" name="name" maxlength="100" class="input" required="true" value="{{ shelf.name }}" id="id_name">
|
||||
</div>
|
||||
{% else %}
|
||||
<input type="hidden" name="name" required="true" value="{{ shelf.name }}">
|
||||
{% endif %}
|
||||
|
||||
<label class="label">
|
||||
|
|
|
@ -360,6 +360,61 @@ class ViewActions(TestCase):
|
|||
self.assertEqual(resp.template_name, 'edit_author.html')
|
||||
|
||||
|
||||
def test_edit_shelf_privacy(self):
|
||||
''' set name or privacy on shelf '''
|
||||
shelf = self.local_user.shelf_set.get(identifier='to-read')
|
||||
self.assertEqual(shelf.privacy, 'public')
|
||||
|
||||
request = self.factory.post(
|
||||
'', {
|
||||
'privacy': 'unlisted',
|
||||
'user': self.local_user.id,
|
||||
'name': 'To Read',
|
||||
})
|
||||
request.user = self.local_user
|
||||
actions.edit_shelf(request, shelf.id)
|
||||
shelf.refresh_from_db()
|
||||
|
||||
self.assertEqual(shelf.privacy, 'unlisted')
|
||||
|
||||
|
||||
def test_edit_shelf_name(self):
|
||||
''' change the name of an editable shelf '''
|
||||
shelf = models.Shelf.objects.create(
|
||||
name='Test Shelf', user=self.local_user)
|
||||
self.assertEqual(shelf.privacy, 'public')
|
||||
|
||||
request = self.factory.post(
|
||||
'', {
|
||||
'privacy': 'public',
|
||||
'user': self.local_user.id,
|
||||
'name': 'cool name'
|
||||
})
|
||||
request.user = self.local_user
|
||||
actions.edit_shelf(request, shelf.id)
|
||||
shelf.refresh_from_db()
|
||||
|
||||
self.assertEqual(shelf.name, 'cool name')
|
||||
self.assertEqual(shelf.identifier, 'testshelf-%d' % shelf.id)
|
||||
|
||||
|
||||
def test_edit_shelf_name_not_editable(self):
|
||||
''' can't change the name of an non-editable shelf '''
|
||||
shelf = self.local_user.shelf_set.get(identifier='to-read')
|
||||
self.assertEqual(shelf.privacy, 'public')
|
||||
|
||||
request = self.factory.post(
|
||||
'', {
|
||||
'privacy': 'public',
|
||||
'user': self.local_user.id,
|
||||
'name': 'cool name'
|
||||
})
|
||||
request.user = self.local_user
|
||||
actions.edit_shelf(request, shelf.id)
|
||||
|
||||
self.assertEqual(shelf.name, 'To Read')
|
||||
|
||||
|
||||
def test_edit_readthrough(self):
|
||||
''' adding dates to an ongoing readthrough '''
|
||||
start = timezone.make_aware(dateutil.parser.parse('2021-01-03'))
|
||||
|
|
|
@ -352,13 +352,14 @@ def edit_shelf(request, shelf_id):
|
|||
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:
|
||||
return HttpResponseBadRequest()
|
||||
|
||||
form = forms.ShelfForm(request.POST, instance=shelf)
|
||||
if not form.is_valid():
|
||||
return redirect(request.headers.get('Referer', '/'))
|
||||
return redirect(shelf.local_path)
|
||||
shelf = form.save()
|
||||
return redirect('/user/%s/shelf/%s' % \
|
||||
(request.user.localname, shelf.identifier))
|
||||
return redirect(shelf.local_path)
|
||||
|
||||
|
||||
@login_required
|
||||
|
|
Loading…
Reference in a new issue