mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Change enums to not use the user defined function in meta2
This commit is contained in:
parent
49530f1bbb
commit
5fa0b8941a
@ -254,6 +254,12 @@ class ResultCache(SearchQueryParser): # {{{
|
||||
if field_metadata[key]['datatype'] == 'composite':
|
||||
self.composites.append((key, field_metadata[key]['rec_index']))
|
||||
|
||||
self.enumerations = []
|
||||
for key in field_metadata:
|
||||
if field_metadata[key]['datatype'] == 'enumeration':
|
||||
self.enumerations.append((field_metadata[key]['display']['enum_values'][0],
|
||||
field_metadata[key]['rec_index']))
|
||||
|
||||
def __getitem__(self, row):
|
||||
return self._data[self._map_filtered[row]]
|
||||
|
||||
@ -691,6 +697,10 @@ class ResultCache(SearchQueryParser): # {{{
|
||||
mi = db.get_metadata(id, index_is_id=True)
|
||||
for k,c in self.composites:
|
||||
self._data[id][c] = mi.get(k, None)
|
||||
if len(self.enumerations) > 0:
|
||||
for v,c in self.enumerations:
|
||||
if self._data[id][c] is None:
|
||||
self._data[id][c] = v
|
||||
except IndexError:
|
||||
return None
|
||||
try:
|
||||
@ -711,6 +721,10 @@ class ResultCache(SearchQueryParser): # {{{
|
||||
mi = db.get_metadata(id, index_is_id=True)
|
||||
for k,c in self.composites:
|
||||
self._data[id][c] = mi.get(k)
|
||||
if len(self.enumerations) > 0:
|
||||
for v,c in self.self._data[id][c]:
|
||||
if self._data[id][c] is None:
|
||||
self._data[id][c] = v
|
||||
self._map[0:0] = ids
|
||||
self._map_filtered[0:0] = ids
|
||||
|
||||
@ -740,6 +754,10 @@ class ResultCache(SearchQueryParser): # {{{
|
||||
mi = db.get_metadata(item[0], index_is_id=True)
|
||||
for k,c in self.composites:
|
||||
item[c] = mi.get(k)
|
||||
if len(self.enumerations) > 0:
|
||||
for v,c in self.enumerations:
|
||||
if item[c] is None:
|
||||
item[c] = v
|
||||
|
||||
self._map = [i[0] for i in self._data if i is not None]
|
||||
if field is not None:
|
||||
|
@ -525,18 +525,6 @@ class CustomColumns(object):
|
||||
display = data['display']
|
||||
table, lt = self.custom_table_names(data['num'])
|
||||
if data['normalized']:
|
||||
if data['datatype'] == 'enumeration':
|
||||
query = '%s.value'
|
||||
line = '''
|
||||
val_for_enum(\'
|
||||
SELECT {table}.value FROM {lt}
|
||||
AS link INNER JOIN {table} ON(link.value={table}.id)
|
||||
WHERE link.book=?\',
|
||||
\'{default}\', books.id) custom_{num}
|
||||
'''.format(lt=lt, table=table,
|
||||
default=data['display']['enum_values'][0],
|
||||
num=data['num'])
|
||||
else:
|
||||
query = '%s.value'
|
||||
if data['is_multiple']:
|
||||
query = 'group_concat(%s.value, "|")'
|
||||
|
@ -115,18 +115,6 @@ def pynocase(one, two, encoding='utf-8'):
|
||||
pass
|
||||
return cmp(one.lower(), two.lower())
|
||||
|
||||
def enum_col_value(select, def_val, id, conn=None):
|
||||
try:
|
||||
v = conn.get(select, (id,), all=False)
|
||||
if v is None:
|
||||
v = def_val
|
||||
except Exception, e:
|
||||
if DEBUG:
|
||||
print 'enum_col_value failed'
|
||||
print e
|
||||
v = def_val
|
||||
return v
|
||||
|
||||
def load_c_extensions(conn, debug=DEBUG):
|
||||
try:
|
||||
conn.enable_load_extension(True)
|
||||
@ -176,8 +164,6 @@ class DBThread(Thread):
|
||||
self.conn.create_function('author_to_author_sort', 1,
|
||||
_author_to_author_sort)
|
||||
self.conn.create_function('uuid4', 0, lambda : str(uuid.uuid4()))
|
||||
self.conn.create_function('val_for_enum', 3,
|
||||
partial(enum_col_value, conn=self.conn))
|
||||
# Dummy functions for dynamically created filters
|
||||
self.conn.create_function('books_list_filter', 1, lambda x: 1)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user