Fix #1170 Auth-digest Header no longer crashs calibre-web

Fix #1161 Shelfs are reordering again
Update Sortable.js to 2.10.1
Code cosmetics
pull/1186/head
Ozzieisaacs 5 years ago
parent f67953c447
commit b33a2ac90d

@ -284,8 +284,14 @@ def show_shelf(shelf_type, shelf_id):
books_in_shelf = ub.session.query(ub.BookShelf).filter(ub.BookShelf.shelf == shelf_id)\ books_in_shelf = ub.session.query(ub.BookShelf).filter(ub.BookShelf.shelf == shelf_id)\
.order_by(ub.BookShelf.order.asc()).all() .order_by(ub.BookShelf.order.asc()).all()
books_list = [ b.book_id for b in books_in_shelf] for book in books_in_shelf:
result = db.session.query(db.Books).filter(db.Books.id.in_(books_list)).filter(common_filters()).all() cur_book = db.session.query(db.Books).filter(db.Books.id == book.book_id).filter(common_filters()).first()
if cur_book:
result.append(cur_book)
else:
log.info('Not existing book %s in %s deleted', book.book_id, shelf)
ub.session.query(ub.BookShelf).filter(ub.BookShelf.book_id == book.book_id).delete()
ub.session.commit()
return render_title_template(page, entries=result, title=_(u"Shelf: '%(name)s'", name=shelf.name), return render_title_template(page, entries=result, title=_(u"Shelf: '%(name)s'", name=shelf.name),
shelf=shelf, page="shelf") shelf=shelf, page="shelf")
else: else:
@ -317,8 +323,11 @@ def order_shelf(shelf_id):
if shelf: if shelf:
books_in_shelf2 = ub.session.query(ub.BookShelf).filter(ub.BookShelf.shelf == shelf_id) \ books_in_shelf2 = ub.session.query(ub.BookShelf).filter(ub.BookShelf.shelf == shelf_id) \
.order_by(ub.BookShelf.order.asc()).all() .order_by(ub.BookShelf.order.asc()).all()
books_list = [ b.book_id for b in books_in_shelf2] for book in books_in_shelf2:
result = db.session.query(db.Books).filter(db.Books.id.in_(books_list)).filter(common_filters()).all() cur_book = db.session.query(db.Books).filter(db.Books.id == book.book_id).filter(common_filters()).first()
result.append(cur_book)
#books_list = [ b.book_id for b in books_in_shelf2]
#result = db.session.query(db.Books).filter(db.Books.id.in_(books_list)).filter(common_filters()).all()
return render_title_template('shelf_order.html', entries=result, return render_title_template('shelf_order.html', entries=result,
title=_(u"Change order of Shelf: '%(name)s'", name=shelf.name), title=_(u"Change order of Shelf: '%(name)s'", name=shelf.name),
shelf=shelf, page="shelforder") shelf=shelf, page="shelforder")

@ -55,9 +55,9 @@ $(function () {
$(".cover img").attr("src", book.cover); $(".cover img").attr("src", book.cover);
$("#cover_url").val(book.cover); $("#cover_url").val(book.cover);
$("#pubdate").val(book.publishedDate); $("#pubdate").val(book.publishedDate);
$("#publisher").val(book.publisher) $("#publisher").val(book.publisher);
if (book.series != undefined) { if (typeof book.series !== "undefined") {
$("#series").val(book.series) $("#series").val(book.series);
} }
} }
@ -72,16 +72,18 @@ $(function () {
} }
function formatDate (date) { function formatDate (date) {
var d = new Date(date), var d = new Date(date),
month = '' + (d.getMonth() + 1), month = "" + (d.getMonth() + 1),
day = '' + d.getDate(), day = "" + d.getDate(),
year = d.getFullYear(); year = d.getFullYear();
if (month.length < 2) if (month.length < 2) {
month = '0' + month; month = "0" + month;
if (day.length < 2) }
day = '0' + day; if (day.length < 2) {
day = "0" + day;
}
return [year, month, day].join('-'); return [year, month, day].join("-");
} }
if (ggDone && ggResults.length > 0) { if (ggDone && ggResults.length > 0) {
@ -116,15 +118,16 @@ $(function () {
} }
if (dbDone && dbResults.length > 0) { if (dbDone && dbResults.length > 0) {
dbResults.forEach(function(result) { dbResults.forEach(function(result) {
if (result.series){ var seriesTitle = "";
var series_title = result.series.title if (result.series) {
seriesTitle = result.series.title;
} }
var date_fomers = result.pubdate.split("-") var dateFomers = result.pubdate.split("-");
var publishedYear = parseInt(date_fomers[0]) var publishedYear = parseInt(dateFomers[0]);
var publishedMonth = parseInt(date_fomers[1]) var publishedMonth = parseInt(dateFomers[1]);
var publishedDate = new Date(publishedYear, publishedMonth-1, 1) var publishedDate = new Date(publishedYear, publishedMonth - 1, 1);
publishedDate = formatDate(publishedDate) publishedDate = formatDate(publishedDate);
var book = { var book = {
id: result.id, id: result.id,
@ -137,7 +140,7 @@ $(function () {
return tag.title.toLowerCase().replace(/,/g, "_"); return tag.title.toLowerCase().replace(/,/g, "_");
}), }),
rating: result.rating.average || 0, rating: result.rating.average || 0,
series: series_title || "", series: seriesTitle || "",
cover: result.image, cover: result.image,
url: "https://book.douban.com/subject/" + result.id, url: "https://book.douban.com/subject/" + result.id,
source: { source: {
@ -183,7 +186,7 @@ $(function () {
} }
function dbSearchBook (title) { function dbSearchBook (title) {
apikey="0df993c66c0c636e29ecbb5344252a4a" var apikey = "0df993c66c0c636e29ecbb5344252a4a";
$.ajax({ $.ajax({
url: douban + dbSearch + "?apikey=" + apikey + "&q=" + title + "&fields=all&count=10", url: douban + dbSearch + "?apikey=" + apikey + "&q=" + title + "&fields=all&count=10",
type: "GET", type: "GET",
@ -193,7 +196,7 @@ $(function () {
dbResults = data.books; dbResults = data.books;
}, },
error: function error() { error: function error() {
$("#meta-info").html("<p class=\"text-danger\">" + msg.search_error + "!</p>"+ $("#meta-info")[0].innerHTML) $("#meta-info").html("<p class=\"text-danger\">" + msg.search_error + "!</p>" + $("#meta-info")[0].innerHTML);
}, },
complete: function complete() { complete: function complete() {
dbDone = true; dbDone = true;

File diff suppressed because one or more lines are too long

@ -29,7 +29,7 @@ function sendData(path) {
var maxElements; var maxElements;
var tmp = []; var tmp = [];
elements = Sortable.utils.find(sortTrue, "div"); elements = $(".list-group-item");
maxElements = elements.length; maxElements = elements.length;
var form = document.createElement("form"); var form = document.createElement("form");

@ -150,7 +150,7 @@ def load_user_from_auth_header(header_val):
header_val = base64.b64decode(header_val).decode('utf-8') header_val = base64.b64decode(header_val).decode('utf-8')
basic_username = header_val.split(':')[0] basic_username = header_val.split(':')[0]
basic_password = header_val.split(':')[1] basic_password = header_val.split(':')[1]
except TypeError: except (TypeError, UnicodeDecodeError):
pass pass
user = _fetch_user_by_name(basic_username) user = _fetch_user_by_name(basic_username)
if user and check_password_hash(str(user.password), basic_password): if user and check_password_hash(str(user.password), basic_password):

Loading…
Cancel
Save