forked from mirrors/bookwyrm
Create new books
This commit is contained in:
parent
d3162e12db
commit
a5baa1f5c6
5 changed files with 39 additions and 23 deletions
|
@ -134,7 +134,7 @@ class EditionForm(CustomForm):
|
||||||
'updated_date',
|
'updated_date',
|
||||||
'edition_rank',
|
'edition_rank',
|
||||||
|
|
||||||
'authors',# TODO
|
'authors',
|
||||||
'parent_work',
|
'parent_work',
|
||||||
'shelves',
|
'shelves',
|
||||||
|
|
||||||
|
|
|
@ -13,11 +13,13 @@
|
||||||
{% trans "Add Book" %}
|
{% trans "Add Book" %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</h1>
|
</h1>
|
||||||
|
{% if book %}
|
||||||
<div>
|
<div>
|
||||||
<p>{% trans "Added:" %} {{ book.created_date | naturaltime }}</p>
|
<p>{% trans "Added:" %} {{ book.created_date | naturaltime }}</p>
|
||||||
<p>{% trans "Updated:" %} {{ book.updated_date | naturaltime }}</p>
|
<p>{% trans "Updated:" %} {{ book.updated_date | naturaltime }}</p>
|
||||||
<p>{% trans "Last edited by:" %} <a href="{{ book.last_edited_by.remote_id }}">{{ book.last_edited_by.display_name }}</a></p>
|
<p>{% trans "Last edited by:" %} <a href="{{ book.last_edited_by.remote_id }}">{{ book.last_edited_by.display_name }}</a></p>
|
||||||
</div>
|
</div>
|
||||||
|
{% endif %}
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
{% if form.non_field_errors %}
|
{% if form.non_field_errors %}
|
||||||
|
@ -26,7 +28,12 @@
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if book %}
|
||||||
<form class="block" name="edit-book" action="{{ book.local_path }}/{% if confirm_mode %}confirm{% else %}edit{% endif %}" method="post" enctype="multipart/form-data">
|
<form class="block" name="edit-book" action="{{ book.local_path }}/{% if confirm_mode %}confirm{% else %}edit{% endif %}" method="post" enctype="multipart/form-data">
|
||||||
|
{% else %}
|
||||||
|
<form class="block" name="create-book" action="/create-book{% if confirm_mode %}/confirm{% endif %}" method="post" enctype="multipart/form-data">
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{% if confirm_mode %}
|
{% if confirm_mode %}
|
||||||
<div class="box">
|
<div class="box">
|
||||||
|
@ -111,12 +118,8 @@
|
||||||
</label>
|
</label>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</fieldset>
|
</fieldset>
|
||||||
{% if confirm_mode %}
|
|
||||||
<input type="hidden" name="add_author" value="{{ add_author }}">
|
|
||||||
{% else %}
|
|
||||||
<label class="label" for="id_add_author">{% trans "Add Author:" %}</label>
|
<label class="label" for="id_add_author">{% trans "Add Author:" %}</label>
|
||||||
<input class="input" type="text" name="add_author" id="id_add_author" placeholder="{% trans 'John Doe' %}" value="{{ add_author }}">
|
<input class="input" type="text" name="add_author" id="id_add_author" placeholder="{% trans 'John Doe' %}" value="{{ add_author }}">
|
||||||
{% endif %}
|
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -68,6 +68,10 @@
|
||||||
{% include 'snippets/toggle/close_button.html' with text=button_text small=True controls_text="more-results" %}
|
{% include 'snippets/toggle/close_button.html' with text=button_text small=True controls_text="more-results" %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="block">
|
||||||
|
<a href="/create-book">Manually add book</a>
|
||||||
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<div class="column">
|
<div class="column">
|
||||||
|
|
|
@ -130,12 +130,13 @@ urlpatterns = [
|
||||||
re_path(r'%s(.json)?/?$' % book_path, views.Book.as_view()),
|
re_path(r'%s(.json)?/?$' % book_path, views.Book.as_view()),
|
||||||
re_path(r'%s/edit/?$' % book_path, views.EditBook.as_view()),
|
re_path(r'%s/edit/?$' % book_path, views.EditBook.as_view()),
|
||||||
re_path(r'%s/confirm/?$' % book_path, views.ConfirmEditBook.as_view()),
|
re_path(r'%s/confirm/?$' % book_path, views.ConfirmEditBook.as_view()),
|
||||||
|
re_path(r'^create-book/?$', views.EditBook.as_view()),
|
||||||
|
re_path(r'^create-book/confirm?$', views.ConfirmEditBook.as_view()),
|
||||||
re_path(r'%s/editions(.json)?/?$' % book_path, views.Editions.as_view()),
|
re_path(r'%s/editions(.json)?/?$' % book_path, views.Editions.as_view()),
|
||||||
re_path(r'^upload-cover/(?P<book_id>\d+)/?$', views.upload_cover),
|
re_path(r'^upload-cover/(?P<book_id>\d+)/?$', views.upload_cover),
|
||||||
re_path(r'^add-description/(?P<book_id>\d+)/?$', views.add_description),
|
re_path(r'^add-description/(?P<book_id>\d+)/?$', views.add_description),
|
||||||
re_path(r'^resolve-book/?$', views.resolve_book),
|
re_path(r'^resolve-book/?$', views.resolve_book),
|
||||||
re_path(r'^switch-edition/?$', views.switch_edition),
|
re_path(r'^switch-edition/?$', views.switch_edition),
|
||||||
re_path(r'^create-book/?$', views.EditBook.as_view()),
|
|
||||||
|
|
||||||
# isbn
|
# isbn
|
||||||
re_path(r'^isbn/(?P<isbn>\d+)(.json)?/?$', views.Isbn.as_view()),
|
re_path(r'^isbn/(?P<isbn>\d+)(.json)?/?$', views.Isbn.as_view()),
|
||||||
|
|
|
@ -145,7 +145,7 @@ class EditBook(View):
|
||||||
search=vector
|
search=vector
|
||||||
).annotate(
|
).annotate(
|
||||||
rank=SearchRank(vector, add_author)
|
rank=SearchRank(vector, add_author)
|
||||||
).filter(rank__gt=0.8).order_by('-rank')[:5]
|
).filter(rank__gt=0.4).order_by('-rank')[:5]
|
||||||
|
|
||||||
# we're creating a new book
|
# we're creating a new book
|
||||||
if not book:
|
if not book:
|
||||||
|
@ -190,25 +190,33 @@ class ConfirmEditBook(View):
|
||||||
if not form.is_valid():
|
if not form.is_valid():
|
||||||
return TemplateResponse(request, 'edit_book.html', data)
|
return TemplateResponse(request, 'edit_book.html', data)
|
||||||
|
|
||||||
# create work, if needed
|
with transaction.atomic():
|
||||||
# TODO
|
# save book
|
||||||
|
book = form.save()
|
||||||
|
|
||||||
# save book
|
# get or create author as needed
|
||||||
book = form.save()
|
if request.POST.get('add_author'):
|
||||||
|
if request.POST.get('author_match'):
|
||||||
|
author = get_object_or_404(
|
||||||
|
models.Author, id=request.POST['author_match'])
|
||||||
|
else:
|
||||||
|
author = models.Author.objects.create(
|
||||||
|
name=request.POST.get('add_author'))
|
||||||
|
book.authors.add(author)
|
||||||
|
|
||||||
# get or create author as needed
|
# create work, if needed
|
||||||
if request.POST.get('add_author'):
|
if not book_id:
|
||||||
if request.POST.get('author_match'):
|
work_match = request.POST.get('parent_work')
|
||||||
author = get_object_or_404(
|
if work_match:
|
||||||
models.Author, id=request.POST['author_match'])
|
work = get_object_or_404(models.Work, id=work_match)
|
||||||
else:
|
else:
|
||||||
author = models.Author.objects.create(
|
work = models.Work.objects.create(title=form.cleaned_data.title)
|
||||||
name=request.POST.get('add_author'))
|
work.authors.set(book.authors.all())
|
||||||
book.authors.add(author)
|
book.parent_work = work
|
||||||
|
book.save()
|
||||||
|
|
||||||
remove_authors = request.POST.getlist('remove_authors')
|
for author_id in request.POST.getlist('remove_authors'):
|
||||||
for author_id in remove_authors:
|
book.authors.remove(author_id)
|
||||||
book.authors.remove(author_id)
|
|
||||||
|
|
||||||
return redirect('/book/%s' % book.id)
|
return redirect('/book/%s' % book.id)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue