Merge remote-tracking branch 'image_formats/dev'

This commit is contained in:
Ozzieisaacs
2019-04-15 20:57:25 +02:00
5 changed files with 113 additions and 42 deletions
+12 -25
View File
@@ -3558,33 +3558,19 @@ def upload_single_file(request, book, book_id):
helper.global_WorkerThread.add_upload(current_user.nickname,
"<a href=\"" + url_for('show_book', book_id=book.id) + "\">" + uploadText + "</a>")
def upload_cover(request, book):
if 'btn-upload-cover' in request.files:
requested_file = request.files['btn-upload-cover']
# check for empty request
if requested_file.filename != '':
file_ext = requested_file.filename.rsplit('.', 1)[-1].lower()
filepath = os.path.normpath(os.path.join(config.config_calibre_dir, book.path))
saved_filename = os.path.join(filepath, 'cover.' + file_ext)
# check if file path exists, otherwise create it, copy file to calibre path and delete temp file
if not os.path.exists(filepath):
try:
os.makedirs(filepath)
except OSError:
flash(_(u"Failed to create path for cover %(path)s (Permission denied).", cover=filepath),
category="error")
return redirect(url_for('show_book', book_id=book.id))
try:
requested_file.save(saved_filename)
# im=Image.open(saved_filename)
book.has_cover = 1
except OSError:
flash(_(u"Failed to store cover-file %(cover)s.", cover=saved_filename), category="error")
return redirect(url_for('show_book', book_id=book.id))
except IOError:
flash(_(u"Cover-file is not a valid image file" % saved_filename), category="error")
return redirect(url_for('show_book', book_id=book.id))
if helper.save_cover(requested_file, book.path) is True:
return True
else:
# ToDo Message not always coorect
flash(_(u"Cover is not a supported imageformat (jpg/png/webp), can't save"), category="error")
return False
return None
@app.route("/admin/book/<int:book_id>", methods=['GET', 'POST'])
@login_required_if_no_ano
@@ -3605,7 +3591,8 @@ def edit_book(book_id):
return redirect(url_for("index"))
upload_single_file(request, book, book_id)
upload_cover(request, book)
if upload_cover(request, book) is True:
book.has_cover = 1
try:
to_save = request.form.to_dict()
# Update book
@@ -3651,10 +3638,10 @@ def edit_book(book_id):
if not error:
if to_save["cover_url"]:
if helper.save_cover(to_save["cover_url"], book.path) is True:
if helper.save_cover_from_url(to_save["cover_url"], book.path) is True:
book.has_cover = 1
else:
flash(_(u"Cover is not a jpg file, can't save"), category="error")
flash(_(u"Cover is not a supported imageformat (jpg/png/webp), can't save"), category="error")
if book.series_index != to_save["series_index"]:
book.series_index = to_save["series_index"]