Code cosmetics

pull/164/merge
OzzieIsaacs 7 years ago
parent 78067b87bc
commit 986f40b80a

@ -264,7 +264,7 @@ class Books(Base):
class Custom_Columns(Base):
__tablename__ = 'custom_columns'
id = Column(Integer, primary_key=True)
label = Column(String)
name = Column(String)

@ -57,7 +57,7 @@ def get_epub_info(tmp_file_path, original_file_name, original_file_extension):
epub_metadata['description'] = ""
if epub_metadata['language'] == "Unknown":
epub_metadata['language'] == ""
epub_metadata['language'] = ""
else:
lang = epub_metadata['language'].split('-', 1)[0].lower()
if len(lang) == 2:
@ -87,7 +87,7 @@ def get_epub_info(tmp_file_path, original_file_name, original_file_extension):
coverfile = extractCover(zip, filename, "", tmp_file_path)
else:
coverfile = extractCover(zip, coversection[0], coverpath, tmp_file_path)
if epub_metadata['title'] is None:
title = original_file_name
else:

@ -277,12 +277,12 @@ def update_dir_stucture(book_id, calibrepath):
db.session.connection().connection.connection.create_function("title_sort", 1, db.title_sort)
book = db.session.query(db.Books).filter(db.Books.id == book_id).first()
path = os.path.join(calibrepath, book.path)#.replace('/',os.path.sep)).replace('\\',os.path.sep)
authordir = book.path.split('/')[0]
new_authordir = get_valid_filename(book.authors[0].name)
titledir = book.path.split('/')[1]
new_titledir = get_valid_filename(book.title) + " (" + str(book_id) + ")"
if titledir != new_titledir:
new_title_path = os.path.join(os.path.dirname(path), new_titledir)
os.rename(path, new_title_path)
@ -348,7 +348,7 @@ class Updater(threading.Thread):
if web.gevent_server:
web.gevent_server.stop()
else:
# stop tornado server
# stop tornado server
server = IOLoop.instance()
server.add_callback(server.stop)
self.status=7

@ -17,8 +17,8 @@ function prefixed_source(prefix, query, cb, bhAdapter) {
});
}
function get_path(){
var jsFileLocation = $('script[src*=edit_books]').attr('src'); // the js file path
jsFileLocation = jsFileLocation.replace('/static/js/edit_books.js', ''); // the js folder path
var jsFileLocation = $("script[src*=edit_books]").attr("src"); // the js file path
jsFileLocation = jsFileLocation.replace("/static/js/edit_books.js", ''); // the js folder path
return jsFileLocation;
}
@ -29,7 +29,7 @@ var authors = new Bloodhound({
},
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: get_path()+'/get_authors_json?q=%QUERY'
url: get_path()+"/get_authors_json?q=%QUERY"
}
});
@ -58,7 +58,8 @@ var promise = authors.initialize();
highlight: true, minLength: 1,
hint: true
}, {
name: 'authors', displayKey: 'name',
name: "authors",
displayKey: "name",
source: authors_source
}
)
@ -73,10 +74,9 @@ var series = new Bloodhound({
return [query];
},
remote: {
url: get_path()+'/get_series_json?q=',
url: get_path()+"/get_series_json?q=",
replace: function(url, query) {
url_query = url+encodeURIComponent(query);
return url_query;
return url+encodeURIComponent(query);
}
}
});
@ -87,7 +87,8 @@ var promise = series.initialize();
highlight: true, minLength: 0,
hint: true
}, {
name: 'series', displayKey: 'name',
name: "series",
displayKey: "name",
source: series.ttAdapter()
}
)
@ -99,9 +100,9 @@ var tags = new Bloodhound({
return [datum.name];
},
queryTokenizer: function(query) {
tokens = query.split(",");
var tokens = query.split(",");
tokens = [tokens[tokens.length-1].trim()];
return tokens
return tokens;
},
remote: {
url: get_path()+"/get_tags_json?q=%QUERY"
@ -131,7 +132,8 @@ var promise = tags.initialize();
highlight: true, minLength: 0,
hint: true
}, {
name: 'tags', displayKey: 'name',
name: "tags",
displayKey: "name",
source: tag_source
}
)
@ -146,7 +148,7 @@ var languages = new Bloodhound({
return [query];
},
remote: {
url: get_path()+'/get_languages_json?q=',
url: get_path()+"/get_languages_json?q=",
replace: function(url, query) {
url_query = url+encodeURIComponent(query);
return url_query;
@ -177,23 +179,24 @@ var promise = languages.initialize();
highlight: true, minLength: 0,
hint: true
}, {
name: 'languages', displayKey: 'name',
name: "languages",
displayKey: "name",
source: language_source
}
)
});
$('form').on('change input typeahead:selected', function(data){
form = $('form').serialize();
$("form").on("change input typeahead:selected", function(data){
var form = $("form").serialize();
$.getJSON( get_path()+"/get_matching_tags", form, function( data ) {
$('.tags_click').each(function() {
if ($.inArray(parseInt($(this).children('input').first().val(), 10), data.tags) == -1 ) {
if (!($(this).hasClass('active'))) {
$(this).addClass('disabled');
$(".tags_click").each(function() {
if ($.inArray(parseInt($(this).children("input").first().val(), 10), data.tags) === -1 ) {
if (!($(this).hasClass("active"))) {
$(this).addClass("disabled");
}
}
else {
$(this).removeClass('disabled');
$(this).removeClass("disabled");
}
});
});

@ -6,33 +6,33 @@
*/
$(document).ready(function () {
var msg = i18n_msg;
var msg = i18nMsg;
var douban = "https://api.douban.com";
var db_search = '/v2/book/search';
var db_get_info = '/v2/book/';
var db_get_info_by_isbn = '/v2/book/isbn/ ';
var db_done = false;
var dbSearch = "/v2/book/search";
var db_get_info = "/v2/book/";
var db_get_info_by_isbn = "/v2/book/isbn/ ";
var dbDone = false;
var google = 'https://www.googleapis.com/';
var gg_search = '/books/v1/volumes';
var gg_get_info = '/books/v1/volumes/';
var google = "https://www.googleapis.com/";
var gg_search = "/books/v1/volumes";
var gg_get_info = "/books/v1/volumes/";
var gg_done = false;
var db_results = [];
var gg_results = [];
var show_flag = 0;
String.prototype.replaceAll = function (s1, s2) {  
return this.replace(new RegExp(s1, "gm"), s2);  
return this.replace(new RegExp(s1, "gm"), s2);
};
gg_search_book = function (title) {
title = title.replaceAll(/\s+/, '+');
var url = google + gg_search + '?q=' + title;
function gg_search_book (title) {
title = title.replaceAll(/\s+/, "+");
var url = google + gg_search + "?q=" + title;
$.ajax({
url: url,
url,
type: "GET",
dataType: "jsonp",
jsonp: 'callback',
jsonp: "callback",
success: function (data) {
gg_results = data.items;
},
@ -43,15 +43,16 @@ $(document).ready(function () {
});
}
get_meta = function (source, id) {
function get_meta (source, id) {
var meta;
if (source == "google") {
var tags;
if (source === "google") {
meta = gg_results[id];
$("#description").val(meta.volumeInfo.description);
$("#bookAuthor").val(meta.volumeInfo.authors.join(' & '));
$("#bookAuthor").val(meta.volumeInfo.authors.join(" & "));
$("#book_title").val(meta.volumeInfo.title);
if (meta.volumeInfo.categories) {
var tags = meta.volumeInfo.categories.join(',');
tags = meta.volumeInfo.categories.join(",");
$("#tags").val(tags);
}
if (meta.volumeInfo.averageRating) {
@ -59,10 +60,10 @@ $(document).ready(function () {
}
return;
}
if (source == "douban") {
if (source === "douban") {
meta = db_results[id];
$("#description").val(meta.summary);
$("#bookAuthor").val(meta.author.join(' & '));
$("#bookAuthor").val(meta.author.join(" & "));
$("#book_title").val(meta.title);
var tags = '';
for (var i = 0; i < meta.tags.length; i++) {
@ -84,7 +85,7 @@ $(document).ready(function () {
}
db_search_book = function (title) {
var url = douban + db_search + '?q=' + title + '&fields=all&count=10';
var url = douban + dbSearch + '?q=' + title + '&fields=all&count=10';
$.ajax({
url: url,
type: "GET",
@ -97,18 +98,18 @@ $(document).ready(function () {
$('#meta-info').html('<p class="text-danger">'+ msg.search_error+'!</p>');
},
complete: function () {
db_done = true;
dbDone = true;
show_result();
}
});
}
show_result = function () {
function show_result () {
show_flag++;
if (show_flag == 1) {
$('#meta-info').html('<ul id="book-list" class="media-list"></ul>');
}
if (gg_done && db_done) {
if (gg_done && dbDone) {
if (!gg_results && !db_results) {
$('#meta-info').html('<p class="text-danger">'+ msg.no_result +'</p>');
return;
@ -140,7 +141,7 @@ $(document).ready(function () {
}
gg_done = false;
}
if (db_done && db_results.length > 0) {
if (dbDone && db_results.length > 0) {
for (var i = 0; i < db_results.length; i++) {
var book = db_results[i];
var book_html = '<li class="media">' +
@ -155,24 +156,24 @@ $(document).ready(function () {
'<p>' + msg.description + ':' + book.summary + '</p>' +
'<p>' + msg.source + ':<a href="https://book.douban.com" target="_blank">Douban Books</a></p>' +
'</div>' +
'</li>';
"</li>";
$("#book-list").append(book_html);
}
db_done = false;
dbDone = false;
}
}
$('#do-search').click(function () {
var keyword = $('#keyword').val();
$("#do-search").click(function () {
var keyword = $("#keyword").val();
if (keyword) {
do_search(keyword);
}
});
$('#get_meta').click(function () {
var book_title = $('#book_title').val();
$("#get_meta").click(function () {
var book_title = $("#book_title").val();
if (book_title) {
$('#keyword').val(book_title);
$("#keyword").val(book_title);
do_search(book_title);
}
});

@ -3,7 +3,7 @@ var updateTimerID;
var updateText;
$(function() {
$('.discover .row').isotope({
$(".discover .row").isotope({
// options
itemSelector : ".book",
layoutMode : "fitRows"
@ -20,28 +20,28 @@ $(function() {
extraScrollPx: 300,
// selector for all items you'll retrieve
}, function(data){
$(".load-more .row").isotope( 'appended', $(data), null );
$(".load-more .row").isotope( "appended", $(data), null );
});
$('#sendbtn').click(function(){
$("#sendbtn").click(function(){
var $this = $(this);
$this.text("Please wait...");
$this.addClass("disabled");
});
$("#restart").click(function() {
$.ajax({
dataType: 'json',
dataType: "json",
url: window.location.pathname+"/../../shutdown",
data: {"parameter":0},
success: function(data) {
$('#spinner').show();
$("#spinner").show();
displaytext=data.text;
setTimeout(restartTimer, 3000);}
});
});
$("#shutdown").click(function() {
$.ajax({
dataType: 'json',
dataType: "json",
url: window.location.pathname+"/../../shutdown",
data: {"parameter":1},
success: function(data) {
@ -50,13 +50,13 @@ $(function() {
});
$("#check_for_update").click(function() {
var button_text = $("#check_for_update").html();
$("#check_for_update").html('...');
$("#check_for_update").html("...");
$.ajax({
dataType: 'json',
dataType: "json",
url: window.location.pathname+"/../../get_update_status",
success: function(data) {
$("#check_for_update").html(button_text);
if (data.status == true) {
if (data.status === true) {
$("#check_for_update").addClass("hidden");
$("#perform_update").removeClass("hidden");
$("#update_info").removeClass("hidden");
@ -82,13 +82,12 @@ $(function() {
success: function(data) {
updateText=data.text;
$("#UpdateprogressDialog #Updatecontent").html(updateText[data.status]);
console.log(data.status);
// console.log(data.status);
updateTimerID=setInterval(updateTimer, 2000);}
});
});
});
function restartTimer() {
$("#spinner").hide();
$("#RestartDialog").modal("hide");
@ -103,10 +102,10 @@ function updateTimer() {
$("#UpdateprogressDialog #Updatecontent").html(updateText[data.status]);
if (data.status >6){
clearInterval(updateTimerID);
$('#spinner2').hide();
$('#UpdateprogressDialog #updateFinished').removeClass('hidden');
$("#check_for_update").removeClass('hidden');
$("#perform_update").addClass('hidden');
$("#spinner2").hide();
$("#UpdateprogressDialog #updateFinished").removeClass("hidden");
$("#check_for_update").removeClass("hidden");
$("#perform_update").addClass("hidden");
}
},
error: function() {

@ -1,4 +1,4 @@
Sortable.create(sortTrue, {
var sortable = Sortable.create(sortTrue, {
group: "sorting",
sort: true
});
@ -9,7 +9,7 @@ function sendData(path){
var maxElements;
var tmp=[];
elements=Sortable.utils.find(sortTrue,"div");
elements=sortable.utils.find(sortTrue,"div");
maxElements=elements.length;
var form = document.createElement("form");

@ -138,7 +138,7 @@
{% block js %}
<script>
var i18n_msg = {
var i18nMsg = {
'loading': {{_('Loading...')|safe|tojson}},
'search_error': {{_('Search error!')|safe|tojson}},
'no_result': {{_('No Result! Please try anonther keyword.')|safe|tojson}},

@ -508,7 +508,6 @@ def create_anonymous_user():
session.commit()
except Exception:
session.rollback()
pass
# Generate User admin with admin123 password, and access to everything
@ -525,7 +524,7 @@ def create_admin_user():
session.add(user)
try:
session.commit()
except Exception as e:
except Exception:
session.rollback()
pass

Loading…
Cancel
Save