mirror of
https://github.com/janeczku/calibre-web
synced 2024-11-25 02:57:22 +00:00
Merging books basically working
This commit is contained in:
parent
a758976c69
commit
c6c9cfea22
@ -173,7 +173,7 @@ def modify_identifiers(input_identifiers, db_identifiers, db_session):
|
|||||||
@editbook.route("/ajax/delete/<int:book_id>")
|
@editbook.route("/ajax/delete/<int:book_id>")
|
||||||
@login_required
|
@login_required
|
||||||
def delete_book_from_details(book_id):
|
def delete_book_from_details(book_id):
|
||||||
return delete_book(book_id,"", True)
|
return Response(delete_book(book_id,"", True), mimetype='application/json')
|
||||||
|
|
||||||
|
|
||||||
@editbook.route("/delete/<int:book_id>", defaults={'book_format': ""})
|
@editbook.route("/delete/<int:book_id>", defaults={'book_format': ""})
|
||||||
@ -191,11 +191,10 @@ def delete_book(book_id, book_format, jsonResponse):
|
|||||||
result, error = helper.delete_book(book, config.config_calibre_dir, book_format=book_format.upper())
|
result, error = helper.delete_book(book, config.config_calibre_dir, book_format=book_format.upper())
|
||||||
if not result:
|
if not result:
|
||||||
if jsonResponse:
|
if jsonResponse:
|
||||||
return Response(json.dumps({"location": url_for("editbook.edit_book"),
|
return json.dumps({"location": url_for("editbook.edit_book"),
|
||||||
"type": "alert",
|
"type": "alert",
|
||||||
"format": "",
|
"format": "",
|
||||||
"error": error}),
|
"error": error}),
|
||||||
mimetype='application/json')
|
|
||||||
else:
|
else:
|
||||||
flash(error, category="error")
|
flash(error, category="error")
|
||||||
return redirect(url_for('editbook.edit_book', book_id=book_id))
|
return redirect(url_for('editbook.edit_book', book_id=book_id))
|
||||||
@ -263,21 +262,19 @@ def delete_book(book_id, book_format, jsonResponse):
|
|||||||
log.error('Book with id "%s" could not be deleted: not found', book_id)
|
log.error('Book with id "%s" could not be deleted: not found', book_id)
|
||||||
if book_format:
|
if book_format:
|
||||||
if jsonResponse:
|
if jsonResponse:
|
||||||
return Response(json.dumps([warning, {"location": url_for("editbook.edit_book", book_id=book_id),
|
return json.dumps([warning, {"location": url_for("editbook.edit_book", book_id=book_id),
|
||||||
"type": "success",
|
"type": "success",
|
||||||
"format": book_format,
|
"format": book_format,
|
||||||
"message": _('Book Format Successfully Deleted')}]),
|
"message": _('Book Format Successfully Deleted')}])
|
||||||
mimetype='application/json')
|
|
||||||
else:
|
else:
|
||||||
flash(_('Book Format Successfully Deleted'), category="success")
|
flash(_('Book Format Successfully Deleted'), category="success")
|
||||||
return redirect(url_for('editbook.edit_book', book_id=book_id))
|
return redirect(url_for('editbook.edit_book', book_id=book_id))
|
||||||
else:
|
else:
|
||||||
if jsonResponse:
|
if jsonResponse:
|
||||||
return Response(json.dumps([warning, {"location": url_for('web.index'),
|
return json.dumps([warning, {"location": url_for('web.index'),
|
||||||
"type": "success",
|
"type": "success",
|
||||||
"format": book_format,
|
"format": book_format,
|
||||||
"message": _('Book Successfully Deleted')}]),
|
"message": _('Book Successfully Deleted')}])
|
||||||
mimetype='application/json')
|
|
||||||
else:
|
else:
|
||||||
flash(_('Book Successfully Deleted'), category="success")
|
flash(_('Book Successfully Deleted'), category="success")
|
||||||
return redirect(url_for('web.index'))
|
return redirect(url_for('web.index'))
|
||||||
@ -994,8 +991,33 @@ def get_sorted_entry(field, bookid):
|
|||||||
@editbook.route("/ajax/mergebooks", methods=['POST'])
|
@editbook.route("/ajax/mergebooks", methods=['POST'])
|
||||||
@login_required
|
@login_required
|
||||||
def merge_list_book():
|
def merge_list_book():
|
||||||
vals = request.get_json()
|
vals = request.get_json().get('Merge_books')
|
||||||
|
to_file= list()
|
||||||
# load first book
|
if vals:
|
||||||
# load every next book, append data to first book, delete 2nd book
|
# load all formats from target book
|
||||||
|
to_book = calibre_db.get_book(vals[0])
|
||||||
|
vals.pop(0)
|
||||||
|
if to_book:
|
||||||
|
for file in to_book.data:
|
||||||
|
to_file.append(file.format)
|
||||||
|
to_name = helper.get_valid_filename(to_book.title) + ' - ' + \
|
||||||
|
helper.get_valid_filename(to_book.authors[0].name)
|
||||||
|
for book_id in vals:
|
||||||
|
from_book = calibre_db.get_book(book_id)
|
||||||
|
if from_book:
|
||||||
|
for element in from_book.data:
|
||||||
|
if element.format not in to_file:
|
||||||
|
# create new data entry with: book_id, book_format, uncompressed_size, name
|
||||||
|
filepath_new = os.path.normpath(os.path.join(config.config_calibre_dir,
|
||||||
|
to_book.path,
|
||||||
|
to_name + "." + element.format.lower()))
|
||||||
|
filepath_old = os.path.normpath(os.path.join(config.config_calibre_dir,
|
||||||
|
from_book.path,
|
||||||
|
element.name + "." + element.format.lower()))
|
||||||
|
copyfile(filepath_old, filepath_new)
|
||||||
|
to_book.data.append(db.Data(to_book.id,
|
||||||
|
element.format,
|
||||||
|
element.uncompressed_size,
|
||||||
|
to_name))
|
||||||
|
delete_book(from_book.id,"", True) # json_resp =
|
||||||
return ""
|
return ""
|
||||||
|
Loading…
Reference in New Issue
Block a user