Code cosmetics

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

@ -57,7 +57,7 @@ def get_epub_info(tmp_file_path, original_file_name, original_file_extension):
epub_metadata['description'] = "" epub_metadata['description'] = ""
if epub_metadata['language'] == "Unknown": if epub_metadata['language'] == "Unknown":
epub_metadata['language'] == "" epub_metadata['language'] = ""
else: else:
lang = epub_metadata['language'].split('-', 1)[0].lower() lang = epub_metadata['language'].split('-', 1)[0].lower()
if len(lang) == 2: if len(lang) == 2:

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

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

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

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

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

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

Loading…
Cancel
Save