From 1e1d3a7c81fbf12921303c3108feb6b673b8d474 Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Sun, 17 Oct 2021 14:05:18 +0200 Subject: [PATCH] Enable edit of enum column in books list --- cps/editbooks.py | 28 +++++++++++----------------- cps/templates/book_table.html | 4 +++- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/cps/editbooks.py b/cps/editbooks.py index e44d30c5..9ad39373 100644 --- a/cps/editbooks.py +++ b/cps/editbooks.py @@ -1088,23 +1088,17 @@ def convert_bookformat(book_id): flash(_(u"There was an error converting this book: %(res)s", res=rtn), category="error") return redirect(url_for('editbook.edit_book', book_id=book_id)) -@editbook.route("/scholarsearch/",methods=['GET']) -@login_required_if_no_ano -@edit_required -def scholar_search(query): - if have_scholar: - scholar_gen = scholarly.search_pubs(' '.join(query.split('+'))) - i=0 - result = [] - for publication in scholar_gen: - del publication['source'] - result.append(publication) - i+=1 - if(i>=10): - break - return Response(json.dumps(result),mimetype='application/json') - else: - return "[]" +@editbook.route("/ajax/getcustomenum/") +@login_required +def table_get_custom_enum(c_id): + ret = list() + cc = (calibre_db.session.query(db.Custom_Columns) + .filter(db.Custom_Columns.id == c_id) + .filter(db.Custom_Columns.datatype.notin_(db.cc_exceptions)).one_or_none()) + for idx, en in enumerate(cc.get_display_dict()['enum_values']): + ret.append({'value': en, 'text': en}) + return json.dumps(ret) + @editbook.route("/ajax/editbooks/", methods=['POST']) @login_required_if_no_ano diff --git a/cps/templates/book_table.html b/cps/templates/book_table.html index 3722d6c1..b565ec75 100644 --- a/cps/templates/book_table.html +++ b/cps/templates/book_table.html @@ -63,9 +63,11 @@ {% if c.datatype == "int" %} {{c.name}} {% elif c.datatype == "rating" %} - {{c.name}} + {{c.name}} {% elif c.datatype == "float" %} {{c.name}} + {% elif c.datatype == "enumeration" %} + {{c.name}} {% else %} {% endif %}