mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-27 20:11:14 +00:00
Fixes editing shelves
This commit is contained in:
parent
8d88c768cc
commit
1bcb19fde9
3 changed files with 45 additions and 2 deletions
|
@ -106,6 +106,8 @@
|
||||||
<label class="label" for="id_name">Name:</label>
|
<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">
|
<input type="text" name="name" maxlength="100" class="input" required="true" value="{{ shelf.name }}" id="id_name">
|
||||||
</div>
|
</div>
|
||||||
|
{% else %}
|
||||||
|
<input type="hidden" name="name" required="true" value="{{ shelf.name }}">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<label class="label">
|
<label class="label">
|
||||||
|
|
|
@ -360,7 +360,7 @@ class ViewActions(TestCase):
|
||||||
self.assertEqual(resp.template_name, 'edit_author.html')
|
self.assertEqual(resp.template_name, 'edit_author.html')
|
||||||
|
|
||||||
|
|
||||||
def test_edit_shelf(self):
|
def test_edit_shelf_privacy(self):
|
||||||
''' set name or privacy on shelf '''
|
''' set name or privacy on shelf '''
|
||||||
shelf = self.local_user.shelf_set.get(identifier='to-read')
|
shelf = self.local_user.shelf_set.get(identifier='to-read')
|
||||||
self.assertEqual(shelf.privacy, 'public')
|
self.assertEqual(shelf.privacy, 'public')
|
||||||
|
@ -369,11 +369,50 @@ class ViewActions(TestCase):
|
||||||
'', {
|
'', {
|
||||||
'privacy': 'unlisted',
|
'privacy': 'unlisted',
|
||||||
'user': self.local_user.id,
|
'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
|
request.user = self.local_user
|
||||||
actions.edit_shelf(request, shelf.id)
|
actions.edit_shelf(request, shelf.id)
|
||||||
|
|
||||||
self.assertEqual(shelf.privacy, 'unlisted')
|
self.assertEqual(shelf.name, 'To Read')
|
||||||
|
|
||||||
|
|
||||||
def test_edit_readthrough(self):
|
def test_edit_readthrough(self):
|
||||||
|
|
|
@ -352,6 +352,8 @@ def edit_shelf(request, shelf_id):
|
||||||
shelf = get_object_or_404(models.Shelf, id=shelf_id)
|
shelf = get_object_or_404(models.Shelf, id=shelf_id)
|
||||||
if request.user != shelf.user:
|
if request.user != shelf.user:
|
||||||
return HttpResponseBadRequest()
|
return HttpResponseBadRequest()
|
||||||
|
if not shelf.editable and request.POST.get('name') != shelf.name:
|
||||||
|
return HttpResponseBadRequest()
|
||||||
|
|
||||||
form = forms.ShelfForm(request.POST, instance=shelf)
|
form = forms.ShelfForm(request.POST, instance=shelf)
|
||||||
if not form.is_valid():
|
if not form.is_valid():
|
||||||
|
|
Loading…
Reference in a new issue