From c18d5786dd7cd96f7c884c361ada37640b493a96 Mon Sep 17 00:00:00 2001 From: Ozzieisaacs Date: Fri, 12 Jun 2020 13:45:07 +0200 Subject: [PATCH] Improved validation check --- cps/db.py | 2 +- cps/editbooks.py | 31 ++++++++++++++++++++---- cps/static/js/table.js | 45 +++++++++++++++++++++++++++++++---- cps/templates/book_table.html | 35 +++++++-------------------- cps/web.py | 5 ++++ 5 files changed, 82 insertions(+), 36 deletions(-) diff --git a/cps/db.py b/cps/db.py index 51182a6d..0ed89467 100644 --- a/cps/db.py +++ b/cps/db.py @@ -294,7 +294,7 @@ class Data(Base): class Books(Base): __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) title = Column(String(collation='NOCASE'), nullable=False, default='Unknown') diff --git a/cps/editbooks.py b/cps/editbooks.py index 70577771..8ce54267 100644 --- a/cps/editbooks.py +++ b/cps/editbooks.py @@ -911,20 +911,41 @@ def edit_list_book(param): book.author_sort = vals['value'] elif param =='title': book.title = vals['value'] + helper.update_dir_stucture(book.id, config.config_calibre_dir) elif param =='sort': book.sort = vals['value'] # ToDo: edit books 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() calibre_db.session.commit() return "" -@editbook.route("/ajax/sort_value") +@editbook.route("/ajax/sort_value//") @login_required -def get_sorted_entry(): - pass +def get_sorted_entry(field, bookid): + 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") @login_required diff --git a/cps/static/js/table.js b/cps/static/js/table.js index 949f93f2..2d3f0774 100644 --- a/cps/static/js/table.js +++ b/cps/static/js/table.js @@ -76,12 +76,14 @@ $(function() { } column.push(element); }); + $("#books-table").bootstrapTable({ sidePagination: "server", pagination: true, paginationDetailHAlign: " hidden", paginationHAlign: "left", idField: "id", + uniqueId: "id", search: true, showColumns: true, searchAlign: "left", @@ -94,8 +96,47 @@ $(function() { formatNoMatches: function () { 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) { event.preventDefault(); $("#domain_add_allow").ajaxForm(); @@ -194,10 +235,6 @@ $(function() {
{{ message[1] }}
*/ - // to save current setting - // coresponding event: onColumnSwitch - //$table.bootstrapTable('getVisibleColumns') - //$table.bootstrapTable('getHiddenColumns'). $("#restrictModal").on("hidden.bs.modal", function () { // Destroy table and remove hooks for buttons diff --git a/cps/templates/book_table.html b/cps/templates/book_table.html index ee349c05..c0065b78 100644 --- a/cps/templates/book_table.html +++ b/cps/templates/book_table.html @@ -17,27 +17,10 @@ {% endblock %} {% block body %}

{{_(title)}}

- -
{{_('Merge selected books')}}
+
{{_('Remove Selections')}}
+
{{_('Update Title Sort automatically')}}
+
{{_('Update Author Sort automatically')}}
@@ -47,14 +30,14 @@ {% endif %} {{ text_table_row('title', _('Enter Title'),_('Title'), true) }} - {{ text_table_row('sort', _('Enter Titlesort'),_('Sort'), false) }} - {{ text_table_row('author_sort', _('Enter Authorsort'),_('Authors Sort'), false) }} - {{ text_table_row('authors', _('Enter Authors'),_('Authors'), false) }} - {{ text_table_row('tags', _('Enter Tags'),_('Tags'), false) }} + {{ text_table_row('sort', _('Enter Title Sort'),_('Title Sort'), false) }} + {{ text_table_row('author_sort', _('Enter Author Sort'),_('Author Sort'), false) }} + {{ text_table_row('authors', _('Enter Authors'),_('Authors'), true) }} + {{ text_table_row('tags', _('Enter Categories'),_('Categories'), false) }} {{ text_table_row('series', _('Enter Series'),_('Series'), false) }} - + {{ text_table_row('languages', _('Enter Languages'),_('Languages'), false) }} - + {{ text_table_row('publishers', _('Enter Publishers'),_('Publishers'), false) }} {% if g.user.role_edit() %} diff --git a/cps/web.py b/cps/web.py index 1f47e7c2..6a3aa7f2 100644 --- a/cps/web.py +++ b/cps/web.py @@ -865,6 +865,11 @@ def list_books(): response.headers["Content-Type"] = "application/json; charset=utf-8" return response +@web.route("/ajax/table_settings") +@login_required +def update_table_settings(): + # ToDo: Save table settings + pass @web.route("/author") @login_required_if_no_ano
{{_('Series Index')}}{{_('Series Index')}}_('Publishing Date'){{_('Publishing Date')}}