Added "comments" type to supported custom columns

This commit is contained in:
Ozzie Isaacs 2021-05-13 14:00:01 +02:00
parent 380292a8aa
commit 6bf360fbfb
6 changed files with 42 additions and 30 deletions

View File

@ -59,7 +59,7 @@ except ImportError:
log = logger.create() log = logger.create()
cc_exceptions = ['comments', 'composite', 'series'] cc_exceptions = ['composite', 'series']
cc_classes = {} cc_classes = {}
Base = declarative_base() Base = declarative_base()
@ -473,7 +473,7 @@ class CalibreDB():
} }
books_custom_column_links[row.id] = type(str('books_custom_column_' + str(row.id) + '_link'), books_custom_column_links[row.id] = type(str('books_custom_column_' + str(row.id) + '_link'),
(Base,), dicttable) (Base,), dicttable)
else: if row.datatype in ['rating', 'text', 'enumeration']:
books_custom_column_links[row.id] = Table('books_custom_column_' + str(row.id) + '_link', books_custom_column_links[row.id] = Table('books_custom_column_' + str(row.id) + '_link',
Base.metadata, Base.metadata,
Column('book', Integer, ForeignKey('books.id'), Column('book', Integer, ForeignKey('books.id'),
@ -497,12 +497,12 @@ class CalibreDB():
ccdict['value'] = Column(Boolean) ccdict['value'] = Column(Boolean)
else: else:
ccdict['value'] = Column(String) 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')) ccdict['book'] = Column(Integer, ForeignKey('books.id'))
cc_classes[row.id] = type(str('custom_column_' + str(row.id)), (Base,), ccdict) cc_classes[row.id] = type(str('custom_column_' + str(row.id)), (Base,), ccdict)
for cc_id in cc_ids: 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, setattr(Books,
'custom_column_' + str(cc_id[0]), 'custom_column_' + str(cc_id[0]),
relationship(cc_classes[cc_id[0]], relationship(cc_classes[cc_id[0]],

View File

@ -495,7 +495,7 @@ def edit_book_publisher(publishers, book):
return changed 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 changed = False
if to_save[cc_string] == 'None': if to_save[cc_string] == 'None':
to_save[cc_string] = None to_save[cc_string] = None
@ -564,8 +564,8 @@ def edit_cc_data(book_id, book, to_save):
else: else:
cc_db_value = None cc_db_value = None
if to_save[cc_string].strip(): if to_save[cc_string].strip():
if c.datatype in ['int', 'bool', 'float', "datetime"]: if c.datatype in ['int', 'bool', 'float', "datetime", "comments"]:
changed, to_save = edit_cc_data_number(book_id, book, c, to_save, cc_db_value, cc_string) changed, to_save = edit_cc_data_value(book_id, book, c, to_save, cc_db_value, cc_string)
else: else:
changed, to_save = edit_cc_data_string(book, c, to_save, cc_db_value, cc_string) changed, to_save = edit_cc_data_string(book, c, to_save, cc_db_value, cc_string)
else: else:

View File

@ -10,8 +10,19 @@ if ($("#description").length) {
menubar: "edit view format", menubar: "edit view format",
language: language language: language
}); });
}
if (!Modernizr.inputtypes.date) { 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({ $("#pubdate").datepicker({
format: "yyyy-mm-dd", format: "yyyy-mm-dd",
language: language language: language
@ -26,9 +37,9 @@ if ($("#description").length) {
.removeClass("hidden"); .removeClass("hidden");
} }
}).trigger("change"); }).trigger("change");
}
} }
if (!Modernizr.inputtypes.date) { if (!Modernizr.inputtypes.date) {
$("#Publishstart").datepicker({ $("#Publishstart").datepicker({
format: "yyyy-mm-dd", format: "yyyy-mm-dd",

View File

@ -150,7 +150,6 @@
{% endif %} {% endif %}
{% if c.datatype == 'datetime' %} {% if c.datatype == 'datetime' %}
<div style="position: relative"> <div style="position: relative">
<input type="date" class="form-control" name="{{ 'custom_column_' ~ c.id }}" id="{{ 'custom_column_' ~ c.id }}" <input type="date" class="form-control" name="{{ 'custom_column_' ~ c.id }}" id="{{ 'custom_column_' ~ c.id }}"
{% if book['custom_column_' ~ c.id]|length > 0 %} {% if book['custom_column_' ~ c.id]|length > 0 %}
@ -163,7 +162,9 @@
</div> </div>
{% endif %} {% endif %}
{% if c.datatype == 'comments' %}
<textarea class="form-control tiny_editor" name="{{ 'custom_column_' ~ c.id }}" id="{{ 'custom_column_' ~ c.id }}" rows="7">{% if book['custom_column_' ~ c.id]|length > 0 %}{{book['custom_column_' ~ c.id][0].value}}{%endif%}</textarea>
{% endif %}
{% if c.datatype == 'enumeration' %} {% if c.datatype == 'enumeration' %}
<select class="form-control" name="{{ 'custom_column_' ~ c.id }}" id="{{ 'custom_column_' ~ c.id }}"> <select class="form-control" name="{{ 'custom_column_' ~ c.id }}" id="{{ 'custom_column_' ~ c.id }}">
<option></option> <option></option>

View File

@ -195,15 +195,15 @@
{{ column.value|formatfloat(2) }} {{ column.value|formatfloat(2) }}
{% elif c.datatype == 'datetime' %} {% elif c.datatype == 'datetime' %}
{{ column.value|formatdate }} {{ column.value|formatdate }}
{% else %} {% elif c.datatype == 'comments' %}
{% if c.datatype == 'series' %} {{column.value|safe}}
{% elif c.datatype == 'series' %}
{{ '%s [%s]' % (column.value, column.extra|formatfloat(2)) }} {{ '%s [%s]' % (column.value, column.extra|formatfloat(2)) }}
{% else %} {% else %}
{{ column.value }} {{ column.value }}
{% endif %} {% endif %}
{% endif %} {% endif %}
{% endif %} {% endif %}
{% endif %}
{% endfor %} {% endfor %}
{% endif %} {% endif %}
</div> </div>

View File

@ -186,7 +186,7 @@
</div> </div>
{% endif %} {% endif %}
{% if c.datatype in ['text', 'series'] and not c.is_multiple %} {% if c.datatype in ['text', 'series', 'comments'] and not c.is_multiple %}
<input type="text" class="form-control" name="{{ 'custom_column_' ~ c.id }}" id="{{ 'custom_column_' ~ c.id }}" value=""> <input type="text" class="form-control" name="{{ 'custom_column_' ~ c.id }}" id="{{ 'custom_column_' ~ c.id }}" value="">
{% endif %} {% endif %}