mirror of
https://github.com/janeczku/calibre-web
synced 2024-12-25 09:30:31 +00:00
add support for is_multiple custom columns
This commit is contained in:
parent
3f1a54ea59
commit
b2146ba4b9
@ -47,11 +47,17 @@
|
||||
{% for c in cc %}
|
||||
<div class="form-group">
|
||||
<label for="{{ 'custom_column_' ~ c.id }}">{{ c.name }}</label>
|
||||
{% if c.datatype in ['text', 'series'] %}
|
||||
{% if c.datatype in ['text', 'series'] and not c.is_multiple %}
|
||||
<input type="text" class="form-control" name="{{ 'custom_column_' ~ c.id }}" id="{{ 'custom_column_' ~ c.id }}"
|
||||
{% if book['custom_column_' ~ c.id]|length > 0 %}
|
||||
{% for column in book['custom_column_' ~ c.id] %}
|
||||
value="{{ column.value }}{% if not loop.last %}, {% endif %}{% endfor %}"{% endif %}>
|
||||
value="{{ book['custom_column_' ~ c.id][0].value }}"
|
||||
{% endif %}>
|
||||
{% endif %}
|
||||
|
||||
{% if c.datatype in ['text', 'series'] and c.is_multiple %}
|
||||
<input type="text" class="form-control" name="{{ 'custom_column_' ~ c.id }}" id="{{ 'custom_column_' ~ c.id }}"
|
||||
{% if book['custom_column_' ~ c.id]|length > 0 %}
|
||||
value="{% for column in book['custom_column_' ~ c.id] %}{{ column.value.strip() }}{% if not loop.last %}, {% endif %}{% endfor %}"{% endif %}>
|
||||
{% endif %}
|
||||
|
||||
{% if c.datatype == 'enumeration' %}
|
||||
|
46
cps/web.py
46
cps/web.py
@ -840,6 +840,7 @@ def edit_book(book_id):
|
||||
|
||||
for c in cc:
|
||||
cc_string = "custom_column_" + str(c.id)
|
||||
if not c.is_multiple:
|
||||
if len(getattr(book, cc_string)) > 0:
|
||||
cc_db_value = getattr(book, cc_string)[0].value
|
||||
else:
|
||||
@ -871,6 +872,51 @@ def edit_book(book_id):
|
||||
getattr(book, cc_string).remove(del_cc)
|
||||
if len(del_cc.books) == 0:
|
||||
db.session.delete(del_cc)
|
||||
else:
|
||||
input_tags = to_save[cc_string].split(',')
|
||||
input_tags = map(lambda it: it.strip(), input_tags)
|
||||
input_tags = [x for x in input_tags if x != '']
|
||||
# we have all author names now
|
||||
# 1. search for tags to remove
|
||||
del_tags = []
|
||||
for c_tag in getattr(book, cc_string):
|
||||
found = False
|
||||
for inp_tag in input_tags:
|
||||
if inp_tag == c_tag.value:
|
||||
found = True
|
||||
break;
|
||||
# if the tag was not found in the new list, add him to remove list
|
||||
if not found:
|
||||
del_tags.append(c_tag)
|
||||
# 2. search for tags that need to be added
|
||||
add_tags = []
|
||||
for inp_tag in input_tags:
|
||||
found = False
|
||||
for c_tag in getattr(book, cc_string):
|
||||
if inp_tag == c_tag.value:
|
||||
found = True
|
||||
break;
|
||||
if not found:
|
||||
add_tags.append(inp_tag)
|
||||
# if there are tags to remove, we remove them now
|
||||
if len(del_tags) > 0:
|
||||
for del_tag in del_tags:
|
||||
getattr(book, cc_string).remove(del_tag)
|
||||
if len(del_tag.books) == 0:
|
||||
db.session.delete(del_tag)
|
||||
# if there are tags to add, we add them now!
|
||||
if len(add_tags) > 0:
|
||||
for add_tag in add_tags:
|
||||
# check if a tag with that name exists
|
||||
new_tag = db.session.query(db.cc_classes[c.id]).filter(db.cc_classes[c.id].value == add_tag).first()
|
||||
# if no tag is found add it
|
||||
if new_tag == None:
|
||||
print add_tag
|
||||
new_tag = db.cc_classes[c.id](value=add_tag)
|
||||
db.session.add(new_tag)
|
||||
new_tag = db.session.query(db.cc_classes[c.id]).filter(db.cc_classes[c.id].value == add_tag).first()
|
||||
# add tag to book
|
||||
getattr(book, cc_string).append(new_tag)
|
||||
|
||||
db.session.commit()
|
||||
author_names = []
|
||||
|
Loading…
Reference in New Issue
Block a user