diff --git a/cps.py b/cps.py index 180be500..523246b2 100755 --- a/cps.py +++ b/cps.py @@ -22,7 +22,7 @@ except ImportError: if __name__ == '__main__': if web.ub.DEVELOPMENT: - web.app.run(host="0.0.0.0", port=web.ub.config.config_port, debug=True) + web.app.run(port=web.ub.config.config_port, debug=True) else: if gevent_present: web.app.logger.info('Attempting to start gevent') diff --git a/cps/helper.py b/cps/helper.py index 7f561319..71cacd74 100755 --- a/cps/helper.py +++ b/cps/helper.py @@ -13,6 +13,7 @@ import os import traceback import re import unicodedata + try: from StringIO import StringIO from email.MIMEBase import MIMEBase diff --git a/cps/static/js/edit_books.js b/cps/static/js/edit_books.js index 07d25148..810869a5 100644 --- a/cps/static/js/edit_books.js +++ b/cps/static/js/edit_books.js @@ -8,7 +8,7 @@ Takes a prefix, query typeahead callback, Bloodhound typeahead adapter and returns the completions it gets from the bloodhound engine prefixed. */ -function prefixed_source(prefix, query, cb, bhAdapter) { +function prefixedSource(prefix, query, cb, bhAdapter) { bhAdapter(query, function(retArray){ var matches = []; for (var i = 0; i < retArray.length; i++) { @@ -18,7 +18,7 @@ function prefixed_source(prefix, query, cb, bhAdapter) { cb(matches); }); } -function get_path(){ +function getPath(){ 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; @@ -31,7 +31,7 @@ var authors = new Bloodhound({ }, queryTokenizer: Bloodhound.tokenizers.whitespace, remote: { - url: get_path()+"/get_authors_json?q=%QUERY" + url: getPath()+"/get_authors_json?q=%QUERY" } }); @@ -44,7 +44,7 @@ var series = new Bloodhound({ return [query]; }, remote: { - url: get_path()+"/get_series_json?q=", + url: getPath()+"/get_series_json?q=", replace: function(url, query) { return url+encodeURIComponent(query); } @@ -63,7 +63,7 @@ var tags = new Bloodhound({ return tokens; }, remote: { - url: get_path()+"/get_tags_json?q=%QUERY" + url: getPath()+"/get_tags_json?q=%QUERY" } }); @@ -76,10 +76,9 @@ var languages = new Bloodhound({ return [query]; }, remote: { - url: get_path()+"/get_languages_json?q=", + url: getPath()+"/get_languages_json?q=", replace: function(url, query) { - url_query = url+encodeURIComponent(query); - return url_query; + return url+encodeURIComponent(query); } } }); @@ -101,7 +100,7 @@ function sourceSplit(query, cb, split, source) { for (var i = 0; i < tokens.length; i++) { prefix += tokens[i].trim() + newSplit; } - prefixed_source(prefix, currentSource, cb, bhAdapter); + prefixedSource(prefix, currentSource, cb, bhAdapter); } var promiseAuthors = authors.initialize(); @@ -130,7 +129,7 @@ var promiseSeries = series.initialize(); displayKey: "name", source: series.ttAdapter() } - ) + ); }); var promiseTags = tags.initialize(); @@ -165,7 +164,7 @@ var promiseLanguages = languages.initialize(); $("form").on("change input typeahead:selected", function(data){ var form = $("form").serialize(); - $.getJSON( get_path()+"/get_matching_tags", form, function( data ) { + $.getJSON( getPath()+"/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"))) { diff --git a/cps/static/js/get_meta.js b/cps/static/js/get_meta.js index 583abea2..316d2651 100644 --- a/cps/static/js/get_meta.js +++ b/cps/static/js/get_meta.js @@ -9,36 +9,95 @@ $(document).ready(function () { var msg = i18nMsg; var douban = "https://api.douban.com"; var dbSearch = "/v2/book/search"; - var db_get_info = "/v2/book/"; - var db_get_info_by_isbn = "/v2/book/isbn/ "; + // var dbGetInfo = "/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 gg_done = false; + var ggSearch = "/books/v1/volumes"; + // var gg_get_info = "/books/v1/volumes/"; + var ggDone = false; - var db_results = []; - var gg_results = []; - var show_flag = 0; - String.prototype.replaceAll = function (s1, s2) { + var dbResults = []; + var ggResults = []; + var showFlag = 0; + String.prototype.replaceAll = function (s1, s2) { return this.replace(new RegExp(s1, "gm"), s2); }; - function gg_search_book (title) { + function showResult () { + showFlag++; + if (showFlag === 1) { + $("#meta-info").html('
'+ msg.no_result +"
"); + return; + } + } + if (ggDone && ggResults.length > 0) { + for (var i = 0; i < ggResults.length; i++) { + var book = ggResults[i]; + var bookCover; + if (book.volumeInfo.imageLinks) { + bookCover = book.volumeInfo.imageLinks.thumbnail; + } else { + bookCover = "/static/generic_cover.jpg"; + } + var bookHtml = '"+ msg.author +":" + book.volumeInfo.authors + "
" + + ""+ msg.publisher + ":" + book.volumeInfo.publisher + "
" + + ""+ msg.description + ":" + book.volumeInfo.description + "
" + + ""+ msg.source + ':Google Books
' + + "" + msg.author + ":" + book.author + "
" + + "" + msg.publisher + ":" + book.publisher + "
" + + "" + msg.description + ":" + book.summary + "
" + + "" + msg.source + ':Douban Books
' + + "'+ msg.no_result +'
'); - return; - } - } - if (gg_done && gg_results.length > 0) { - for (var i = 0; i < gg_results.length; i++) { - var book = gg_results[i]; - var book_cover; - if (book.volumeInfo.imageLinks) { - book_cover = book.volumeInfo.imageLinks.thumbnail; - } else { - book_cover = '/static/generic_cover.jpg'; - } - var book_html = ''+ msg.author +':' + book.volumeInfo.authors + '
' + - ''+ msg.publisher + ':' + book.volumeInfo.publisher + '
' + - ''+ msg.description + ':' + book.volumeInfo.description + '
' + - ''+ msg.source + ':Google Books
' + - '' + msg.author + ':' + book.author + '
' + - '' + msg.publisher + ':' + book.publisher + '
' + - '' + msg.description + ':' + book.summary + '
' + - '' + msg.source + ':Douban Books
' + - ''+ msg.search_error+'!
'); + $("#meta-info").html(''+ msg.search_error+"!
"); }, complete: function () { dbDone = true; - show_result(); + showResult(); } }); } @@ -167,15 +167,15 @@ $(document).ready(function () { $("#do-search").click(function () { var keyword = $("#keyword").val(); if (keyword) { - do_search(keyword); + doSearch(keyword); } }); $("#get_meta").click(function () { - var book_title = $("#book_title").val(); - if (book_title) { - $("#keyword").val(book_title); - do_search(book_title); + var bookTitle = $("#book_title").val(); + if (bookTitle) { + $("#keyword").val(bookTitle); + doSearch(bookTitle); } }); diff --git a/cps/static/js/main.js b/cps/static/js/main.js index 8494973f..10e4dc08 100644 --- a/cps/static/js/main.js +++ b/cps/static/js/main.js @@ -49,13 +49,13 @@ $(function() { }); }); $("#check_for_update").click(function() { - var button_text = $("#check_for_update").html(); + var buttonText = $("#check_for_update").html(); $("#check_for_update").html("..."); $.ajax({ dataType: "json", url: window.location.pathname+"/../../get_update_status", success: function(data) { - $("#check_for_update").html(button_text); + $("#check_for_update").html(buttonText); if (data.status === true) { $("#check_for_update").addClass("hidden"); $("#perform_update").removeClass("hidden"); @@ -67,7 +67,7 @@ $(function() { }); $("#restart_database").click(function() { $.ajax({ - dataType: 'json', + dataType: "json", url: window.location.pathname+"/../../shutdown", data: {"parameter":2} }); @@ -76,7 +76,7 @@ $(function() { $("#spinner2").show(); $.ajax({ type: "POST", - dataType: 'json', + dataType: "json", data: { start: "True"}, url: window.location.pathname+"/../../get_updater_status", success: function(data) { @@ -94,10 +94,10 @@ $(function() { function updateTimer() { $.ajax({ - dataType: 'json', + dataType: "json", url: window.location.pathname+"/../../get_updater_status", success: function(data) { - console.log(data.status); + // console.log(data.status); $("#UpdateprogressDialog #Updatecontent").html(updateText[data.status]); if (data.status >6){ clearInterval(updateTimerID); diff --git a/cps/templates/book_edit.html b/cps/templates/book_edit.html index 165512c7..b94ddbb2 100644 --- a/cps/templates/book_edit.html +++ b/cps/templates/book_edit.html @@ -106,7 +106,7 @@ {{_('Get metadata')}} - {{_('Back')}} + {{_('Back')}} {% endif %} diff --git a/cps/templates/detail.html b/cps/templates/detail.html index e0a7ef01..44fc8f55 100644 --- a/cps/templates/detail.html +++ b/cps/templates/detail.html @@ -15,7 +15,7 @@{{_('Book')}} {{entry.series_index}} {{_('of')}} {{entry.series[0].name}}
+{{_('Book')}} {{entry.series_index}} {{_('of')}} {{entry.series[0].name}}
{% endif %} {% if entry.languages.__len__() > 0 %} @@ -65,7 +65,7 @@ {% for tag in entry.tags %} - {{tag.name}} + {{tag.name}} {%endfor%} @@ -110,7 +110,7 @@ {% if not g.user.is_anonymous() %}