|
|
@ -154,6 +154,7 @@ def delete_book(book_id, book_format):
|
|
|
|
if current_user.role_delete_books():
|
|
|
|
if current_user.role_delete_books():
|
|
|
|
book = db.session.query(db.Books).filter(db.Books.id == book_id).first()
|
|
|
|
book = db.session.query(db.Books).filter(db.Books.id == book_id).first()
|
|
|
|
if book:
|
|
|
|
if book:
|
|
|
|
|
|
|
|
try:
|
|
|
|
helper.delete_book(book, config.config_calibre_dir, book_format=book_format.upper())
|
|
|
|
helper.delete_book(book, config.config_calibre_dir, book_format=book_format.upper())
|
|
|
|
if not book_format:
|
|
|
|
if not book_format:
|
|
|
|
# delete book from Shelfs, Downloads, Read list
|
|
|
|
# delete book from Shelfs, Downloads, Read list
|
|
|
@ -170,31 +171,42 @@ def delete_book(book_id, book_format):
|
|
|
|
modify_database_object([u''], book.languages, db.Languages, db.session, 'languages')
|
|
|
|
modify_database_object([u''], book.languages, db.Languages, db.session, 'languages')
|
|
|
|
modify_database_object([u''], book.publishers, db.Publishers, db.session, 'publishers')
|
|
|
|
modify_database_object([u''], book.publishers, db.Publishers, db.session, 'publishers')
|
|
|
|
|
|
|
|
|
|
|
|
cc = db.session.query(db.Custom_Columns).filter(db.Custom_Columns.datatype.notin_(db.cc_exceptions)).all()
|
|
|
|
cc = db.session.query(db.Custom_Columns).\
|
|
|
|
|
|
|
|
filter(db.Custom_Columns.datatype.notin_(db.cc_exceptions)).all()
|
|
|
|
for c in cc:
|
|
|
|
for c in cc:
|
|
|
|
cc_string = "custom_column_" + str(c.id)
|
|
|
|
cc_string = "custom_column_" + str(c.id)
|
|
|
|
if not c.is_multiple:
|
|
|
|
if not c.is_multiple:
|
|
|
|
if len(getattr(book, cc_string)) > 0:
|
|
|
|
if len(getattr(book, cc_string)) > 0:
|
|
|
|
if c.datatype == 'bool' or c.datatype == 'integer' or c.datatype == 'float':
|
|
|
|
if c.datatype == 'bool' or c.datatype == 'int' or c.datatype == 'float':
|
|
|
|
del_cc = getattr(book, cc_string)[0]
|
|
|
|
del_cc = getattr(book, cc_string)[0]
|
|
|
|
getattr(book, cc_string).remove(del_cc)
|
|
|
|
getattr(book, cc_string).remove(del_cc)
|
|
|
|
|
|
|
|
log.debug('remove ' + str(c.id))
|
|
|
|
db.session.delete(del_cc)
|
|
|
|
db.session.delete(del_cc)
|
|
|
|
|
|
|
|
db.session.commit()
|
|
|
|
elif c.datatype == 'rating':
|
|
|
|
elif c.datatype == 'rating':
|
|
|
|
del_cc = getattr(book, cc_string)[0]
|
|
|
|
del_cc = getattr(book, cc_string)[0]
|
|
|
|
getattr(book, cc_string).remove(del_cc)
|
|
|
|
getattr(book, cc_string).remove(del_cc)
|
|
|
|
if len(del_cc.books) == 0:
|
|
|
|
if len(del_cc.books) == 0:
|
|
|
|
|
|
|
|
log.debug('remove ' + str(c.id))
|
|
|
|
db.session.delete(del_cc)
|
|
|
|
db.session.delete(del_cc)
|
|
|
|
|
|
|
|
db.session.commit()
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
del_cc = getattr(book, cc_string)[0]
|
|
|
|
del_cc = getattr(book, cc_string)[0]
|
|
|
|
getattr(book, cc_string).remove(del_cc)
|
|
|
|
getattr(book, cc_string).remove(del_cc)
|
|
|
|
|
|
|
|
log.debug('remove ' + str(c.id))
|
|
|
|
db.session.delete(del_cc)
|
|
|
|
db.session.delete(del_cc)
|
|
|
|
|
|
|
|
db.session.commit()
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
modify_database_object([u''], getattr(book, cc_string), db.cc_classes[c.id],
|
|
|
|
modify_database_object([u''], getattr(book, cc_string), db.cc_classes[c.id],
|
|
|
|
db.session, 'custom')
|
|
|
|
db.session, 'custom')
|
|
|
|
db.session.query(db.Books).filter(db.Books.id == book_id).delete()
|
|
|
|
db.session.query(db.Books).filter(db.Books.id == book_id).delete()
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
db.session.query(db.Data).filter(db.Data.book == book.id).filter(db.Data.format == book_format).delete()
|
|
|
|
db.session.query(db.Data).filter(db.Data.book == book.id).\
|
|
|
|
|
|
|
|
filter(db.Data.format == book_format).delete()
|
|
|
|
db.session.commit()
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
|
|
log.debug(e)
|
|
|
|
|
|
|
|
db.session.rollback()
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
# book not found
|
|
|
|
# book not found
|
|
|
|
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)
|
|
|
|