mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
Handle unparse-able search expressions better
This commit is contained in:
parent
166697795f
commit
d95bf4d0ef
@ -112,7 +112,10 @@ def interface_data(ctx, rd):
|
|||||||
except Exception:
|
except Exception:
|
||||||
raise HTTPNotFound('Invalid number of books: %r' % rd.query.get('num'))
|
raise HTTPNotFound('Invalid number of books: %r' % rd.query.get('num'))
|
||||||
with db.safe_read_lock:
|
with db.safe_read_lock:
|
||||||
|
try:
|
||||||
ans['search_result'] = search_result(ctx, rd, db, rd.query.get('search', ''), num, 0, ','.join(sorts), ','.join(orders))
|
ans['search_result'] = search_result(ctx, rd, db, rd.query.get('search', ''), num, 0, ','.join(sorts), ','.join(orders))
|
||||||
|
except ParseException:
|
||||||
|
ans['search_result'] = search_result(ctx, rd, db, '', num, 0, ','.join(sorts), ','.join(orders))
|
||||||
sf = db.field_metadata.ui_sortable_field_keys()
|
sf = db.field_metadata.ui_sortable_field_keys()
|
||||||
sf.pop('ondevice', None)
|
sf.pop('ondevice', None)
|
||||||
ans['sortable_fields'] = sorted(((
|
ans['sortable_fields'] = sorted(((
|
||||||
@ -203,6 +206,8 @@ def get_books(ctx, rd):
|
|||||||
try:
|
try:
|
||||||
ans['search_result'] = search_result(ctx, rd, db, searchq, num, 0, ','.join(sorts), ','.join(orders))
|
ans['search_result'] = search_result(ctx, rd, db, searchq, num, 0, ','.join(sorts), ','.join(orders))
|
||||||
except ParseException as err:
|
except ParseException as err:
|
||||||
|
# This must not be translated as it is used by the front end to
|
||||||
|
# detect invalid search expressions
|
||||||
raise HTTPBadRequest('Invalid search expression: %s' % as_unicode(err))
|
raise HTTPBadRequest('Invalid search expression: %s' % as_unicode(err))
|
||||||
for book_id in ans['search_result']['book_ids']:
|
for book_id in ans['search_result']['book_ids']:
|
||||||
data = book_as_json(db, book_id)
|
data = book_as_json(db, book_id)
|
||||||
|
@ -253,7 +253,10 @@ class BooksView:
|
|||||||
boss.ui.close_panel()
|
boss.ui.close_panel()
|
||||||
window.scrollTo(0, 0)
|
window.scrollTo(0, 0)
|
||||||
elif end_type != 'abort':
|
elif end_type != 'abort':
|
||||||
error_dialog(_('Could not change search query'), xhr.error_html)
|
msg = xhr.error_html
|
||||||
|
if xhr.status == 400 and str.startswith(xhr.responseText, 'Invalid search expression:'):
|
||||||
|
msg = _('The search expression could not be parsed: ') + xhr.responseText
|
||||||
|
error_dialog(_('Could not change search query'), msg)
|
||||||
|
|
||||||
def refresh(self):
|
def refresh(self):
|
||||||
self.clear()
|
self.clear()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user