mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
1) finish JSON-storage of template function source code
2) fix for #8388. This fix was chosen because it emulates the behavior in 0.7.38, where get_metadata returned empty author lists
This commit is contained in:
parent
ebea6bdaed
commit
a21bf30ff8
@ -5,7 +5,7 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import traceback
|
import json, traceback
|
||||||
|
|
||||||
from calibre.gui2 import error_dialog
|
from calibre.gui2 import error_dialog
|
||||||
from calibre.gui2.preferences import ConfigWidgetBase, test_widget
|
from calibre.gui2.preferences import ConfigWidgetBase, test_widget
|
||||||
@ -73,6 +73,12 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
|||||||
self.textBrowser.setHtml(help_text)
|
self.textBrowser.setHtml(help_text)
|
||||||
|
|
||||||
def initialize(self):
|
def initialize(self):
|
||||||
|
try:
|
||||||
|
with open(P('template-functions.json'), 'rb') as f:
|
||||||
|
self.builtin_source_dict = json.load(f, encoding='utf-8')
|
||||||
|
except:
|
||||||
|
self.builtin_source_dict = {}
|
||||||
|
|
||||||
self.funcs = formatter_functions.get_functions()
|
self.funcs = formatter_functions.get_functions()
|
||||||
self.builtins = formatter_functions.get_builtins()
|
self.builtins = formatter_functions.get_builtins()
|
||||||
|
|
||||||
@ -179,8 +185,13 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
|||||||
func = self.funcs[txt]
|
func = self.funcs[txt]
|
||||||
self.argument_count.setValue(func.arg_count)
|
self.argument_count.setValue(func.arg_count)
|
||||||
self.documentation.setText(func.doc)
|
self.documentation.setText(func.doc)
|
||||||
self.program.setPlainText(func.program_text)
|
|
||||||
if txt in self.builtins:
|
if txt in self.builtins:
|
||||||
|
if hasattr(func, 'program_text'):
|
||||||
|
self.program.setPlainText(func.program_text)
|
||||||
|
elif txt in self.builtin_source_dict:
|
||||||
|
self.program.setPlainText(self.builtin_source_dict[txt])
|
||||||
|
else:
|
||||||
|
self.program.setPlainText(_('function source code not available'))
|
||||||
self.documentation.setReadOnly(True)
|
self.documentation.setReadOnly(True)
|
||||||
self.argument_count.setReadOnly(True)
|
self.argument_count.setReadOnly(True)
|
||||||
self.program.setReadOnly(True)
|
self.program.setReadOnly(True)
|
||||||
|
@ -690,7 +690,10 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
mi = Metadata(None)
|
mi = Metadata(None)
|
||||||
|
|
||||||
aut_list = row[fm['au_map']]
|
aut_list = row[fm['au_map']]
|
||||||
aut_list = [p.split(':::') for p in aut_list.split(':#:')]
|
if not aut_list:
|
||||||
|
aut_list = []
|
||||||
|
else:
|
||||||
|
aut_list = [p.split(':::') for p in aut_list.split(':#:')]
|
||||||
aum = []
|
aum = []
|
||||||
aus = {}
|
aus = {}
|
||||||
for (author, author_sort) in aut_list:
|
for (author, author_sort) in aut_list:
|
||||||
|
@ -100,7 +100,7 @@ class AumSortedConcatenate(object):
|
|||||||
keys = self.ans.keys()
|
keys = self.ans.keys()
|
||||||
l = len(keys)
|
l = len(keys)
|
||||||
if l == 0:
|
if l == 0:
|
||||||
return 'Unknown:::Unknown'
|
return None
|
||||||
if l == 1:
|
if l == 1:
|
||||||
return self.ans[keys[0]]
|
return self.ans[keys[0]]
|
||||||
return ':#:'.join([self.ans[v] for v in sorted(keys)])
|
return ':#:'.join([self.ans[v] for v in sorted(keys)])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user