Improved validation check

pull/1539/head
Ozzieisaacs 5 years ago
parent f26ccfe16c
commit c18d5786dd

@ -294,7 +294,7 @@ class Data(Base):
class Books(Base): class Books(Base):
__tablename__ = 'books' __tablename__ = 'books'
DEFAULT_PUBDATE = "0101-01-01 00:00:00+00:00" DEFAULT_PUBDATE = datetime(101, 1, 1, 0, 0, 0, 0) # ("0101-01-01 00:00:00+00:00")
id = Column(Integer, primary_key=True, autoincrement=True) id = Column(Integer, primary_key=True, autoincrement=True)
title = Column(String(collation='NOCASE'), nullable=False, default='Unknown') title = Column(String(collation='NOCASE'), nullable=False, default='Unknown')

@ -911,20 +911,41 @@ def edit_list_book(param):
book.author_sort = vals['value'] book.author_sort = vals['value']
elif param =='title': elif param =='title':
book.title = vals['value'] book.title = vals['value']
helper.update_dir_stucture(book.id, config.config_calibre_dir)
elif param =='sort': elif param =='sort':
book.sort = vals['value'] book.sort = vals['value']
# ToDo: edit books # ToDo: edit books
elif param =='authors': elif param =='authors':
edit_book_languages(vals['value'], book) input_authors = vals['value'].split('&')
input_authors = list(map(lambda it: it.strip().replace(',', '|'), input_authors))
modify_database_object(input_authors, book.authors, db.Authors, calibre_db.session, 'author')
sort_authors_list = list()
for inp in input_authors:
stored_author = calibre_db.session.query(db.Authors).filter(db.Authors.name == inp).first()
if not stored_author:
stored_author = helper.get_sorted_author(inp)
else:
stored_author = stored_author.sort
sort_authors_list.append(helper.get_sorted_author(stored_author))
sort_authors = ' & '.join(sort_authors_list)
if book.author_sort != sort_authors:
book.author_sort = sort_authors
helper.update_dir_stucture(book.id, config.config_calibre_dir, input_authors[0])
book.last_modified = datetime.utcnow() book.last_modified = datetime.utcnow()
calibre_db.session.commit() calibre_db.session.commit()
return "" return ""
@editbook.route("/ajax/sort_value") @editbook.route("/ajax/sort_value/<field>/<int:bookid>")
@login_required @login_required
def get_sorted_entry(): def get_sorted_entry(field, bookid):
pass if field == 'title' or field == 'authors':
book = calibre_db.get_filtered_book(bookid)
if book:
if field == 'title':
return json.dumps({'sort': book.sort})
elif field == 'authors':
return json.dumps({'author_sort': book.author_sort})
return ''
@editbook.route("/ajax/deletebooks") @editbook.route("/ajax/deletebooks")
@login_required @login_required

@ -76,12 +76,14 @@ $(function() {
} }
column.push(element); column.push(element);
}); });
$("#books-table").bootstrapTable({ $("#books-table").bootstrapTable({
sidePagination: "server", sidePagination: "server",
pagination: true, pagination: true,
paginationDetailHAlign: " hidden", paginationDetailHAlign: " hidden",
paginationHAlign: "left", paginationHAlign: "left",
idField: "id", idField: "id",
uniqueId: "id",
search: true, search: true,
showColumns: true, showColumns: true,
searchAlign: "left", searchAlign: "left",
@ -94,7 +96,46 @@ $(function() {
formatNoMatches: function () { formatNoMatches: function () {
return ""; return "";
}, },
onEditableSave: function (field, row, oldvalue, $el) {
if (field === 'title' || field === 'authors') {
$.ajax({
method:"get",
dataType: "json",
url: window.location.pathname + "/../../ajax/sort_value/" + field + '/' + row.id,
success: function success(data) {
var key = Object.keys(data)[0]
$("#books-table").bootstrapTable('updateCellByUniqueId', {
id: row.id,
field: key,
value: data[key]
})
console.log(data);
}
}); });
}
},
onColumnSwitch: function (field, checked) {
var visible = $("#books-table").bootstrapTable('getVisibleColumns');
var hidden = $("#books-table").bootstrapTable('getHiddenColumns');
$.ajax({
method:"post",
contentType: "application/json; charset=utf-8",
dataType: "json",
url: window.location.pathname + "/../../ajax/table_settings",
data: JSON.stringify({"Merge_books":selections}),
success: function success() {
// ToDo:
}
});
}
});
// to save current setting
// coresponding event: onColumnSwitch
//$table.bootstrapTable('getVisibleColumns')
//$table.bootstrapTable('getHiddenColumns').
$("#domain_allow_submit").click(function(event) { $("#domain_allow_submit").click(function(event) {
event.preventDefault(); event.preventDefault();
@ -194,10 +235,6 @@ $(function() {
<div id="flash_success" class="alert alert-success">{{ message[1] }}</div> <div id="flash_success" class="alert alert-success">{{ message[1] }}</div>
</div>*/ </div>*/
// to save current setting
// coresponding event: onColumnSwitch
//$table.bootstrapTable('getVisibleColumns')
//$table.bootstrapTable('getHiddenColumns').
$("#restrictModal").on("hidden.bs.modal", function () { $("#restrictModal").on("hidden.bs.modal", function () {
// Destroy table and remove hooks for buttons // Destroy table and remove hooks for buttons

@ -17,27 +17,10 @@
{% endblock %} {% endblock %}
{% block body %} {% block body %}
<h2 class="{{page}}">{{_(title)}}</h2> <h2 class="{{page}}">{{_(title)}}</h2>
<!--table id="table1"></table-->
<!--a href="{{url_for('editbook.merge_list_book')}}" class="btn btn-default disabled" id="merge_book" role="button" aria-disabled="true">{{_('Merge selected books')}}
data-side-pagination="server"
data-pagination="true"
data-pagination-detail-h-align=" hidden"
data-pagination-h-align="left"
id="books-table"
data-id-field="id"
data-editable-mode="inline"
data-show-columns="true"
data-search="true"
data-search-align="left"
data-show-search-button="false"
data-search-on-enter-key="true"
data-checkbox-header="false"
data-maintain-meta-data="true"
data-response-handler="responseHandler"
data-editable-emptytext="<span class='glyphicon glyphicon-plus'></span>"
</a-->
<div class="btn btn-default disabled" id="merge_books" aria-disabled="true">{{_('Merge selected books')}}</div> <div class="btn btn-default disabled" id="merge_books" aria-disabled="true">{{_('Merge selected books')}}</div>
<div class="btn btn-default" id="delete_selection" aria-disabled="false">{{_('Remove Selections')}}</div>
<div class="btn btn-default" id="autoupdate_titlesort" aria-disabled="false">{{_('Update Title Sort automatically')}}</div>
<div class="btn btn-default" id="autoupdate_autorsort" aria-disabled="false">{{_('Update Author Sort automatically')}}</div>
<table id="books-table" class="table table-no-bordered table-striped" <table id="books-table" class="table table-no-bordered table-striped"
data-url="{{url_for('web.list_books')}}"> data-url="{{url_for('web.list_books')}}">
<thead> <thead>
@ -47,14 +30,14 @@
{% endif %} {% endif %}
<th data-field="id" id="id" data-visible="false" data-switchable="false"></th> <th data-field="id" id="id" data-visible="false" data-switchable="false"></th>
{{ text_table_row('title', _('Enter Title'),_('Title'), true) }} {{ text_table_row('title', _('Enter Title'),_('Title'), true) }}
{{ text_table_row('sort', _('Enter Titlesort'),_('Sort'), false) }} {{ text_table_row('sort', _('Enter Title Sort'),_('Title Sort'), false) }}
{{ text_table_row('author_sort', _('Enter Authorsort'),_('Authors Sort'), false) }} {{ text_table_row('author_sort', _('Enter Author Sort'),_('Author Sort'), false) }}
{{ text_table_row('authors', _('Enter Authors'),_('Authors'), false) }} {{ text_table_row('authors', _('Enter Authors'),_('Authors'), true) }}
{{ text_table_row('tags', _('Enter Tags'),_('Tags'), false) }} {{ text_table_row('tags', _('Enter Categories'),_('Categories'), false) }}
{{ text_table_row('series', _('Enter Series'),_('Series'), false) }} {{ text_table_row('series', _('Enter Series'),_('Series'), false) }}
<th data-field="series_index" id="series_index" data-sortable="true" {% if g.user.role_edit() %} data-editable-type="number" data-editable-placeholder="1" data-editable-step="0.01" data-editable-min="0" data-editable-url="{{ url_for('editbook.edit_list_book', param='series_index')}}" data-editable="true" data-editable-title="{{_('Enter title')}}"{% endif %}>{{_('Series Index')}}</th> <th data-field="series_index" id="series_index" data-edit-validate="{{ _('This Field is Required') }}" data-sortable="true" {% if g.user.role_edit() %} data-editable-type="number" data-editable-placeholder="1" data-editable-step="0.01" data-editable-min="0" data-editable-url="{{ url_for('editbook.edit_list_book', param='series_index')}}" data-edit="true" data-editable-title="{{_('Enter title')}}"{% endif %}>{{_('Series Index')}}</th>
{{ text_table_row('languages', _('Enter Languages'),_('Languages'), false) }} {{ text_table_row('languages', _('Enter Languages'),_('Languages'), false) }}
<th data-field="pubdate" data-type="date" data-viewformat="dd.mm.yyyy" id="pubdate" data-sortable="true">_('Publishing Date')</th> <th data-field="pubdate" data-type="date" data-viewformat="dd.mm.yyyy" id="pubdate" data-sortable="true">{{_('Publishing Date')}}</th>
{{ text_table_row('publishers', _('Enter Publishers'),_('Publishers'), false) }} {{ text_table_row('publishers', _('Enter Publishers'),_('Publishers'), false) }}
{% if g.user.role_edit() %} {% if g.user.role_edit() %}
<th data-align="right" data-formatter="EbookActions" data-switchable="false"></th> <th data-align="right" data-formatter="EbookActions" data-switchable="false"></th>

@ -865,6 +865,11 @@ def list_books():
response.headers["Content-Type"] = "application/json; charset=utf-8" response.headers["Content-Type"] = "application/json; charset=utf-8"
return response return response
@web.route("/ajax/table_settings")
@login_required
def update_table_settings():
# ToDo: Save table settings
pass
@web.route("/author") @web.route("/author")
@login_required_if_no_ano @login_required_if_no_ano

Loading…
Cancel
Save