Add a no-plus quoted value variant

This commit is contained in:
Kovid Goyal 2025-02-08 13:06:14 +05:30
parent a632436c60
commit 496a9630f1
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 12 additions and 7 deletions

View File

@ -69,7 +69,9 @@ def search_action_with_data(search_term, value, book_id, field=None, **k):
def web_search_link(template, mi, value): def web_search_link(template, mi, value):
formatter = SafeFormat() formatter = SafeFormat()
mi.set('item_value', qquote(str(value))) iv = str(value)
mi.set('item_value', qquote(iv, True))
mi.set('item_value_no_plus', qquote(iv, False))
u = formatter.safe_format(template, mi, 'BOOK DETAILS WEB LINK', mi) u = formatter.safe_format(template, mi, 'BOOK DETAILS WEB LINK', mi)
if u: if u:
return u, prepare_string_for_xml(_('Click to browse to: {}').format(u), attribute=True) return u, prepare_string_for_xml(_('Click to browse to: {}').format(u), attribute=True)

View File

@ -542,11 +542,12 @@ class CreateCustomColumn(QDialog):
l.addWidget(self.web_search_label) l.addWidget(self.web_search_label)
wst = self.web_search_template = QLineEdit() wst = self.web_search_template = QLineEdit()
wst.setToolTip('<p>' + _( wst.setToolTip('<p>' + _(
"Fill in this box if you want clicking on the value in book details to do a " 'Fill in this box if you want clicking on the value in book details to do a '
"web search instead of searching your calibre library. The book's metadata are " "web search instead of searching your calibre library. The book's metadata is "
"available to the template. An additional field 'item_value' is available to the " "available to the template. Additional fields '{0}' and '{1}' are also available to the "
"template. For multiple-valued (tags-like) columns it is the value being examined, " 'template. For multiple-valued (tags-like) columns they are the value being examined, '
"telling you which value to use to generate the link.") + '</p>') 'telling you which value to use to generate the link. These two values are automatically escaped for use in URLs.').format(
'item_value', 'item_value_no_plus') + '</p>')
l.addWidget(wst) l.addWidget(wst)
self.web_search_label.setBuddy(wst) self.web_search_label.setBuddy(wst)
wst_tb = self.web_search_toolbutton = QToolButton() wst_tb = self.web_search_toolbutton = QToolButton()
@ -566,11 +567,13 @@ class CreateCustomColumn(QDialog):
vals = [{'value': _('Value'), 'lookup_name': _('Lookup name'), 'author': _('Author'), vals = [{'value': _('Value'), 'lookup_name': _('Lookup name'), 'author': _('Author'),
'title': _('Title'), 'author_sort': _('Author sort')}] 'title': _('Title'), 'author_sort': _('Author sort')}]
else: else:
from calibre.ebooks.metadata.search_internet import qquote
vals = [] vals = []
for row in rows: for row in rows:
book_id = lv.model().id(row) book_id = lv.model().id(row)
mi = db.new_api.get_metadata(book_id) mi = db.new_api.get_metadata(book_id)
mi.set('item_value', 'Item Value') mi.set('item_value', qquote('Item Value', True))
mi.set('item_value_no_plus', qquote('Item Value', False))
vals.append(mi) vals.append(mi)
d = TemplateDialog(parent=self, text=self.web_search_template.text(), mi=vals) d = TemplateDialog(parent=self, text=self.web_search_template.text(), mi=vals)
if d.exec() == QDialog.DialogCode.Accepted: if d.exec() == QDialog.DialogCode.Accepted: