Some code cosmetics
This commit is contained in:
parent
4df443e007
commit
8c751eb532
8 changed files with 57 additions and 54 deletions
|
@ -47,7 +47,7 @@ except ImportError as err:
|
|||
|
||||
current_milli_time = lambda: int(round(time() * 1000))
|
||||
|
||||
gdrive_watch_callback_token = 'target=calibreweb-watch_files'
|
||||
gdrive_watch_callback_token = 'target=calibreweb-watch_files' #nosec
|
||||
|
||||
|
||||
@gdrive.route("/authenticate")
|
||||
|
|
16
cps/kobo.py
16
cps/kobo.py
|
@ -42,8 +42,7 @@ from flask import (
|
|||
from flask_login import current_user
|
||||
from werkzeug.datastructures import Headers
|
||||
from sqlalchemy import func
|
||||
from sqlalchemy.sql.expression import and_, or_
|
||||
from sqlalchemy.orm import load_only
|
||||
from sqlalchemy.sql.expression import and_
|
||||
from sqlalchemy.exc import StatementError
|
||||
import requests
|
||||
|
||||
|
@ -893,17 +892,6 @@ def HandleProductsRequest(dummy=None):
|
|||
return redirect_or_proxy_request()
|
||||
|
||||
|
||||
'''@kobo.errorhandler(404)
|
||||
def handle_404(err):
|
||||
# This handler acts as a catch-all for endpoints that we don't have an interest in
|
||||
# implementing (e.g: v1/analytics/gettests, v1/user/recommendations, etc)
|
||||
if err:
|
||||
print('404')
|
||||
return jsonify(error=str(err)), 404
|
||||
log.debug("Unknown Request received: %s, method: %s, data: %s", request.base_url, request.method, request.data)
|
||||
return redirect_or_proxy_request()'''
|
||||
|
||||
|
||||
def make_calibre_web_auth_response():
|
||||
# As described in kobo_auth.py, CalibreWeb doesn't make use practical use of this auth/device API call for
|
||||
# authentation (nor for authorization). We return a dummy response just to keep the device happy.
|
||||
|
@ -947,7 +935,7 @@ def HandleInitRequest():
|
|||
store_response_json = store_response.json()
|
||||
if "Resources" in store_response_json:
|
||||
kobo_resources = store_response_json["Resources"]
|
||||
except:
|
||||
except Exception:
|
||||
log.error("Failed to receive or parse response from Kobo's init endpoint. Falling back to un-proxied mode.")
|
||||
if not kobo_resources:
|
||||
kobo_resources = NATIVE_KOBO_RESOURCES()
|
||||
|
|
|
@ -370,7 +370,7 @@ input:-moz-placeholder { color: #454545; }
|
|||
}
|
||||
|
||||
#searchResults li {
|
||||
margin-bottom:10px;
|
||||
margin-bottom: 10px;
|
||||
width: 225px;
|
||||
font-family: Georgia, "Times New Roman", Times, serif;
|
||||
list-style: none;
|
||||
|
|
|
@ -36,7 +36,6 @@ $("#desc").click(function() {
|
|||
sortBy: "name",
|
||||
sortAscending: true
|
||||
});
|
||||
return;
|
||||
});
|
||||
|
||||
$("#asc").click(function() {
|
||||
|
@ -52,19 +51,20 @@ $("#asc").click(function() {
|
|||
sortBy: "name",
|
||||
sortAscending: false
|
||||
});
|
||||
return;
|
||||
});
|
||||
|
||||
$("#all").click(function() {
|
||||
// go through all elements and make them visible
|
||||
$list.isotope({ filter: function() {
|
||||
return true;
|
||||
} })
|
||||
return true;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(".char").click(function() {
|
||||
var character = this.innerText;
|
||||
$list.isotope({ filter: function() {
|
||||
return this.attributes["data-id"].value.charAt(0).toUpperCase() == character;
|
||||
} })
|
||||
return this.attributes["data-id"].value.charAt(0).toUpperCase() == character;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -138,8 +138,8 @@ $(function () {
|
|||
seriesTitle = result.series.title;
|
||||
}
|
||||
var dateFomers = result.pubdate.split("-");
|
||||
var publishedYear = parseInt(dateFomers[0]);
|
||||
var publishedMonth = parseInt(dateFomers[1]);
|
||||
var publishedYear = parseInt(dateFomers[0], 10);
|
||||
var publishedMonth = parseInt(dateFomers[1], 10);
|
||||
var publishedDate = new Date(publishedYear, publishedMonth - 1, 1);
|
||||
|
||||
publishedDate = formatDate(publishedDate);
|
||||
|
@ -194,8 +194,8 @@ $(function () {
|
|||
} else {
|
||||
dateFomers = result.date_added.split("-");
|
||||
}
|
||||
var publishedYear = parseInt(dateFomers[0]);
|
||||
var publishedMonth = parseInt(dateFomers[1]);
|
||||
var publishedYear = parseInt(dateFomers[0], 10);
|
||||
var publishedMonth = parseInt(dateFomers[1], 10);
|
||||
var publishedDate = new Date(publishedYear, publishedMonth - 1, 1);
|
||||
|
||||
publishedDate = formatDate(publishedDate);
|
||||
|
|
|
@ -610,7 +610,7 @@ def migrate_Database(session):
|
|||
"locale VARCHAR(2),"
|
||||
"sidebar_view INTEGER,"
|
||||
"default_language VARCHAR(3),"
|
||||
"view_settings VARCHAR,"
|
||||
"view_settings VARCHAR,"
|
||||
"UNIQUE (nickname),"
|
||||
"UNIQUE (email))")
|
||||
conn.execute("INSERT INTO user_id(id, nickname, email, role, password, kindle_mail,locale,"
|
||||
|
|
|
@ -267,7 +267,8 @@ class Updater(threading.Thread):
|
|||
log.debug("Could not remove: %s", item_path)
|
||||
shutil.rmtree(source, ignore_errors=True)
|
||||
|
||||
def is_venv(self):
|
||||
@staticmethod
|
||||
def is_venv():
|
||||
if (hasattr(sys, 'real_prefix')) or (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix):
|
||||
return os.sep + os.path.relpath(sys.prefix, constants.BASE_DIR)
|
||||
else:
|
||||
|
|
66
cps/web.py
66
cps/web.py
|
@ -373,23 +373,9 @@ def render_books_list(data, sort, book_id, page):
|
|||
order = get_sort_function(sort, data)
|
||||
|
||||
if data == "rated":
|
||||
if current_user.check_visibility(constants.SIDEBAR_BEST_RATED):
|
||||
entries, random, pagination = calibre_db.fill_indexpage(page, 0,
|
||||
db.Books,
|
||||
db.Books.ratings.any(db.Ratings.rating > 9),
|
||||
order)
|
||||
return render_title_template('index.html', random=random, entries=entries, pagination=pagination,
|
||||
id=book_id, title=_(u"Top Rated Books"), page="rated")
|
||||
else:
|
||||
abort(404)
|
||||
return render_rated_books(page, book_id, order=order)
|
||||
elif data == "discover":
|
||||
if current_user.check_visibility(constants.SIDEBAR_RANDOM):
|
||||
entries, __, pagination = calibre_db.fill_indexpage(page, 0, db.Books, True, [func.randomblob(2)])
|
||||
pagination = Pagination(1, config.config_books_per_page, config.config_books_per_page)
|
||||
return render_title_template('discover.html', entries=entries, pagination=pagination, id=book_id,
|
||||
title=_(u"Discover (Random Books)"), page="discover")
|
||||
else:
|
||||
abort(404)
|
||||
return render_discover_books(page, book_id)
|
||||
elif data == "unread":
|
||||
return render_read_books(page, False, order=order)
|
||||
elif data == "read":
|
||||
|
@ -429,6 +415,27 @@ def render_books_list(data, sort, book_id, page):
|
|||
title=_(u"Books"), page=website)
|
||||
|
||||
|
||||
def render_rated_books(page, book_id, order):
|
||||
if current_user.check_visibility(constants.SIDEBAR_BEST_RATED):
|
||||
entries, random, pagination = calibre_db.fill_indexpage(page, 0,
|
||||
db.Books,
|
||||
db.Books.ratings.any(db.Ratings.rating > 9),
|
||||
order)
|
||||
return render_title_template('index.html', random=random, entries=entries, pagination=pagination,
|
||||
id=book_id, title=_(u"Top Rated Books"), page="rated")
|
||||
else:
|
||||
abort(404)
|
||||
|
||||
|
||||
def render_discover_books(page, book_id):
|
||||
if current_user.check_visibility(constants.SIDEBAR_RANDOM):
|
||||
entries, __, pagination = calibre_db.fill_indexpage(page, 0, db.Books, True, [func.randomblob(2)])
|
||||
pagination = Pagination(1, config.config_books_per_page, config.config_books_per_page)
|
||||
return render_title_template('discover.html', entries=entries, pagination=pagination, id=book_id,
|
||||
title=_(u"Discover (Random Books)"), page="discover")
|
||||
else:
|
||||
abort(404)
|
||||
|
||||
def render_hot_books(page):
|
||||
if current_user.check_visibility(constants.SIDEBAR_HOT):
|
||||
if current_user.show_detail_random():
|
||||
|
@ -1478,16 +1485,7 @@ def logout():
|
|||
|
||||
|
||||
# ################################### Users own configuration #########################################################
|
||||
def change_profile(kobo_support, local_oauth_check, oauth_status, translations, languages):
|
||||
to_save = request.form.to_dict()
|
||||
current_user.random_books = 0
|
||||
if current_user.role_passwd() or current_user.role_admin():
|
||||
if "password" in to_save and to_save["password"]:
|
||||
current_user.password = generate_password_hash(to_save["password"])
|
||||
if "kindle_mail" in to_save and to_save["kindle_mail"] != current_user.kindle_mail:
|
||||
current_user.kindle_mail = to_save["kindle_mail"]
|
||||
if "allowed_tags" in to_save and to_save["allowed_tags"] != current_user.allowed_tags:
|
||||
current_user.allowed_tags = to_save["allowed_tags"].strip()
|
||||
def change_profile_email(to_save, kobo_support, local_oauth_check, oauth_status):
|
||||
if "email" in to_save and to_save["email"] != current_user.email:
|
||||
if config.config_public_reg and not check_valid_domain(to_save["email"]):
|
||||
flash(_(u"E-mail is not from valid domain"), category="error")
|
||||
|
@ -1496,6 +1494,8 @@ def change_profile(kobo_support, local_oauth_check, oauth_status, translations,
|
|||
kobo_support=kobo_support,
|
||||
registered_oauth=local_oauth_check, oauth_status=oauth_status)
|
||||
current_user.email = to_save["email"]
|
||||
|
||||
def change_profile_nickname(to_save, kobo_support, local_oauth_check, translations, languages):
|
||||
if "nickname" in to_save and to_save["nickname"] != current_user.nickname:
|
||||
# Query User nickname, if not existing, change
|
||||
if not ub.session.query(ub.User).filter(ub.User.nickname == to_save["nickname"]).scalar():
|
||||
|
@ -1511,6 +1511,20 @@ def change_profile(kobo_support, local_oauth_check, oauth_status, translations,
|
|||
title=_(u"Edit User %(nick)s",
|
||||
nick=current_user.nickname),
|
||||
page="edituser")
|
||||
|
||||
|
||||
def change_profile(kobo_support, local_oauth_check, oauth_status, translations, languages):
|
||||
to_save = request.form.to_dict()
|
||||
current_user.random_books = 0
|
||||
if current_user.role_passwd() or current_user.role_admin():
|
||||
if "password" in to_save and to_save["password"]:
|
||||
current_user.password = generate_password_hash(to_save["password"])
|
||||
if "kindle_mail" in to_save and to_save["kindle_mail"] != current_user.kindle_mail:
|
||||
current_user.kindle_mail = to_save["kindle_mail"]
|
||||
if "allowed_tags" in to_save and to_save["allowed_tags"] != current_user.allowed_tags:
|
||||
current_user.allowed_tags = to_save["allowed_tags"].strip()
|
||||
change_profile_email(to_save, kobo_support, local_oauth_check, oauth_status)
|
||||
change_profile_nickname(to_save, kobo_support, local_oauth_check, translations, languages)
|
||||
if "show_random" in to_save and to_save["show_random"] == "on":
|
||||
current_user.random_books = 1
|
||||
if "default_language" in to_save:
|
||||
|
|
Loading…
Reference in a new issue