Edit links view

This commit is contained in:
Mouse Reeve 2022-01-12 09:52:26 -08:00
parent 2ca41a0b11
commit ebc451fdd2
8 changed files with 100 additions and 11 deletions

View file

@ -0,0 +1,69 @@
{% extends 'layout.html' %}
{% load i18n %}
{% load utilities %}
{% block title %}{% trans "Edit links" %}{% endblock %}
{% block content %}
<header class="block content">
<h1 class="title">
{% blocktrans with title=book|book_title %}
Links for "<em>{{ title }}</em>"
{% endblocktrans %}
</h1>
</header>
<nav class="breadcrumb subtitle" aria-label="breadcrumbs">
<ul>
<li><a href="{% url 'book' book.id %}">{{ book|book_title }}</a></li>
<li class="is-active">
<a href="#" aria-current="page">
{% trans "Edit links" %}
</a>
</li>
</ul>
</nav>
<section class="block content">
<div class="table-container">
<table class="is-striped is-fullwidth">
<tr>
<th>{% trans "URL" %}</th>
<th>{% trans "Added by" %}</th>
<th>{% trans "Filetype" %}</th>
<th>{% trans "Domain" %}</th>
<th>{% trans "Actions" %}</th>
</tr>
{% for link in book.file_links.all %}
<tr>
<td class="overflow-wrap-anywhere">
<a href="{{ link.url }}" target="_blank" rel="noopener">{{ link.url }}</a>
</td>
<td>
<a href="{% url 'user-feed' link.added_by.id %}">{{ link.added_by.display_name }}</a>
</td>
<td>
{{ link.filelink.filetype }}
</td>
<td>
{{ link.domain.name }} ({{ link.domain.get_status_display }})
<p>
<a href="{% url 'report-link' link.added_by.id link.id %}">{% trans "Report spam" %}</a>
</p>
</td>
<td>
<button class="button is-danger is-light">Delete link</button>
</td>
</tr>
{% endfor %}
{% if not book.file_links.exists %}
<tr>
<td colspan="5"><em>{% trans "No links available for this book." %}</em></td>
</tr>
{% endif %}
</table>
</div>
</section>
{% endblock %}

View file

@ -6,7 +6,7 @@
{% endblock %}
{% block modal-form-open %}
<form name="add-link" method="POST" action="{% url 'file-link' book.id %}">
<form name="add-link" method="POST" action="{% url 'file-link-add' book.id %}">
{% endblock %}
{% block modal-body %}

View file

@ -22,7 +22,7 @@ Is that where you'd like to go?
{% if request.user.is_authenticated %}
<div class="has-text-right is-flex-grow-1">
<a href="{% url 'report-link' link.added_by.id link.id %}">{% trans "Report spam" %}</button>
<a href="{% url 'report-link' link.added_by.id link.id %}">{% trans "Report spam" %}</a>
</div>
{% endif %}

View file

@ -10,8 +10,8 @@
</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">
{% url 'file-link-add' book.id as fallback_url %}
<button class="button is-small" type="button" data-modal-open="add-links">
<span class="icon icon-plus">
<span class="is-sr-only">
{% trans "Add link to copy" %}
@ -39,8 +39,12 @@
<em>{% trans "No links available" %}</em>
{% endif %}
{% if can_edit_book %}
{% include 'book/file_link_modal.html' with book=book id="edit-links" %}
{% if can_edit_book and links.exists %}
<a href="{% url 'file-link' book.id %}" class="is-pulled-right">
<span class="icon icon-pencil" aria-hidden="true"></span>
<span>{% trans "Edit links" %}</span>
</a>
{% include 'book/file_link_modal.html' with book=book id="add-links" %}
{% endif %}
{% endif %}

View file

@ -1,7 +1,7 @@
{% load i18n %}
{% load utilities %}
<table class="is-striped">
<table class="is-striped is-fullwidth">
<tr>
<th>{% trans "URL" %}</th>
<th>{% trans "Added by" %}</th>
@ -9,7 +9,7 @@
<th>{% trans "Book" %}</th>
{% block additional_headers %}{% endblock %}
</tr>
{% for link in links%}
{% for link in links %}
<tr>
<td class="overflow-wrap-anywhere">
<a href="{{ link.url }}" target="_blank" rel="noopener">{{ link.url }}</a>
@ -24,13 +24,19 @@
</td>
<td>
{% if link.filelink.filetype %}
{% if link.filelink.book %}
{% with book=link.filelink.book %}
<a href="{{ book.local_path }}">{% include "snippets/book_titleby.html" with book=book %}</a>
{% endwith %}
{% endif %}
</td>
{% block additional_data %}{% endblock %}
</tr>
{% endfor %}
{% if not links %}
<tr>
<td colspan="7"><em>{% trans "No links available for this domain." %}</em></td>
</tr>
{% endif %}
</table>

View file

@ -469,7 +469,8 @@ urlpatterns = [
views.add_description,
name="add-description",
),
re_path(rf"{BOOK_PATH}/filelink/?$", views.AddFileLink.as_view(), name="file-link"),
re_path(rf"{BOOK_PATH}/filelink/?$", views.BookFileLinks.as_view(), name="file-link"),
re_path(rf"{BOOK_PATH}/filelink/add/?$", views.AddFileLink.as_view(), name="file-link-add"),
re_path(r"^resolve-book/?$", views.resolve_book, name="resolve-book"),
re_path(r"^switch-edition/?$", views.switch_edition, name="switch-edition"),
re_path(

View file

@ -37,7 +37,7 @@ from .books.books import (
from .books.books import update_book_from_remote
from .books.edit_book import EditBook, ConfirmEditBook
from .books.editions import Editions, switch_edition
from .books.links import AddFileLink
from .books.links import BookFileLinks, AddFileLink
# landing
from .landing.about import about, privacy, conduct

View file

@ -10,6 +10,15 @@ from bookwyrm import forms, models
# pylint: disable=no-self-use
class BookFileLinks(View):
"""View all links"""
def get(self, request, book_id):
"""view links"""
book = get_object_or_404(models.Edition, id=book_id)
return TemplateResponse(request, "book/edit_links.html", {"book": book})
@method_decorator(login_required, name="dispatch")
@method_decorator(
permission_required("bookwyrm.edit_book", raise_exception=True), name="dispatch"