Bugfix handle archive bit
This commit is contained in:
parent
3bf173d958
commit
fd5ab0ef53
|
@ -20,7 +20,7 @@
|
||||||
from flask_login import current_user
|
from flask_login import current_user
|
||||||
from . import ub
|
from . import ub
|
||||||
import datetime
|
import datetime
|
||||||
from sqlalchemy.sql.expression import or_
|
from sqlalchemy.sql.expression import or_, and_
|
||||||
|
|
||||||
# Add the current book id to kobo_synced_books table for current user, if entry is already present,
|
# Add the current book id to kobo_synced_books table for current user, if entry is already present,
|
||||||
# do nothing (safety precaution)
|
# do nothing (safety precaution)
|
||||||
|
@ -42,18 +42,18 @@ def remove_synced_book(book_id):
|
||||||
ub.session_commit()
|
ub.session_commit()
|
||||||
|
|
||||||
|
|
||||||
def add_archived_books(book_id):
|
def change_archived_books(book_id, state=None, message=None):
|
||||||
archived_book = (ub.session.query(ub.ArchivedBook)
|
archived_book = ub.session.query(ub.ArchivedBook).filter(and_(ub.ArchivedBook.user_id == int(current_user.id),
|
||||||
.filter(ub.ArchivedBook.book_id == book_id)
|
ub.ArchivedBook.book_id == book_id)).first()
|
||||||
.filter(ub.ArchivedBook.user_id == current_user.id)
|
|
||||||
.first())
|
|
||||||
if not archived_book:
|
if not archived_book:
|
||||||
archived_book = ub.ArchivedBook(user_id=current_user.id, book_id=book_id)
|
archived_book = ub.ArchivedBook(user_id=current_user.id, book_id=book_id)
|
||||||
archived_book.is_archived = True
|
|
||||||
|
archived_book.is_archived = state if state else not archived_book.is_archived
|
||||||
archived_book.last_modified = datetime.datetime.utcnow()
|
archived_book.last_modified = datetime.datetime.utcnow()
|
||||||
|
|
||||||
ub.session.merge(archived_book)
|
ub.session.merge(archived_book)
|
||||||
ub.session_commit()
|
ub.session_commit(message)
|
||||||
|
return archived_book.is_archived
|
||||||
|
|
||||||
|
|
||||||
# select all books which are synced by the current user and do not belong to a synced shelf and them to archive
|
# select all books which are synced by the current user and do not belong to a synced shelf and them to archive
|
||||||
|
@ -65,7 +65,7 @@ def update_on_sync_shelfs(user_id):
|
||||||
.filter(or_(ub.Shelf.kobo_sync == 0, ub.Shelf.kobo_sync == None))
|
.filter(or_(ub.Shelf.kobo_sync == 0, ub.Shelf.kobo_sync == None))
|
||||||
.filter(ub.KoboSyncedBooks.user_id == user_id).all())
|
.filter(ub.KoboSyncedBooks.user_id == user_id).all())
|
||||||
for b in books_to_archive:
|
for b in books_to_archive:
|
||||||
add_archived_books(b.book_id)
|
change_archived_books(b.book_id, True)
|
||||||
ub.session.query(ub.KoboSyncedBooks) \
|
ub.session.query(ub.KoboSyncedBooks) \
|
||||||
.filter(ub.KoboSyncedBooks.book_id == b.book_id) \
|
.filter(ub.KoboSyncedBooks.book_id == b.book_id) \
|
||||||
.filter(ub.KoboSyncedBooks.user_id == user_id).delete()
|
.filter(ub.KoboSyncedBooks.user_id == user_id).delete()
|
||||||
|
|
|
@ -631,14 +631,14 @@ function singleUserFormatter(value, row) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkboxFormatter(value, row){
|
function checkboxFormatter(value, row){
|
||||||
if(value & this.column)
|
if (value & this.column)
|
||||||
return '<input type="checkbox" class="chk" data-pk="' + row.id + '" data-name="' + this.field + '" checked onchange="checkboxChange(this, ' + row.id + ', \'' + this.name + '\', ' + this.column + ')">';
|
return '<input type="checkbox" class="chk" data-pk="' + row.id + '" data-name="' + this.field + '" checked onchange="checkboxChange(this, ' + row.id + ', \'' + this.name + '\', ' + this.column + ')">';
|
||||||
else
|
else
|
||||||
return '<input type="checkbox" class="chk" data-pk="' + row.id + '" data-name="' + this.field + '" onchange="checkboxChange(this, ' + row.id + ', \'' + this.name + '\', ' + this.column + ')">';
|
return '<input type="checkbox" class="chk" data-pk="' + row.id + '" data-name="' + this.field + '" onchange="checkboxChange(this, ' + row.id + ', \'' + this.name + '\', ' + this.column + ')">';
|
||||||
}
|
}
|
||||||
|
|
||||||
function singlecheckboxFormatter(value, row){
|
function singlecheckboxFormatter(value, row){
|
||||||
if(value)
|
if (value)
|
||||||
return '<input type="checkbox" class="chk" data-pk="' + row.id + '" data-name="' + this.field + '" checked onchange="checkboxChange(this, ' + row.id + ', \'' + this.name + '\', 0)">';
|
return '<input type="checkbox" class="chk" data-pk="' + row.id + '" data-name="' + this.field + '" checked onchange="checkboxChange(this, ' + row.id + ', \'' + this.name + '\', 0)">';
|
||||||
else
|
else
|
||||||
return '<input type="checkbox" class="chk" data-pk="' + row.id + '" data-name="' + this.field + '" onchange="checkboxChange(this, ' + row.id + ', \'' + this.name + '\', 0)">';
|
return '<input type="checkbox" class="chk" data-pk="' + row.id + '" data-name="' + this.field + '" onchange="checkboxChange(this, ' + row.id + ', \'' + this.name + '\', 0)">';
|
||||||
|
@ -793,7 +793,7 @@ function handleListServerResponse (data) {
|
||||||
function checkboxChange(checkbox, userId, field, field_index) {
|
function checkboxChange(checkbox, userId, field, field_index) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
method: "post",
|
method: "post",
|
||||||
url: window.location.pathname + "/../../ajax/editlistusers/" + field,
|
url: getPath() + "/ajax/editlistusers/" + field,
|
||||||
data: {"pk": userId, "field_index": field_index, "value": checkbox.checked},
|
data: {"pk": userId, "field_index": field_index, "value": checkbox.checked},
|
||||||
error: function(data) {
|
error: function(data) {
|
||||||
handleListServerResponse([{type:"danger", message:data.responseText}])
|
handleListServerResponse([{type:"danger", message:data.responseText}])
|
||||||
|
|
17
cps/web.py
17
cps/web.py
|
@ -56,6 +56,7 @@ from .redirect import redirect_back
|
||||||
from .usermanagement import login_required_if_no_ano
|
from .usermanagement import login_required_if_no_ano
|
||||||
from .kobo_sync_status import remove_synced_book
|
from .kobo_sync_status import remove_synced_book
|
||||||
from .render_template import render_title_template
|
from .render_template import render_title_template
|
||||||
|
from .kobo_sync_status import change_archived_books
|
||||||
|
|
||||||
feature_support = {
|
feature_support = {
|
||||||
'ldap': bool(services.ldap),
|
'ldap': bool(services.ldap),
|
||||||
|
@ -190,24 +191,15 @@ def toggle_read(book_id):
|
||||||
return "Custom Column No.{} is not existing in calibre database".format(config.config_read_column), 400
|
return "Custom Column No.{} is not existing in calibre database".format(config.config_read_column), 400
|
||||||
except (OperationalError, InvalidRequestError) as e:
|
except (OperationalError, InvalidRequestError) as e:
|
||||||
calibre_db.session.rollback()
|
calibre_db.session.rollback()
|
||||||
log.error(u"Read status could not set: %e", e)
|
log.error(u"Read status could not set: {}".format(e))
|
||||||
return "Read status could not set: {}".format(e), 400
|
return "Read status could not set: {}".format(e), 400
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
@web.route("/ajax/togglearchived/<int:book_id>", methods=['POST'])
|
@web.route("/ajax/togglearchived/<int:book_id>", methods=['POST'])
|
||||||
@login_required
|
@login_required
|
||||||
def toggle_archived(book_id):
|
def toggle_archived(book_id):
|
||||||
archived_book = ub.session.query(ub.ArchivedBook).filter(and_(ub.ArchivedBook.user_id == int(current_user.id),
|
is_archived = change_archived_books(book_id, message="Book {} archivebit toggled".format(book_id))
|
||||||
ub.ArchivedBook.book_id == book_id)).first()
|
if is_archived:
|
||||||
if archived_book:
|
|
||||||
archived_book.is_archived = not archived_book.is_archived
|
|
||||||
archived_book.last_modified = datetime.utcnow()
|
|
||||||
else:
|
|
||||||
archived_book = ub.ArchivedBook(user_id=current_user.id, book_id=book_id)
|
|
||||||
archived_book.is_archived = True
|
|
||||||
ub.session.merge(archived_book)
|
|
||||||
ub.session_commit("Book {} archivebit toggled".format(book_id))
|
|
||||||
if archived_book.is_archived:
|
|
||||||
remove_synced_book(book_id)
|
remove_synced_book(book_id)
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
@ -801,7 +793,6 @@ def list_books():
|
||||||
|
|
||||||
if sort == "state":
|
if sort == "state":
|
||||||
state = json.loads(request.args.get("state", "[]"))
|
state = json.loads(request.args.get("state", "[]"))
|
||||||
# order = [db.Books.timestamp.asc()] if order == "asc" else [db.Books.timestamp.desc()] # ToDo wrong: sort ticked
|
|
||||||
elif sort == "tags":
|
elif sort == "tags":
|
||||||
order = [db.Tags.name.asc()] if order == "asc" else [db.Tags.name.desc()]
|
order = [db.Tags.name.asc()] if order == "asc" else [db.Tags.name.desc()]
|
||||||
join = db.books_tags_link,db.Books.id == db.books_tags_link.c.book, db.Tags
|
join = db.books_tags_link,db.Books.id == db.books_tags_link.c.book, db.Tags
|
||||||
|
|
Loading…
Reference in New Issue
Block a user