diff --git a/cps/kobo_sync_status.py b/cps/kobo_sync_status.py
index b88cb6ac..eee47d89 100644
--- a/cps/kobo_sync_status.py
+++ b/cps/kobo_sync_status.py
@@ -20,7 +20,7 @@
from flask_login import current_user
from . import ub
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,
# do nothing (safety precaution)
@@ -42,18 +42,18 @@ def remove_synced_book(book_id):
ub.session_commit()
-def add_archived_books(book_id):
- archived_book = (ub.session.query(ub.ArchivedBook)
- .filter(ub.ArchivedBook.book_id == book_id)
- .filter(ub.ArchivedBook.user_id == current_user.id)
- .first())
+def change_archived_books(book_id, state=None, message=None):
+ archived_book = ub.session.query(ub.ArchivedBook).filter(and_(ub.ArchivedBook.user_id == int(current_user.id),
+ ub.ArchivedBook.book_id == book_id)).first()
if not archived_book:
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()
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
@@ -65,7 +65,7 @@ def update_on_sync_shelfs(user_id):
.filter(or_(ub.Shelf.kobo_sync == 0, ub.Shelf.kobo_sync == None))
.filter(ub.KoboSyncedBooks.user_id == user_id).all())
for b in books_to_archive:
- add_archived_books(b.book_id)
+ change_archived_books(b.book_id, True)
ub.session.query(ub.KoboSyncedBooks) \
.filter(ub.KoboSyncedBooks.book_id == b.book_id) \
.filter(ub.KoboSyncedBooks.user_id == user_id).delete()
diff --git a/cps/static/js/table.js b/cps/static/js/table.js
index 0600f0b3..e98f6a8b 100644
--- a/cps/static/js/table.js
+++ b/cps/static/js/table.js
@@ -631,14 +631,14 @@ function singleUserFormatter(value, row) {
}
function checkboxFormatter(value, row){
- if(value & this.column)
+ if (value & this.column)
return '';
else
return '';
}
function singlecheckboxFormatter(value, row){
- if(value)
+ if (value)
return '';
else
return '';
@@ -793,7 +793,7 @@ function handleListServerResponse (data) {
function checkboxChange(checkbox, userId, field, field_index) {
$.ajax({
method: "post",
- url: window.location.pathname + "/../../ajax/editlistusers/" + field,
+ url: getPath() + "/ajax/editlistusers/" + field,
data: {"pk": userId, "field_index": field_index, "value": checkbox.checked},
error: function(data) {
handleListServerResponse([{type:"danger", message:data.responseText}])
diff --git a/cps/web.py b/cps/web.py
index 13c56f11..f203783b 100644
--- a/cps/web.py
+++ b/cps/web.py
@@ -56,6 +56,7 @@ from .redirect import redirect_back
from .usermanagement import login_required_if_no_ano
from .kobo_sync_status import remove_synced_book
from .render_template import render_title_template
+from .kobo_sync_status import change_archived_books
feature_support = {
'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
except (OperationalError, InvalidRequestError) as e:
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 ""
@web.route("/ajax/togglearchived/", methods=['POST'])
@login_required
def toggle_archived(book_id):
- archived_book = ub.session.query(ub.ArchivedBook).filter(and_(ub.ArchivedBook.user_id == int(current_user.id),
- ub.ArchivedBook.book_id == book_id)).first()
- 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:
+ is_archived = change_archived_books(book_id, message="Book {} archivebit toggled".format(book_id))
+ if is_archived:
remove_synced_book(book_id)
return ""
@@ -801,7 +793,6 @@ def list_books():
if sort == "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":
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