From 6bf360fbfb434232dd50b9bf6ca2264079bc807f Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Thu, 13 May 2021 14:00:01 +0200 Subject: [PATCH] Added "comments" type to supported custom columns --- cps/db.py | 8 +++--- cps/editbooks.py | 6 ++--- cps/static/js/edit_books.js | 45 +++++++++++++++++++++------------- cps/templates/book_edit.html | 5 ++-- cps/templates/detail.html | 6 ++--- cps/templates/search_form.html | 2 +- 6 files changed, 42 insertions(+), 30 deletions(-) diff --git a/cps/db.py b/cps/db.py index 808d8abe..98ad5898 100644 --- a/cps/db.py +++ b/cps/db.py @@ -59,7 +59,7 @@ except ImportError: log = logger.create() -cc_exceptions = ['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'), @@ -497,12 +497,12 @@ class CalibreDB(): ccdict['value'] = Column(Boolean) else: ccdict['value'] = Column(String) - if row.datatype in ['float', 'int', 'bool', 'datetime']: + 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] in ['bool', 'int', 'float', 'datetime']: + if cc_id[1] in ['bool', 'int', 'float', 'datetime', 'comments']: setattr(Books, 'custom_column_' + str(cc_id[0]), relationship(cc_classes[cc_id[0]], diff --git a/cps/editbooks.py b/cps/editbooks.py index f231ab0d..a155e029 100644 --- a/cps/editbooks.py +++ b/cps/editbooks.py @@ -495,7 +495,7 @@ 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 @@ -564,8 +564,8 @@ def edit_cc_data(book_id, book, to_save): else: cc_db_value = None if to_save[cc_string].strip(): - 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) + 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/static/js/edit_books.js b/cps/static/js/edit_books.js index fa3885bb..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", diff --git a/cps/templates/book_edit.html b/cps/templates/book_edit.html index daafc013..194a3248 100644 --- a/cps/templates/book_edit.html +++ b/cps/templates/book_edit.html @@ -150,7 +150,6 @@ {% endif %} {% if c.datatype == 'datetime' %} -
0 %} @@ -163,7 +162,9 @@
{% endif %} - + {% if c.datatype == 'comments' %} + + {% endif %} {% if c.datatype == 'enumeration' %} {% endif %}