diff --git a/cps/db.py b/cps/db.py index 66c289dd..808d8abe 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 = ['comments', 'composite', 'series'] cc_classes = {} Base = declarative_base() @@ -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']: 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']: 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 45e0f9fe..f231ab0d 100644 --- a/cps/editbooks.py +++ b/cps/editbooks.py @@ -501,6 +501,11 @@ def edit_cc_data_number(book_id, book, c, to_save, cc_db_value, cc_string): 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: @@ -559,7 +564,7 @@ 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': + if c.datatype in ['int', 'bool', 'float', "datetime"]: changed, to_save = edit_cc_data_number(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) diff --git a/cps/static/js/edit_books.js b/cps/static/js/edit_books.js index 8cedf688..fa3885bb 100644 --- a/cps/static/js/edit_books.js +++ b/cps/static/js/edit_books.js @@ -63,6 +63,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 +79,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/templates/book_edit.html b/cps/templates/book_edit.html index c0fc141e..daafc013 100644 --- a/cps/templates/book_edit.html +++ b/cps/templates/book_edit.html @@ -149,6 +149,20 @@ {% endif %}> {% endif %} + {% if c.datatype == 'datetime' %} + +