forked from mirrors/bookwyrm
Moves shelf delete button
This commit is contained in:
parent
6d9bf349d1
commit
5ea40e23b7
4 changed files with 22 additions and 17 deletions
|
@ -53,6 +53,10 @@ class Shelf(OrderedCollectionMixin, BookWyrmModel):
|
|||
"""list of books for this shelf, overrides OrderedCollectionMixin"""
|
||||
return self.books.order_by("shelfbook")
|
||||
|
||||
@property
|
||||
def deletable(self):
|
||||
return self.editable and not self.shelfbook_set.exists()
|
||||
|
||||
def get_remote_id(self):
|
||||
"""shelf identifier instead of id"""
|
||||
base_path = self.user.remote_id
|
||||
|
@ -62,9 +66,7 @@ class Shelf(OrderedCollectionMixin, BookWyrmModel):
|
|||
def raise_not_deletable(self, viewer):
|
||||
"""don't let anyone delete a default shelf"""
|
||||
super().raise_not_deletable(viewer)
|
||||
if not self.editable:
|
||||
raise PermissionDenied()
|
||||
if self.shelfbook_set.exists():
|
||||
if not self.deletable:
|
||||
raise PermissionDenied()
|
||||
|
||||
class Meta:
|
||||
|
|
|
@ -91,8 +91,20 @@
|
|||
</div>
|
||||
{% if is_self and shelf.id %}
|
||||
<div class="column is-narrow">
|
||||
{% trans "Edit shelf" as button_text %}
|
||||
{% include 'snippets/toggle/open_button.html' with text=button_text icon_with_text="pencil" controls_text="edit_shelf_form" focus="edit_shelf_form_header" %}
|
||||
<div class="is-flex">
|
||||
{% trans "Edit shelf" as button_text %}
|
||||
{% include 'snippets/toggle/open_button.html' with text=button_text icon_with_text="pencil" controls_text="edit_shelf_form" focus="edit_shelf_form_header" %}
|
||||
|
||||
{% if shelf.deletable %}
|
||||
<form class="ml-1" name="delete-shelf" action="/delete-shelf/{{ shelf.id }}" method="post">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="user" value="{{ request.user.id }}">
|
||||
<button class="button is-danger is-light" type="submit">
|
||||
{% trans "Delete shelf" %}
|
||||
</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
@ -168,16 +180,6 @@
|
|||
</table>
|
||||
{% else %}
|
||||
<p><em>{% trans "This shelf is empty." %}</em></p>
|
||||
{% if shelf.id and shelf.editable %}
|
||||
<form name="delete-shelf" action="/delete-shelf/{{ shelf.id }}" method="post">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="user" value="{{ request.user.id }}">
|
||||
<button class="button is-danger is-light" type="submit">
|
||||
{% trans "Delete shelf" %}
|
||||
</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
|
|
|
@ -270,7 +270,8 @@ class ShelfViews(TestCase):
|
|||
|
||||
def test_delete_shelf_not_editable(self, *_):
|
||||
"""delete a brand new custom shelf"""
|
||||
shelf = self.local_user.shelfset.first()
|
||||
shelf = self.local_user.shelf_set.first()
|
||||
self.assertFalse(shelf.editable)
|
||||
request = self.factory.post("")
|
||||
request.user = self.local_user
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@ class Shelf(View):
|
|||
"shelves": shelves,
|
||||
"shelf": shelf,
|
||||
"books": page,
|
||||
"edit_form": forms.ShelfForm(instance=shelf),
|
||||
"edit_form": forms.ShelfForm(instance=shelf if shelf_identifier else None),
|
||||
"create_form": forms.ShelfForm(),
|
||||
"page_range": paginated.get_elided_page_range(
|
||||
page.number, on_each_side=2, on_ends=1
|
||||
|
|
Loading…
Reference in a new issue