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,9 +190,7 @@ 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
|
# save book
|
||||||
book = form.save()
|
book = form.save()
|
||||||
|
|
||||||
|
@ -206,8 +204,18 @@ class ConfirmEditBook(View):
|
||||||
name=request.POST.get('add_author'))
|
name=request.POST.get('add_author'))
|
||||||
book.authors.add(author)
|
book.authors.add(author)
|
||||||
|
|
||||||
remove_authors = request.POST.getlist('remove_authors')
|
# create work, if needed
|
||||||
for author_id in remove_authors:
|
if not book_id:
|
||||||
|
work_match = request.POST.get('parent_work')
|
||||||
|
if work_match:
|
||||||
|
work = get_object_or_404(models.Work, id=work_match)
|
||||||
|
else:
|
||||||
|
work = models.Work.objects.create(title=form.cleaned_data.title)
|
||||||
|
work.authors.set(book.authors.all())
|
||||||
|
book.parent_work = work
|
||||||
|
book.save()
|
||||||
|
|
||||||
|
for author_id in request.POST.getlist('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