diff --git a/cps/db.py b/cps/db.py index f5fbcbbf..c6e069e5 100755 --- a/cps/db.py +++ b/cps/db.py @@ -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) diff --git a/cps/epub.py b/cps/epub.py index 446efe9b..8d0b2817 100644 --- a/cps/epub.py +++ b/cps/epub.py @@ -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: diff --git a/cps/helper.py b/cps/helper.py index 68f1a296..577fa826 100755 --- a/cps/helper.py +++ b/cps/helper.py @@ -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 diff --git a/cps/static/js/edit_books.js b/cps/static/js/edit_books.js index e81a88b2..12199c0d 100644 --- a/cps/static/js/edit_books.js +++ b/cps/static/js/edit_books.js @@ -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"); } }); }); diff --git a/cps/static/js/get_meta.js b/cps/static/js/get_meta.js index e58e54bf..f9fa5b60 100644 --- a/cps/static/js/get_meta.js +++ b/cps/static/js/get_meta.js @@ -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('
'+ msg.search_error+'!
'); }, complete: function () { - db_done = true; + dbDone = true; show_result(); } }); } - show_result = function () { + function show_result () { show_flag++; if (show_flag == 1) { $('#meta-info').html(''+ msg.no_result +'
'); 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 = '' + msg.description + ':' + book.summary + '
' + '' + msg.source + ':Douban Books
' + '' + - '