Merge remote-tracking branch 'del_books/delete-book-formats'
# Conflicts: # cps/helper.py Implemented delete on gdrive
This commit is contained in:
parent
f81fbaf542
commit
3db682cd15
|
@ -243,11 +243,17 @@ def get_sorted_author(value):
|
||||||
value2 = value
|
value2 = value
|
||||||
return value2
|
return value2
|
||||||
|
|
||||||
|
|
||||||
# Deletes a book fro the local filestorage, returns True if deleting is successfull, otherwise false
|
# Deletes a book fro the local filestorage, returns True if deleting is successfull, otherwise false
|
||||||
def delete_book_file(book, calibrepath):
|
def delete_book_file(book, calibrepath, book_format=None):
|
||||||
# check that path is 2 elements deep, check that target path has no subfolders
|
# check that path is 2 elements deep, check that target path has no subfolders
|
||||||
if book.path.count('/') == 1:
|
if book.path.count('/') == 1:
|
||||||
path = os.path.join(calibrepath, book.path)
|
path = os.path.join(calibrepath, book.path)
|
||||||
|
if book_format:
|
||||||
|
for file in os.listdir(path):
|
||||||
|
if file.upper().endswith("."+book_format):
|
||||||
|
os.remove(os.path.join(path, file))
|
||||||
|
else:
|
||||||
if os.path.isdir(path):
|
if os.path.isdir(path):
|
||||||
if len(next(os.walk(path))[1]):
|
if len(next(os.walk(path))[1]):
|
||||||
web.app.logger.error(
|
web.app.logger.error(
|
||||||
|
@ -258,9 +264,6 @@ def delete_book_file(book, calibrepath):
|
||||||
else:
|
else:
|
||||||
web.app.logger.error("Deleting book " + str(book.id) + " failed, book path not valid: " + book.path)
|
web.app.logger.error("Deleting book " + str(book.id) + " failed, book path not valid: " + book.path)
|
||||||
return False
|
return False
|
||||||
else:
|
|
||||||
web.app.logger.error("Deleting book " + str(book.id) + " failed, book path value: "+ book.path)
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def update_dir_stucture_file(book_id, calibrepath):
|
def update_dir_stucture_file(book_id, calibrepath):
|
||||||
|
@ -333,8 +336,15 @@ def update_dir_structure_gdrive(book_id):
|
||||||
return error
|
return error
|
||||||
|
|
||||||
|
|
||||||
def delete_book_gdrive(book):
|
def delete_book_gdrive(book, book_format):
|
||||||
error= False
|
error= False
|
||||||
|
if book_format:
|
||||||
|
name = ''
|
||||||
|
for entry in book.data:
|
||||||
|
if entry.format.upper() == book_format:
|
||||||
|
name = entry.name + '.' + book_format
|
||||||
|
gFile = gd.getFileFromEbooksFolder(book.path, name)
|
||||||
|
else:
|
||||||
gFile = gd.getFileFromEbooksFolder(os.path.dirname(book.path),book.path.split('/')[1])
|
gFile = gd.getFileFromEbooksFolder(os.path.dirname(book.path),book.path.split('/')[1])
|
||||||
if gFile:
|
if gFile:
|
||||||
gd.deleteDatabaseEntry(gFile['id'])
|
gd.deleteDatabaseEntry(gFile['id'])
|
||||||
|
@ -351,11 +361,11 @@ def update_dir_stucture(book_id, calibrepath):
|
||||||
else:
|
else:
|
||||||
return update_dir_stucture_file(book_id, calibrepath)
|
return update_dir_stucture_file(book_id, calibrepath)
|
||||||
|
|
||||||
def delete_book(book, calibrepath):
|
def delete_book(book, calibrepath, book_format):
|
||||||
if ub.config.config_use_google_drive:
|
if ub.config.config_use_google_drive:
|
||||||
return delete_book_gdrive(book)
|
return delete_book_gdrive(book, book_format)
|
||||||
else:
|
else:
|
||||||
return delete_book_file(book, calibrepath)
|
return delete_book_file(book, calibrepath, book_format)
|
||||||
|
|
||||||
def get_book_cover(cover_path):
|
def get_book_cover(cover_path):
|
||||||
if ub.config.config_use_google_drive:
|
if ub.config.config_use_google_drive:
|
||||||
|
|
|
@ -15,6 +15,15 @@
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<button type="button" class="btn btn-danger" id="delete" data-toggle="modal" data-target="#deleteModal">{{_("Delete Book")}}</button>
|
<button type="button" class="btn btn-danger" id="delete" data-toggle="modal" data-target="#deleteModal">{{_("Delete Book")}}</button>
|
||||||
</div>
|
</div>
|
||||||
|
{% if book.data|length > 1 %}
|
||||||
|
<div class="text-center more-stuff"><h4> {{_('Delete formats:')}} </h4>
|
||||||
|
{% for file in book.data %}
|
||||||
|
<div class="form-group">
|
||||||
|
<a href="{{ url_for('delete_book', book_id=book.id, book_format=file.format) }}" class="btn btn-danger" type="button">{{_('Delete')}} - {{file.format}}</a>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-9 col-xs-12">
|
<div class="col-sm-9 col-xs-12">
|
||||||
|
|
16
cps/web.py
16
cps/web.py
|
@ -1480,12 +1480,15 @@ def stats():
|
||||||
categorycounter=categorys, seriecounter=series, title=_(u"Statistics"), page="stat")
|
categorycounter=categorys, seriecounter=series, title=_(u"Statistics"), page="stat")
|
||||||
|
|
||||||
|
|
||||||
@app.route("/delete/<int:book_id>/")
|
@app.route("/delete/<int:book_id>/", defaults={'book_format': ""})
|
||||||
|
@app.route("/delete/<int:book_id>/<string:book_format>/")
|
||||||
@login_required
|
@login_required
|
||||||
def delete_book(book_id):
|
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:
|
||||||
|
helper.delete_book(book, config.config_calibre_dir, book_format=book_format.upper())
|
||||||
|
if not book_format:
|
||||||
# delete book from Shelfs, Downloads, Read list
|
# delete book from Shelfs, Downloads, Read list
|
||||||
ub.session.query(ub.BookShelf).filter(ub.BookShelf.book_id == book_id).delete()
|
ub.session.query(ub.BookShelf).filter(ub.BookShelf.book_id == book_id).delete()
|
||||||
ub.session.query(ub.ReadBook).filter(ub.ReadBook.book_id == book_id).delete()
|
ub.session.query(ub.ReadBook).filter(ub.ReadBook.book_id == book_id).delete()
|
||||||
|
@ -1494,7 +1497,6 @@ def delete_book(book_id):
|
||||||
# ub.session.query(ub.Downloads).filter(ub.Downloads.book_id == book_id).delete()
|
# ub.session.query(ub.Downloads).filter(ub.Downloads.book_id == book_id).delete()
|
||||||
ub.session.commit()
|
ub.session.commit()
|
||||||
|
|
||||||
helper.delete_book(book, config.config_calibre_dir)
|
|
||||||
# check if only this book links to:
|
# check if only this book links to:
|
||||||
# author, language, series, tags, custom columns
|
# author, language, series, tags, custom columns
|
||||||
modify_database_object([u''], book.authors, db.Authors, db.session, 'author')
|
modify_database_object([u''], book.authors, db.Authors, db.session, 'author')
|
||||||
|
@ -1524,13 +1526,19 @@ def delete_book(book_id):
|
||||||
else:
|
else:
|
||||||
modify_database_object([u''], getattr(book, cc_string), db.cc_classes[c.id], db.session, 'custom')
|
modify_database_object([u''], getattr(book, cc_string), db.cc_classes[c.id], 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:
|
||||||
|
db.session.query(db.Data).filter(db.Data.book == book.id).filter(db.Data.format == book_format).delete()
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
else:
|
else:
|
||||||
# book not foundß
|
# book not found
|
||||||
app.logger.info('Book with id "'+str(book_id)+'" could not be deleted')
|
app.logger.info('Book with id "'+str(book_id)+'" could not be deleted')
|
||||||
|
if book_format:
|
||||||
|
return redirect(url_for('edit_book', book_id=book_id))
|
||||||
|
else:
|
||||||
return redirect(url_for('index'))
|
return redirect(url_for('index'))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/gdrive/authenticate")
|
@app.route("/gdrive/authenticate")
|
||||||
@login_required
|
@login_required
|
||||||
@admin_required
|
@admin_required
|
||||||
|
|
Loading…
Reference in New Issue
Block a user