Only show approved links
This commit is contained in:
parent
70fe7e17af
commit
aa9864a21e
|
@ -82,7 +82,7 @@ class Migration(migrations.Migration):
|
||||||
models.ForeignKey(
|
models.ForeignKey(
|
||||||
blank=True,
|
blank=True,
|
||||||
null=True,
|
null=True,
|
||||||
on_delete=django.db.models.deletion.PROTECT,
|
on_delete=django.db.models.deletion.CASCADE,
|
||||||
to="bookwyrm.linkdomain",
|
to="bookwyrm.linkdomain",
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
@ -15,7 +15,7 @@ class Link(ActivitypubMixin, BookWyrmModel):
|
||||||
|
|
||||||
url = fields.URLField(max_length=255, activitypub_field="href")
|
url = fields.URLField(max_length=255, activitypub_field="href")
|
||||||
domain = models.ForeignKey(
|
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
|
activity_serializer = activitypub.Link
|
||||||
|
|
|
@ -383,37 +383,7 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<section class="content block">
|
<section class="content block">
|
||||||
<header class="columns is-mobile mb-0">
|
{% include "book/links.html" %}
|
||||||
<div class="column">
|
|
||||||
<h2 class="title is-5">{% trans "Get a copy" %}</h2>
|
|
||||||
</div>
|
|
||||||
{% if can_edit_book %}
|
|
||||||
<div class="column is-narrow">
|
|
||||||
{% url 'file-link' book.id as fallback_url %}
|
|
||||||
<button class="button is-small" type="button" data-modal-open="edit-links">
|
|
||||||
<span class="icon icon-plus">
|
|
||||||
<span class="is-sr-only">
|
|
||||||
{% trans "Add link to copy" %}
|
|
||||||
</span>
|
|
||||||
</span>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
</header>
|
|
||||||
{% if book.file_links %}
|
|
||||||
<ul class="mt-0">
|
|
||||||
{% for link in book.file_links.all %}
|
|
||||||
<li>
|
|
||||||
<a href="{{ link.url }}" rel="noopener" target="_blank" title="{{ link.url }}">{{ link.name }}</a>
|
|
||||||
({{ link.filetype }})
|
|
||||||
</li>
|
|
||||||
{% endfor %}
|
|
||||||
</ul>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if can_edit_book %}
|
|
||||||
{% include 'book/file_link_modal.html' with book=book id="edit-links" %}
|
|
||||||
{% endif %}
|
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
{% load i18n %}
|
||||||
|
{% load bookwyrm_tags %}
|
||||||
|
{% get_book_file_links book as links %}
|
||||||
|
<header class="columns is-mobile mb-0">
|
||||||
|
<div class="column">
|
||||||
|
<h2 class="title is-5">{% trans "Get a copy" %}</h2>
|
||||||
|
</div>
|
||||||
|
{% if can_edit_book %}
|
||||||
|
<div class="column is-narrow">
|
||||||
|
{% url 'file-link' book.id as fallback_url %}
|
||||||
|
<button class="button is-small" type="button" data-modal-open="edit-links">
|
||||||
|
<span class="icon icon-plus">
|
||||||
|
<span class="is-sr-only">
|
||||||
|
{% trans "Add link to copy" %}
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</header>
|
||||||
|
{% if links %}
|
||||||
|
<ul class="mt-0">
|
||||||
|
{% for link in links.all %}
|
||||||
|
<li>
|
||||||
|
<a href="{{ link.url }}" rel="noopener" target="_blank" title="{{ link.url }}">{{ link.name }}</a>
|
||||||
|
({{ link.filetype }})
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if can_edit_book %}
|
||||||
|
{% include 'book/file_link_modal.html' with book=book id="edit-links" %}
|
||||||
|
{% endif %}
|
|
@ -177,3 +177,9 @@ def suggested_books(context):
|
||||||
# this happens here instead of in the view so that the template snippet can
|
# this happens here instead of in the view so that the template snippet can
|
||||||
# be cached in the template
|
# be cached in the template
|
||||||
return get_suggested_books(context["request"].user)
|
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")
|
||||||
|
|
|
@ -63,7 +63,6 @@ class LinkViews(TestCase):
|
||||||
"""there are so many views, this just makes sure it LOADS"""
|
"""there are so many views, this just makes sure it LOADS"""
|
||||||
view = views.FileLink.as_view()
|
view = views.FileLink.as_view()
|
||||||
form = forms.FileLinkForm()
|
form = forms.FileLinkForm()
|
||||||
form.data["name"] = "hi"
|
|
||||||
form.data["url"] = "https://www.example.com"
|
form.data["url"] = "https://www.example.com"
|
||||||
form.data["filetype"] = "HTML"
|
form.data["filetype"] = "HTML"
|
||||||
form.data["book"] = self.book.id
|
form.data["book"] = self.book.id
|
||||||
|
@ -81,7 +80,7 @@ class LinkViews(TestCase):
|
||||||
self.assertEqual(activity["object"]["type"], "Edition")
|
self.assertEqual(activity["object"]["type"], "Edition")
|
||||||
|
|
||||||
link = models.FileLink.objects.get()
|
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.url, "https://www.example.com")
|
||||||
self.assertEqual(link.filetype, "HTML")
|
self.assertEqual(link.filetype, "HTML")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue