mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2025-02-02 04:12:20 +00:00
Edit book availability
This commit is contained in:
parent
1595bac9b5
commit
cfcacb4797
4 changed files with 55 additions and 10 deletions
|
@ -34,9 +34,9 @@
|
||||||
<th>{% trans "Filetype" %}</th>
|
<th>{% trans "Filetype" %}</th>
|
||||||
<th>{% trans "Domain" %}</th>
|
<th>{% trans "Domain" %}</th>
|
||||||
<th>{% trans "Status" %}</th>
|
<th>{% trans "Status" %}</th>
|
||||||
<th>{% trans "Actions" %}</th>
|
<th colspan="2">{% trans "Actions" %}</th>
|
||||||
</tr>
|
</tr>
|
||||||
{% for link in book.file_links.all %}
|
{% for link in links %}
|
||||||
<tr>
|
<tr>
|
||||||
<td class="overflow-wrap-anywhere">
|
<td class="overflow-wrap-anywhere">
|
||||||
<a href="{{ link.url }}" target="_blank" rel="noopener">{{ link.url }}</a>
|
<a href="{{ link.url }}" target="_blank" rel="noopener">{{ link.url }}</a>
|
||||||
|
@ -66,7 +66,26 @@
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<form name="delete-link-{{ link.id }}" class="control" method="post" action="{% url 'file-link' book.id link.id %}">
|
<form name="edit-link" class="control" method="post" action="{% url 'file-link' book.id link.id %}">
|
||||||
|
{% csrf_token %}
|
||||||
|
<input type="hidden" name="url" value="{{ link.form.url.value }}">
|
||||||
|
<input type="hidden" name="filetype" value="{{ link.form.filetype.value }}">
|
||||||
|
<input type="hidden" name="added_by" value="{{ link.form.added_by.value }}">
|
||||||
|
<input type="hidden" name="book" value="{{ link.form.book.value }}">
|
||||||
|
<div class="field has-addons">
|
||||||
|
<div class="control">
|
||||||
|
<div class="select">
|
||||||
|
{{ link.form.availability }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="control">
|
||||||
|
<button class="button is-primary" type="submit">{% trans "Save" %}</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<form name="delete-link-{{ link.id }}" class="control" method="post" action="{% url 'file-link-delete' book.id link.id %}">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<button class="button is-danger is-light" type="submit">Delete link</button>
|
<button class="button is-danger is-light" type="submit">Delete link</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -473,10 +473,15 @@ urlpatterns = [
|
||||||
rf"{BOOK_PATH}/filelink/?$", views.BookFileLinks.as_view(), name="file-link"
|
rf"{BOOK_PATH}/filelink/?$", views.BookFileLinks.as_view(), name="file-link"
|
||||||
),
|
),
|
||||||
re_path(
|
re_path(
|
||||||
rf"{BOOK_PATH}/filelink/(?P<link_id>\d+)/delete/?$",
|
rf"{BOOK_PATH}/filelink/(?P<link_id>\d+)/?$",
|
||||||
views.BookFileLinks.as_view(),
|
views.BookFileLinks.as_view(),
|
||||||
name="file-link",
|
name="file-link",
|
||||||
),
|
),
|
||||||
|
re_path(
|
||||||
|
rf"{BOOK_PATH}/filelink/(?P<link_id>\d+)/delete/?$",
|
||||||
|
views.delete_link,
|
||||||
|
name="file-link-delete",
|
||||||
|
),
|
||||||
re_path(
|
re_path(
|
||||||
rf"{BOOK_PATH}/filelink/add/?$",
|
rf"{BOOK_PATH}/filelink/add/?$",
|
||||||
views.AddFileLink.as_view(),
|
views.AddFileLink.as_view(),
|
||||||
|
|
|
@ -37,7 +37,7 @@ from .books.books import (
|
||||||
from .books.books import update_book_from_remote
|
from .books.books import update_book_from_remote
|
||||||
from .books.edit_book import EditBook, ConfirmEditBook
|
from .books.edit_book import EditBook, ConfirmEditBook
|
||||||
from .books.editions import Editions, switch_edition
|
from .books.editions import Editions, switch_edition
|
||||||
from .books.links import BookFileLinks, AddFileLink
|
from .books.links import BookFileLinks, AddFileLink, delete_link
|
||||||
|
|
||||||
# landing
|
# landing
|
||||||
from .landing.about import about, privacy, conduct
|
from .landing.about import about, privacy, conduct
|
||||||
|
|
|
@ -5,28 +5,49 @@ from django.shortcuts import get_object_or_404, redirect
|
||||||
from django.template.response import TemplateResponse
|
from django.template.response import TemplateResponse
|
||||||
from django.views import View
|
from django.views import View
|
||||||
from django.utils.decorators import method_decorator
|
from django.utils.decorators import method_decorator
|
||||||
|
from django.views.decorators.http import require_POST
|
||||||
|
|
||||||
from bookwyrm import forms, models
|
from bookwyrm import forms, models
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=no-self-use
|
# pylint: disable=no-self-use
|
||||||
|
@method_decorator(login_required, name="dispatch")
|
||||||
|
@method_decorator(
|
||||||
|
permission_required("bookwyrm.edit_book", raise_exception=True), name="dispatch"
|
||||||
|
)
|
||||||
class BookFileLinks(View):
|
class BookFileLinks(View):
|
||||||
"""View all links"""
|
"""View all links"""
|
||||||
|
|
||||||
def get(self, request, book_id):
|
def get(self, request, book_id):
|
||||||
"""view links"""
|
"""view links"""
|
||||||
book = get_object_or_404(models.Edition, id=book_id)
|
book = get_object_or_404(models.Edition, id=book_id)
|
||||||
return TemplateResponse(
|
links = book.file_links.order_by("domain__status", "created_date")
|
||||||
request, "book/file_links/edit_links.html", {"book": book}
|
annotated_links = []
|
||||||
)
|
for link in links.all():
|
||||||
|
link.form = forms.FileLinkForm(instance=link)
|
||||||
|
annotated_links.append(link)
|
||||||
|
|
||||||
|
data = {"book": book, "links": annotated_links}
|
||||||
|
return TemplateResponse(request, "book/file_links/edit_links.html", data)
|
||||||
|
|
||||||
def post(self, request, book_id, link_id):
|
def post(self, request, book_id, link_id):
|
||||||
"""delete link"""
|
"""Edit a link"""
|
||||||
link = get_object_or_404(models.FileLink, id=link_id, book=book_id)
|
link = get_object_or_404(models.FileLink, id=link_id, book=book_id)
|
||||||
link.delete()
|
form = forms.FileLinkForm(request.POST, instance=link)
|
||||||
|
form.save()
|
||||||
return self.get(request, book_id)
|
return self.get(request, book_id)
|
||||||
|
|
||||||
|
|
||||||
|
@require_POST
|
||||||
|
@login_required
|
||||||
|
# pylint: disable=unused-argument
|
||||||
|
def delete_link(request, book_id, link_id):
|
||||||
|
"""delete link"""
|
||||||
|
link = get_object_or_404(models.FileLink, id=link_id, book=book_id)
|
||||||
|
link.delete()
|
||||||
|
return redirect("file-link", book_id)
|
||||||
|
|
||||||
|
|
||||||
@method_decorator(login_required, name="dispatch")
|
@method_decorator(login_required, name="dispatch")
|
||||||
@method_decorator(
|
@method_decorator(
|
||||||
permission_required("bookwyrm.edit_book", raise_exception=True), name="dispatch"
|
permission_required("bookwyrm.edit_book", raise_exception=True), name="dispatch"
|
||||||
|
|
Loading…
Reference in a new issue