mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2025-01-11 09:45:27 +00:00
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"""
|
"""list of books for this shelf, overrides OrderedCollectionMixin"""
|
||||||
return self.books.order_by("shelfbook")
|
return self.books.order_by("shelfbook")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def deletable(self):
|
||||||
|
return self.editable and not self.shelfbook_set.exists()
|
||||||
|
|
||||||
def get_remote_id(self):
|
def get_remote_id(self):
|
||||||
"""shelf identifier instead of id"""
|
"""shelf identifier instead of id"""
|
||||||
base_path = self.user.remote_id
|
base_path = self.user.remote_id
|
||||||
|
@ -62,9 +66,7 @@ class Shelf(OrderedCollectionMixin, BookWyrmModel):
|
||||||
def raise_not_deletable(self, viewer):
|
def raise_not_deletable(self, viewer):
|
||||||
"""don't let anyone delete a default shelf"""
|
"""don't let anyone delete a default shelf"""
|
||||||
super().raise_not_deletable(viewer)
|
super().raise_not_deletable(viewer)
|
||||||
if not self.editable:
|
if not self.deletable:
|
||||||
raise PermissionDenied()
|
|
||||||
if self.shelfbook_set.exists():
|
|
||||||
raise PermissionDenied()
|
raise PermissionDenied()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
|
@ -91,8 +91,20 @@
|
||||||
</div>
|
</div>
|
||||||
{% if is_self and shelf.id %}
|
{% if is_self and shelf.id %}
|
||||||
<div class="column is-narrow">
|
<div class="column is-narrow">
|
||||||
{% trans "Edit shelf" as button_text %}
|
<div class="is-flex">
|
||||||
{% include 'snippets/toggle/open_button.html' with text=button_text icon_with_text="pencil" controls_text="edit_shelf_form" focus="edit_shelf_form_header" %}
|
{% 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>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
@ -168,16 +180,6 @@
|
||||||
</table>
|
</table>
|
||||||
{% else %}
|
{% else %}
|
||||||
<p><em>{% trans "This shelf is empty." %}</em></p>
|
<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 %}
|
{% endif %}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -270,7 +270,8 @@ class ShelfViews(TestCase):
|
||||||
|
|
||||||
def test_delete_shelf_not_editable(self, *_):
|
def test_delete_shelf_not_editable(self, *_):
|
||||||
"""delete a brand new custom shelf"""
|
"""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 = self.factory.post("")
|
||||||
request.user = self.local_user
|
request.user = self.local_user
|
||||||
|
|
||||||
|
|
|
@ -85,7 +85,7 @@ class Shelf(View):
|
||||||
"shelves": shelves,
|
"shelves": shelves,
|
||||||
"shelf": shelf,
|
"shelf": shelf,
|
||||||
"books": page,
|
"books": page,
|
||||||
"edit_form": forms.ShelfForm(instance=shelf),
|
"edit_form": forms.ShelfForm(instance=shelf if shelf_identifier else None),
|
||||||
"create_form": forms.ShelfForm(),
|
"create_form": forms.ShelfForm(),
|
||||||
"page_range": paginated.get_elided_page_range(
|
"page_range": paginated.get_elided_page_range(
|
||||||
page.number, on_each_side=2, on_ends=1
|
page.number, on_each_side=2, on_ends=1
|
||||||
|
|
Loading…
Reference in a new issue