Python formatting
This commit is contained in:
parent
b001c31f97
commit
29a6d74ff2
|
@ -287,6 +287,7 @@ class EditionFromWorkForm(CustomForm):
|
||||||
"first_published_date",
|
"first_published_date",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class EditionForm(CustomForm):
|
class EditionForm(CustomForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = models.Edition
|
model = models.Edition
|
||||||
|
|
|
@ -496,7 +496,9 @@ urlpatterns = [
|
||||||
),
|
),
|
||||||
re_path(rf"{BOOK_PATH}/edit/?$", views.EditBook.as_view(), name="edit-book"),
|
re_path(rf"{BOOK_PATH}/edit/?$", views.EditBook.as_view(), name="edit-book"),
|
||||||
re_path(rf"{BOOK_PATH}/confirm/?$", views.ConfirmEditBook.as_view()),
|
re_path(rf"{BOOK_PATH}/confirm/?$", views.ConfirmEditBook.as_view()),
|
||||||
re_path(r"^create-book/data/?$", views.create_book_from_data, name="create-book-data"),
|
re_path(
|
||||||
|
r"^create-book/data/?$", views.create_book_from_data, name="create-book-data"
|
||||||
|
),
|
||||||
re_path(r"^create-book/?$", views.CreateBook.as_view(), name="create-book"),
|
re_path(r"^create-book/?$", views.CreateBook.as_view(), name="create-book"),
|
||||||
re_path(r"^create-book/confirm/?$", views.ConfirmEditBook.as_view()),
|
re_path(r"^create-book/confirm/?$", views.ConfirmEditBook.as_view()),
|
||||||
re_path(rf"{BOOK_PATH}/editions(.json)?/?$", views.Editions.as_view()),
|
re_path(rf"{BOOK_PATH}/editions(.json)?/?$", views.Editions.as_view()),
|
||||||
|
|
|
@ -37,7 +37,12 @@ from .books.books import (
|
||||||
resolve_book,
|
resolve_book,
|
||||||
)
|
)
|
||||||
from .books.books import update_book_from_remote
|
from .books.books import update_book_from_remote
|
||||||
from .books.edit_book import EditBook, ConfirmEditBook, CreateBook, create_book_from_data
|
from .books.edit_book import (
|
||||||
|
EditBook,
|
||||||
|
ConfirmEditBook,
|
||||||
|
CreateBook,
|
||||||
|
create_book_from_data,
|
||||||
|
)
|
||||||
from .books.editions import Editions, switch_edition
|
from .books.editions import Editions, switch_edition
|
||||||
from .books.links import BookFileLinks, AddFileLink, delete_link
|
from .books.links import BookFileLinks, AddFileLink, delete_link
|
||||||
|
|
||||||
|
|
|
@ -157,9 +157,7 @@ class CreateBook(View):
|
||||||
if request.POST.get("authors"):
|
if request.POST.get("authors"):
|
||||||
author_ids = findall(r"\d+", request.POST["authors"])
|
author_ids = findall(r"\d+", request.POST["authors"])
|
||||||
# django can't parse the authors form element
|
# django can't parse the authors form element
|
||||||
book.authors.add(
|
book.authors.add(*models.Author.objects.filter(id__in=author_ids))
|
||||||
*models.Author.objects.filter(id__in=author_ids)
|
|
||||||
)
|
|
||||||
|
|
||||||
url = request.POST.get("cover-url")
|
url = request.POST.get("cover-url")
|
||||||
if url:
|
if url:
|
||||||
|
@ -169,6 +167,7 @@ class CreateBook(View):
|
||||||
book.save()
|
book.save()
|
||||||
return redirect(f"/book/{book.id}")
|
return redirect(f"/book/{book.id}")
|
||||||
|
|
||||||
|
|
||||||
def add_authors(request, data):
|
def add_authors(request, data):
|
||||||
"""helper for adding authors"""
|
"""helper for adding authors"""
|
||||||
add_author = [author for author in request.POST.getlist("add_author") if author]
|
add_author = [author for author in request.POST.getlist("add_author") if author]
|
||||||
|
@ -184,9 +183,7 @@ def add_authors(request, data):
|
||||||
if not author:
|
if not author:
|
||||||
continue
|
continue
|
||||||
# check for existing authors
|
# check for existing authors
|
||||||
vector = SearchVector("name", weight="A") + SearchVector(
|
vector = SearchVector("name", weight="A") + SearchVector("aliases", weight="B")
|
||||||
"aliases", weight="B"
|
|
||||||
)
|
|
||||||
|
|
||||||
author_matches = (
|
author_matches = (
|
||||||
models.Author.objects.annotate(search=vector)
|
models.Author.objects.annotate(search=vector)
|
||||||
|
@ -229,9 +226,7 @@ def create_book_from_data(request):
|
||||||
author_ids = findall(r"\d+", request.POST.get("authors"))
|
author_ids = findall(r"\d+", request.POST.get("authors"))
|
||||||
book = {
|
book = {
|
||||||
"parent_work": {"id": request.POST.get("parent_work")},
|
"parent_work": {"id": request.POST.get("parent_work")},
|
||||||
"authors": models.Author.objects.filter(
|
"authors": models.Author.objects.filter(id__in=author_ids).all(),
|
||||||
id__in=author_ids
|
|
||||||
).all(),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data = {"book": book, "form": forms.EditionForm(request.POST)}
|
data = {"book": book, "form": forms.EditionForm(request.POST)}
|
||||||
|
|
Loading…
Reference in New Issue