mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 02:34:06 -04:00
Languages edit widget for EM page
This commit is contained in:
parent
c088f7e818
commit
d543c10f12
@ -27,7 +27,7 @@ from calibre.srv.routes import endpoint, json
|
|||||||
from calibre.srv.utils import get_library_data, get_use_roman
|
from calibre.srv.utils import get_library_data, get_use_roman
|
||||||
from calibre.utils.config import prefs, tweaks
|
from calibre.utils.config import prefs, tweaks
|
||||||
from calibre.utils.icu import sort_key, numeric_sort_key
|
from calibre.utils.icu import sort_key, numeric_sort_key
|
||||||
from calibre.utils.localization import get_lang
|
from calibre.utils.localization import get_lang, lang_map_for_ui
|
||||||
from calibre.utils.search_query_parser import ParseException
|
from calibre.utils.search_query_parser import ParseException
|
||||||
|
|
||||||
POSTABLE = frozenset({'GET', 'POST', 'HEAD'})
|
POSTABLE = frozenset({'GET', 'POST', 'HEAD'})
|
||||||
@ -387,11 +387,22 @@ def tag_browser(ctx, rd):
|
|||||||
return rd.etagged_dynamic_response(etag, generate)
|
return rd.etagged_dynamic_response(etag, generate)
|
||||||
|
|
||||||
|
|
||||||
|
def all_lang_names():
|
||||||
|
ans = getattr(all_lang_names, 'ans', None)
|
||||||
|
if ans is None:
|
||||||
|
ans = all_lang_names.ans = tuple(sorted(lang_map_for_ui().itervalues(), key=numeric_sort_key))
|
||||||
|
return ans
|
||||||
|
|
||||||
|
|
||||||
@endpoint('/interface-data/field-names/{field}', postprocess=json)
|
@endpoint('/interface-data/field-names/{field}', postprocess=json)
|
||||||
def field_names(ctx, rd, field):
|
def field_names(ctx, rd, field):
|
||||||
'''
|
'''
|
||||||
Get a list of all names for the specified field
|
Get a list of all names for the specified field
|
||||||
Optional: ?library_id=<default library>
|
Optional: ?library_id=<default library>
|
||||||
'''
|
'''
|
||||||
|
if field == 'languages':
|
||||||
|
ans = all_lang_names()
|
||||||
|
else:
|
||||||
db, library_id = get_library_data(ctx, rd)[:2]
|
db, library_id = get_library_data(ctx, rd)[:2]
|
||||||
return tuple(sorted(db.all_field_names(field), key=numeric_sort_key))
|
ans = tuple(sorted(db.all_field_names(field), key=numeric_sort_key))
|
||||||
|
return ans
|
||||||
|
@ -256,6 +256,8 @@ def multiple_line_edit(list_to_ui, ui_to_list, container_id, book_id, field, fm,
|
|||||||
name = fm.name or field
|
name = fm.name or field
|
||||||
le = E.input(type='text', name=name.replace('#', '_c_'), style='width: 100%', oninput=line_edit_updated.bind(None, container_id, field))
|
le = E.input(type='text', name=name.replace('#', '_c_'), style='width: 100%', oninput=line_edit_updated.bind(None, container_id, field))
|
||||||
val = (resolved_metadata(mi, field) or v'[]')
|
val = (resolved_metadata(mi, field) or v'[]')
|
||||||
|
if field is 'languages':
|
||||||
|
val = [mi.lang_names[l] or l for l in val]
|
||||||
if list_to_ui:
|
if list_to_ui:
|
||||||
val = val.join(list_to_ui)
|
val = val.join(list_to_ui)
|
||||||
le.value = val
|
le.value = val
|
||||||
|
Loading…
x
Reference in New Issue
Block a user