Merge metadata of uploaded book versions.

pull/1099/head
Christian Keil 5 years ago
parent fda0ab1e86
commit c61463447f

@ -360,6 +360,9 @@ def upload_single_file(request, book, book_id):
worker.add_upload(current_user.nickname, worker.add_upload(current_user.nickname,
"<a href=\"" + url_for('web.show_book', book_id=book.id) + "\">" + uploadText + "</a>") "<a href=\"" + url_for('web.show_book', book_id=book.id) + "\">" + uploadText + "</a>")
return uploader.process(
saved_filename, *os.path.splitext(requested_file.filename))
def upload_cover(request, book): def upload_cover(request, book):
if 'btn-upload-cover' in request.files: if 'btn-upload-cover' in request.files:
@ -393,11 +396,12 @@ def edit_book(book_id):
flash(_(u"Error opening eBook. File does not exist or file is not accessible"), category="error") flash(_(u"Error opening eBook. File does not exist or file is not accessible"), category="error")
return redirect(url_for("web.index")) return redirect(url_for("web.index"))
upload_single_file(request, book, book_id) meta = upload_single_file(request, book, book_id)
if upload_cover(request, book) is True: if upload_cover(request, book) is True:
book.has_cover = 1 book.has_cover = 1
try: try:
to_save = request.form.to_dict() to_save = request.form.to_dict()
merge_metadata(to_save, meta)
# Update book # Update book
edited_books_id = None edited_books_id = None
#handle book title #handle book title
@ -531,6 +535,20 @@ def edit_book(book_id):
return redirect(url_for('web.show_book', book_id=book.id)) return redirect(url_for('web.show_book', book_id=book.id))
def merge_metadata(to_save, meta):
if to_save['author_name'].lower() == _(u'unknown'):
to_save['author_name'] = ''
if to_save['book_title'].lower() == _(u'unknown'):
to_save['book_title'] = ''
for s_field, m_field in [
('tags', 'tags'), ('author_name', 'author'), ('series', 'series'),
('series_index', 'series_id'), ('languages', 'languages'),
('book_title', 'title')]:
to_save[s_field] = to_save[s_field] or getattr(meta, m_field, '')
to_save["description"] = to_save["description"] or Markup(
getattr(meta, 'description', '')).unescape()
@editbook.route("/upload", methods=["GET", "POST"]) @editbook.route("/upload", methods=["GET", "POST"])
@login_required_if_no_ano @login_required_if_no_ano
@upload_required @upload_required

Loading…
Cancel
Save