diff --git a/bookwyrm/migrations/0126_filelink_link_linkdomain.py b/bookwyrm/migrations/0126_filelink_link_linkdomain.py index 52be86c5..bd261102 100644 --- a/bookwyrm/migrations/0126_filelink_link_linkdomain.py +++ b/bookwyrm/migrations/0126_filelink_link_linkdomain.py @@ -82,7 +82,7 @@ class Migration(migrations.Migration): models.ForeignKey( blank=True, null=True, - on_delete=django.db.models.deletion.PROTECT, + on_delete=django.db.models.deletion.CASCADE, to="bookwyrm.linkdomain", ), ), diff --git a/bookwyrm/models/link.py b/bookwyrm/models/link.py index e3c72b3f..f2b4108b 100644 --- a/bookwyrm/models/link.py +++ b/bookwyrm/models/link.py @@ -15,7 +15,7 @@ class Link(ActivitypubMixin, BookWyrmModel): url = fields.URLField(max_length=255, activitypub_field="href") domain = models.ForeignKey( - "LinkDomain", on_delete=models.PROTECT, null=True, blank=True + "LinkDomain", on_delete=models.CASCADE, null=True, blank=True ) activity_serializer = activitypub.Link diff --git a/bookwyrm/templates/book/book.html b/bookwyrm/templates/book/book.html index 6467bb71..1060f038 100644 --- a/bookwyrm/templates/book/book.html +++ b/bookwyrm/templates/book/book.html @@ -383,37 +383,7 @@ {% endif %}
-
-
-

{% trans "Get a copy" %}

-
- {% if can_edit_book %} -
- {% url 'file-link' book.id as fallback_url %} - -
- {% endif %} -
- {% if book.file_links %} - - {% endif %} - - {% if can_edit_book %} - {% include 'book/file_link_modal.html' with book=book id="edit-links" %} - {% endif %} + {% include "book/links.html" %}
diff --git a/bookwyrm/templates/book/links.html b/bookwyrm/templates/book/links.html new file mode 100644 index 00000000..6bce3c9b --- /dev/null +++ b/bookwyrm/templates/book/links.html @@ -0,0 +1,34 @@ +{% load i18n %} +{% load bookwyrm_tags %} +{% get_book_file_links book as links %} +
+
+

{% trans "Get a copy" %}

+
+ {% if can_edit_book %} +
+ {% url 'file-link' book.id as fallback_url %} + +
+ {% endif %} +
+{% if links %} + +{% endif %} + +{% if can_edit_book %} +{% include 'book/file_link_modal.html' with book=book id="edit-links" %} +{% endif %} diff --git a/bookwyrm/templatetags/bookwyrm_tags.py b/bookwyrm/templatetags/bookwyrm_tags.py index f24219d2..c6781f5a 100644 --- a/bookwyrm/templatetags/bookwyrm_tags.py +++ b/bookwyrm/templatetags/bookwyrm_tags.py @@ -177,3 +177,9 @@ def suggested_books(context): # this happens here instead of in the view so that the template snippet can # be cached in the template return get_suggested_books(context["request"].user) + + +@register.simple_tag(takes_context=False) +def get_book_file_links(book): + """links for a book""" + return book.file_links.filter(domain__status="approved") diff --git a/bookwyrm/tests/views/books/test_links.py b/bookwyrm/tests/views/books/test_links.py index 136a7606..1214e0e2 100644 --- a/bookwyrm/tests/views/books/test_links.py +++ b/bookwyrm/tests/views/books/test_links.py @@ -63,7 +63,6 @@ class LinkViews(TestCase): """there are so many views, this just makes sure it LOADS""" view = views.FileLink.as_view() form = forms.FileLinkForm() - form.data["name"] = "hi" form.data["url"] = "https://www.example.com" form.data["filetype"] = "HTML" form.data["book"] = self.book.id @@ -81,7 +80,7 @@ class LinkViews(TestCase): self.assertEqual(activity["object"]["type"], "Edition") link = models.FileLink.objects.get() - self.assertEqual(link.name, "hi") + self.assertEqual(link.name, "www.example.com") self.assertEqual(link.url, "https://www.example.com") self.assertEqual(link.filetype, "HTML")