|
|
@ -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,17 +396,18 @@ 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
|
|
|
|
if book.title != to_save["book_title"].rstrip().strip():
|
|
|
|
if book.title != to_save["book_title"].rstrip().strip():
|
|
|
|
if to_save["book_title"] == '':
|
|
|
|
if to_save["book_title"] == '':
|
|
|
|
to_save["book_title"] = _(u'unknown')
|
|
|
|
to_save["book_title"] = _(u'Unknown')
|
|
|
|
book.title = to_save["book_title"].rstrip().strip()
|
|
|
|
book.title = to_save["book_title"].rstrip().strip()
|
|
|
|
edited_books_id = book.id
|
|
|
|
edited_books_id = book.id
|
|
|
|
|
|
|
|
|
|
|
@ -412,7 +416,7 @@ def edit_book(book_id):
|
|
|
|
input_authors = list(map(lambda it: it.strip().replace(',', '|'), input_authors))
|
|
|
|
input_authors = list(map(lambda it: it.strip().replace(',', '|'), input_authors))
|
|
|
|
# we have all author names now
|
|
|
|
# we have all author names now
|
|
|
|
if input_authors == ['']:
|
|
|
|
if input_authors == ['']:
|
|
|
|
input_authors = [_(u'unknown')] # prevent empty Author
|
|
|
|
input_authors = [_(u'Unknown')] # prevent empty Author
|
|
|
|
|
|
|
|
|
|
|
|
modify_database_object(input_authors, book.authors, db.Authors, db.session, 'author')
|
|
|
|
modify_database_object(input_authors, book.authors, db.Authors, db.session, 'author')
|
|
|
|
|
|
|
|
|
|
|
@ -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'] == _(u'Unknown'):
|
|
|
|
|
|
|
|
to_save['author_name'] = ''
|
|
|
|
|
|
|
|
if to_save['book_title'] == _(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
|
|
|
@ -573,7 +591,7 @@ def upload():
|
|
|
|
filepath = os.path.join(config.config_calibre_dir, author_dir, title_dir)
|
|
|
|
filepath = os.path.join(config.config_calibre_dir, author_dir, title_dir)
|
|
|
|
saved_filename = os.path.join(filepath, title_dir + meta.extension.lower())
|
|
|
|
saved_filename = os.path.join(filepath, title_dir + meta.extension.lower())
|
|
|
|
|
|
|
|
|
|
|
|
if title != u'Unknown' and authr != u'Unknown':
|
|
|
|
if title != _(u'Unknown') and authr != _(u'Unknown'):
|
|
|
|
entry = helper.check_exists_book(authr, title)
|
|
|
|
entry = helper.check_exists_book(authr, title)
|
|
|
|
if entry:
|
|
|
|
if entry:
|
|
|
|
log.info("Uploaded book probably exists in library")
|
|
|
|
log.info("Uploaded book probably exists in library")
|
|
|
|