pep8 and misc cleanups

This commit is contained in:
Kovid Goyal 2025-02-08 09:33:35 +05:30
parent 78be0f69a4
commit cc8b7ad47b
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 40 additions and 22 deletions

View File

@ -753,8 +753,8 @@ class Metadata:
res = human_readable(res)
return (name, str(res), orig_res, fmeta)
if self.get(key, None):
return (key, str(self.get(key)), self.get(key), None)
if kv := self.get(key, None):
return (key, str(kv), kv, None)
return (None, None, None, None)

View File

@ -69,17 +69,21 @@ def search_action_with_data(search_term, value, book_id, field=None, **k):
def cc_search_action_with_data(search_term, value, book_id, fm, mi, field=None, **k):
if mi is not None and fm is not None:
template = fm.get('display', {}).get('web_search_template')
if template:
if template := fm.get('display', {}).get('web_search_template'):
try:
formatter = SafeFormat()
mi.set('item_value', value)
u = formatter.safe_format(template, mi, "BOOK DETAILS WEB LINK", mi)
u = formatter.safe_format(template, mi, 'BOOK DETAILS WEB LINK', mi)
if u:
v = prepare_string_for_xml(_('Click to browse to {0}').format(u), attribute=True)
v = prepare_string_for_xml(_('Click to browse to {}').format(u), attribute=True)
return action('cc_url', url=u), v
except Exception:
import traceback
traceback.print_exc()
t = _('Click to see books with {0}: {1}').format(mi.get('name', search_term), prepare_string_for_xml(value))
return search_action_with_data(search_term, value, book_id, **k), t
def notes_action(**keys):
return 'notes:' + as_hex_unicode(json_dumps(keys))
@ -226,7 +230,7 @@ def mi_to_html(
else:
if not metadata['is_multiple']:
u, v = cc_search_action_with_data(field, val, book_id, metadata, mi, field)
val = '<a href="{}" title="{}">{}</a>'.format(u, v, p(val))
val = f'<a href="{u}" title="{v}">{p(val)}</a>'
else:
all_vals = [v.strip()
for v in val.split(metadata['is_multiple']['cache_to_list']) if v.strip()]
@ -234,7 +238,7 @@ def mi_to_html(
links = []
for x in all_vals:
u, v = cc_search_action_with_data(field, x, book_id, metadata, mi, field)
links.append('<a href="{}" title="{}">{}</a>'.format(u, v, p(x)))
links.append(f'<a href="{u}" title="{v}">{p(x)}</a>')
else:
links = all_vals
val = value_list(metadata['is_multiple']['list_to_ui'], links)
@ -406,7 +410,7 @@ def mi_to_html(
for x in all_vals:
if metadata['is_custom']:
u, v = cc_search_action_with_data(field, x, book_id, metadata, mi, field)
v = '<a href="{}" title="{}">{}</a>'.format(u, v, p(x))
v = f'<a href="{u}" title="{v}">{p(x)}</a>'
else:
v = '<a href="{}" title="{}">{}</a>'.format(
search_action_with_data(st, x, book_id, field),
@ -425,7 +429,7 @@ def mi_to_html(
if show_links:
if metadata['is_custom']:
u, v = cc_search_action_with_data(st, x, book_id, metadata, mi, field)
v = '<a href="{}" title="{}">{}</a>'.format(u, v, p(x))
v = f'<a href="{u}" title="{v}">{p(x)}</a>'
else:
v = '<a href="{}" title="{}">{}</a>'.format(
search_action_with_data(st, x, book_id, field),
@ -436,7 +440,7 @@ def mi_to_html(
val = v + add_other_links(field, val)
elif metadata['datatype'] == 'enumeration':
u, v = cc_search_action_with_data(field, x, book_id, metadata, mi, field)
val = '<a href="{}" title="{}">{}</a>'.format(u, v, p(x)) + add_other_links(field, val)
val = f'<a href="{u}" title="{v}">{p(x)}</a>' + add_other_links(field, val)
elif metadata['datatype'] == 'bool':
val = '<a href="{}" title="{}">{}</a>'.format(
search_action_with_data(field, val, book_id, None), a(

View File

@ -7,7 +7,21 @@ __docformat__ = 'restructuredtext en'
import json
from qt.core import QAbstractListModel, QComboBox, QDialog, QFormLayout, QHBoxLayout, QIcon, QItemSelectionModel, QLineEdit, Qt, QToolButton, QVBoxLayout, QWidget, pyqtSignal
from qt.core import (
QAbstractListModel,
QComboBox,
QDialog,
QFormLayout,
QHBoxLayout,
QIcon,
QItemSelectionModel,
QLineEdit,
Qt,
QToolButton,
QVBoxLayout,
QWidget,
pyqtSignal,
)
from calibre.ebooks.metadata.book.render import DEFAULT_AUTHOR_LINK
from calibre.ebooks.metadata.search_internet import qquote