diff --git a/cps/db.py b/cps/db.py index 66c289dd..98ad5898 100644 --- a/cps/db.py +++ b/cps/db.py @@ -59,7 +59,7 @@ except ImportError: log = logger.create() -cc_exceptions = ['datetime', 'comments', 'composite', 'series'] +cc_exceptions = ['composite', 'series'] cc_classes = {} Base = declarative_base() @@ -473,7 +473,7 @@ class CalibreDB(): } books_custom_column_links[row.id] = type(str('books_custom_column_' + str(row.id) + '_link'), (Base,), dicttable) - else: + if row.datatype in ['rating', 'text', 'enumeration']: books_custom_column_links[row.id] = Table('books_custom_column_' + str(row.id) + '_link', Base.metadata, Column('book', Integer, ForeignKey('books.id'), @@ -491,23 +491,25 @@ class CalibreDB(): ccdict['value'] = Column(Float) elif row.datatype == 'int': ccdict['value'] = Column(Integer) + elif row.datatype == 'datetime': + ccdict['value'] = Column(TIMESTAMP) elif row.datatype == 'bool': ccdict['value'] = Column(Boolean) else: ccdict['value'] = Column(String) - if row.datatype in ['float', 'int', 'bool']: + if row.datatype in ['float', 'int', 'bool', 'datetime', 'comments']: ccdict['book'] = Column(Integer, ForeignKey('books.id')) cc_classes[row.id] = type(str('custom_column_' + str(row.id)), (Base,), ccdict) for cc_id in cc_ids: - if (cc_id[1] == 'bool') or (cc_id[1] == 'int') or (cc_id[1] == 'float'): + if cc_id[1] in ['bool', 'int', 'float', 'datetime', 'comments']: setattr(Books, 'custom_column_' + str(cc_id[0]), relationship(cc_classes[cc_id[0]], primaryjoin=( Books.id == cc_classes[cc_id[0]].book), backref='books')) - elif (cc_id[1] == 'series'): + elif cc_id[1] == 'series': setattr(Books, 'custom_column_' + str(cc_id[0]), relationship(books_custom_column_links[cc_id[0]], diff --git a/cps/editbooks.py b/cps/editbooks.py index e5ef0dee..5cebec80 100644 --- a/cps/editbooks.py +++ b/cps/editbooks.py @@ -504,12 +504,17 @@ def edit_book_publisher(publishers, book): return changed -def edit_cc_data_number(book_id, book, c, to_save, cc_db_value, cc_string): +def edit_cc_data_value(book_id, book, c, to_save, cc_db_value, cc_string): changed = False if to_save[cc_string] == 'None': to_save[cc_string] = None elif c.datatype == 'bool': to_save[cc_string] = 1 if to_save[cc_string] == 'True' else 0 + elif c.datatype == 'datetime': + try: + to_save[cc_string] = datetime.strptime(to_save[cc_string], "%Y-%m-%d") + except ValueError: + to_save[cc_string] = db.Books.DEFAULT_PUBDATE if to_save[cc_string] != cc_db_value: if cc_db_value is not None: @@ -568,8 +573,8 @@ def edit_cc_data(book_id, book, to_save): else: cc_db_value = None if to_save[cc_string].strip(): - if c.datatype == 'int' or c.datatype == 'bool' or c.datatype == 'float': - changed, to_save = edit_cc_data_number(book_id, book, c, to_save, cc_db_value, cc_string) + if c.datatype in ['int', 'bool', 'float', "datetime", "comments"]: + changed, to_save = edit_cc_data_value(book_id, book, c, to_save, cc_db_value, cc_string) else: changed, to_save = edit_cc_data_string(book, c, to_save, cc_db_value, cc_string) else: diff --git a/cps/kobo.py b/cps/kobo.py index 8988ef3f..085bf1bc 100644 --- a/cps/kobo.py +++ b/cps/kobo.py @@ -158,6 +158,7 @@ def HandleSyncRequest(): .filter(db.Books.last_modified >= sync_token.books_last_modified) .filter(db.Books.id>sync_token.books_last_id) .filter(db.Data.format.in_(KOBO_FORMATS)) + .filter(calibre_db.common_filters()) .order_by(db.Books.last_modified) .order_by(db.Books.id) .limit(SYNC_ITEM_LIMIT) @@ -168,6 +169,7 @@ def HandleSyncRequest(): .join(db.Data).outerjoin(ub.ArchivedBook, db.Books.id == ub.ArchivedBook.book_id) .filter(db.Books.last_modified > sync_token.books_last_modified) .filter(db.Data.format.in_(KOBO_FORMATS)) + .filter(calibre_db.common_filters()) .order_by(db.Books.last_modified) .order_by(db.Books.id) .limit(SYNC_ITEM_LIMIT) diff --git a/cps/static/js/edit_books.js b/cps/static/js/edit_books.js index 8cedf688..389a247f 100644 --- a/cps/static/js/edit_books.js +++ b/cps/static/js/edit_books.js @@ -10,25 +10,36 @@ if ($("#description").length) { menubar: "edit view format", language: language }); - - if (!Modernizr.inputtypes.date) { - $("#pubdate").datepicker({ - format: "yyyy-mm-dd", - language: language - }).on("change", function () { - // Show localized date over top of the standard YYYY-MM-DD date - var pubDate; - var results = /(\d{4})[-\/\\](\d{1,2})[-\/\\](\d{1,2})/.exec(this.value); // YYYY-MM-DD - if (results) { - pubDate = new Date(results[1], parseInt(results[2], 10) - 1, results[3]) || new Date(this.value); - $("#fake_pubdate") - .val(pubDate.toLocaleDateString(language)) - .removeClass("hidden"); - } - }).trigger("change"); - } } +if ($(".tiny_editor").length) { + tinymce.init({ + selector: ".tiny_editor", + branding: false, + menubar: "edit view format", + language: language + }); +} + +tiny_editor +if (!Modernizr.inputtypes.date) { + $("#pubdate").datepicker({ + format: "yyyy-mm-dd", + language: language + }).on("change", function () { + // Show localized date over top of the standard YYYY-MM-DD date + var pubDate; + var results = /(\d{4})[-\/\\](\d{1,2})[-\/\\](\d{1,2})/.exec(this.value); // YYYY-MM-DD + if (results) { + pubDate = new Date(results[1], parseInt(results[2], 10) - 1, results[3]) || new Date(this.value); + $("#fake_pubdate") + .val(pubDate.toLocaleDateString(language)) + .removeClass("hidden"); + } + }).trigger("change"); +} + + if (!Modernizr.inputtypes.date) { $("#Publishstart").datepicker({ format: "yyyy-mm-dd", @@ -63,6 +74,7 @@ if (!Modernizr.inputtypes.date) { }).trigger("change"); } + /* Takes a prefix, query typeahead callback, Bloodhound typeahead adapter and returns the completions it gets from the bloodhound engine prefixed. @@ -78,11 +90,6 @@ function prefixedSource(prefix, query, cb, bhAdapter) { }); } -/*function getPath() { - var jsFileLocation = $("script[src*=edit_books]").attr("src"); // the js file path - return jsFileLocation.substr(0, jsFileLocation.search("/static/js/edit_books.js")); // the js folder path -}*/ - var authors = new Bloodhound({ name: "authors", datumTokenizer: function datumTokenizer(datum) { diff --git a/cps/static/js/main.js b/cps/static/js/main.js index 927b65ac..ca9f3e14 100644 --- a/cps/static/js/main.js +++ b/cps/static/js/main.js @@ -533,7 +533,7 @@ $(function() { $("#pub_new").toggleClass("disabled"); $("#pub_old").toggleClass("disabled"); var alternative_text = $("#toggle_order_shelf").data('alt-text'); - $("#toggle_order_shelf")[0].attributes['data-alt-text'].value = $("#toggle_order_shelf").html(); + $("#toggle_order_shelf").data('alt-text', $("#toggle_order_shelf").html()); $("#toggle_order_shelf").html(alternative_text); }); diff --git a/cps/templates/book_edit.html b/cps/templates/book_edit.html index cc21cf52..b74a2f34 100644 --- a/cps/templates/book_edit.html +++ b/cps/templates/book_edit.html @@ -149,7 +149,22 @@ {% endif %}> {% endif %} + {% if c.datatype == 'datetime' %} +