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':
|
if field_metadata[key]['datatype'] == 'composite':
|
||||||
self.composites.append((key, field_metadata[key]['rec_index']))
|
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):
|
def __getitem__(self, row):
|
||||||
return self._data[self._map_filtered[row]]
|
return self._data[self._map_filtered[row]]
|
||||||
|
|
||||||
@ -691,6 +697,10 @@ class ResultCache(SearchQueryParser): # {{{
|
|||||||
mi = db.get_metadata(id, index_is_id=True)
|
mi = db.get_metadata(id, index_is_id=True)
|
||||||
for k,c in self.composites:
|
for k,c in self.composites:
|
||||||
self._data[id][c] = mi.get(k, None)
|
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:
|
except IndexError:
|
||||||
return None
|
return None
|
||||||
try:
|
try:
|
||||||
@ -711,6 +721,10 @@ class ResultCache(SearchQueryParser): # {{{
|
|||||||
mi = db.get_metadata(id, index_is_id=True)
|
mi = db.get_metadata(id, index_is_id=True)
|
||||||
for k,c in self.composites:
|
for k,c in self.composites:
|
||||||
self._data[id][c] = mi.get(k)
|
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[0:0] = ids
|
||||||
self._map_filtered[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)
|
mi = db.get_metadata(item[0], index_is_id=True)
|
||||||
for k,c in self.composites:
|
for k,c in self.composites:
|
||||||
item[c] = mi.get(k)
|
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]
|
self._map = [i[0] for i in self._data if i is not None]
|
||||||
if field is not None:
|
if field is not None:
|
||||||
|
@ -525,30 +525,18 @@ class CustomColumns(object):
|
|||||||
display = data['display']
|
display = data['display']
|
||||||
table, lt = self.custom_table_names(data['num'])
|
table, lt = self.custom_table_names(data['num'])
|
||||||
if data['normalized']:
|
if data['normalized']:
|
||||||
if data['datatype'] == 'enumeration':
|
query = '%s.value'
|
||||||
query = '%s.value'
|
if data['is_multiple']:
|
||||||
line = '''
|
query = 'group_concat(%s.value, "|")'
|
||||||
val_for_enum(\'
|
if not display.get('sort_alpha', False):
|
||||||
SELECT {table}.value FROM {lt}
|
query = 'sort_concat(link.id, %s.value)'
|
||||||
AS link INNER JOIN {table} ON(link.value={table}.id)
|
line = '''(SELECT {query} FROM {lt} AS link INNER JOIN
|
||||||
WHERE link.book=?\',
|
{table} ON(link.value={table}.id) WHERE link.book=books.id)
|
||||||
\'{default}\', books.id) custom_{num}
|
custom_{num}
|
||||||
'''.format(lt=lt, table=table,
|
'''.format(query=query%table, lt=lt, table=table, num=data['num'])
|
||||||
default=data['display']['enum_values'][0],
|
if data['datatype'] == 'series':
|
||||||
num=data['num'])
|
line += ''',(SELECT extra FROM {lt} WHERE {lt}.book=books.id)
|
||||||
else:
|
custom_index_{num}'''.format(lt=lt, num=data['num'])
|
||||||
query = '%s.value'
|
|
||||||
if data['is_multiple']:
|
|
||||||
query = 'group_concat(%s.value, "|")'
|
|
||||||
if not display.get('sort_alpha', False):
|
|
||||||
query = 'sort_concat(link.id, %s.value)'
|
|
||||||
line = '''(SELECT {query} FROM {lt} AS link INNER JOIN
|
|
||||||
{table} ON(link.value={table}.id) WHERE link.book=books.id)
|
|
||||||
custom_{num}
|
|
||||||
'''.format(query=query%table, lt=lt, table=table, num=data['num'])
|
|
||||||
if data['datatype'] == 'series':
|
|
||||||
line += ''',(SELECT extra FROM {lt} WHERE {lt}.book=books.id)
|
|
||||||
custom_index_{num}'''.format(lt=lt, num=data['num'])
|
|
||||||
else:
|
else:
|
||||||
line = '''
|
line = '''
|
||||||
(SELECT value FROM {table} WHERE book=books.id) custom_{num}
|
(SELECT value FROM {table} WHERE book=books.id) custom_{num}
|
||||||
|
@ -115,18 +115,6 @@ def pynocase(one, two, encoding='utf-8'):
|
|||||||
pass
|
pass
|
||||||
return cmp(one.lower(), two.lower())
|
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):
|
def load_c_extensions(conn, debug=DEBUG):
|
||||||
try:
|
try:
|
||||||
conn.enable_load_extension(True)
|
conn.enable_load_extension(True)
|
||||||
@ -176,8 +164,6 @@ class DBThread(Thread):
|
|||||||
self.conn.create_function('author_to_author_sort', 1,
|
self.conn.create_function('author_to_author_sort', 1,
|
||||||
_author_to_author_sort)
|
_author_to_author_sort)
|
||||||
self.conn.create_function('uuid4', 0, lambda : str(uuid.uuid4()))
|
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
|
# Dummy functions for dynamically created filters
|
||||||
self.conn.create_function('books_list_filter', 1, lambda x: 1)
|
self.conn.create_function('books_list_filter', 1, lambda x: 1)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user