mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix updating of title_sort in cache when updating title
This commit is contained in:
parent
954c64c156
commit
85cb16265f
@ -219,6 +219,8 @@ class Cache(object):
|
|||||||
field.series_field = self.fields['series']
|
field.series_field = self.fields['series']
|
||||||
elif name == 'authors':
|
elif name == 'authors':
|
||||||
field.author_sort_field = self.fields['author_sort']
|
field.author_sort_field = self.fields['author_sort']
|
||||||
|
elif name == 'title':
|
||||||
|
field.title_sort_field = self.fields['sort']
|
||||||
|
|
||||||
@read_api
|
@read_api
|
||||||
def field_for(self, name, book_id, default_value=None):
|
def field_for(self, name, book_id, default_value=None):
|
||||||
@ -620,7 +622,6 @@ class Cache(object):
|
|||||||
@write_api
|
@write_api
|
||||||
def set_field(self, name, book_id_to_val_map, allow_case_change=True):
|
def set_field(self, name, book_id_to_val_map, allow_case_change=True):
|
||||||
# TODO: Specialize title/authors to also update path
|
# TODO: Specialize title/authors to also update path
|
||||||
# TODO: Ensure the sort fields are updated for title/author/series?
|
|
||||||
f = self.fields[name]
|
f = self.fields[name]
|
||||||
is_series = f.metadata['datatype'] == 'series'
|
is_series = f.metadata['datatype'] == 'series'
|
||||||
|
|
||||||
|
@ -247,6 +247,10 @@ class WritingTest(BaseTest):
|
|||||||
ae(c.field_for('author_sort', 1), 'Unknown')
|
ae(c.field_for('author_sort', 1), 'Unknown')
|
||||||
ae(c.field_for('author_sort', 2), 'An, Author')
|
ae(c.field_for('author_sort', 2), 'An, Author')
|
||||||
ae(c.field_for('author_sort', 3), 'Goyal, Kovid & Layog, Divok')
|
ae(c.field_for('author_sort', 3), 'Goyal, Kovid & Layog, Divok')
|
||||||
|
if name == 'authors':
|
||||||
|
ae(c.field_for('author_sort', 3), 'Goyal, Kovid & Layog, Divok')
|
||||||
|
ae(c.field_for('author_sort', 2), 'An, Author')
|
||||||
|
ae(c.field_for('author_sort', 1), 'Unknown')
|
||||||
del cache2
|
del cache2
|
||||||
ae(cache.set_field('authors', {1:'KoviD GoyaL'}), {1, 3})
|
ae(cache.set_field('authors', {1:'KoviD GoyaL'}), {1, 3})
|
||||||
ae(cache.field_for('author_sort', 1), 'GoyaL, KoviD')
|
ae(cache.field_for('author_sort', 1), 'GoyaL, KoviD')
|
||||||
@ -276,6 +280,15 @@ class WritingTest(BaseTest):
|
|||||||
ae(c.field_for('identifiers', 3), {'one':'1', 'two':'2'})
|
ae(c.field_for('identifiers', 3), {'one':'1', 'two':'2'})
|
||||||
ae(c.field_for('identifiers', 2), {})
|
ae(c.field_for('identifiers', 2), {})
|
||||||
ae(c.field_for('identifiers', 1), {'test':'1', 'two':'2'})
|
ae(c.field_for('identifiers', 1), {'test':'1', 'two':'2'})
|
||||||
|
del cache2
|
||||||
|
|
||||||
|
# Test setting of title sort
|
||||||
|
ae(sf('title', {1:'The Moose', 2:'Cat'}), {1, 2})
|
||||||
|
cache2 = self.init_cache(cl)
|
||||||
|
for c in (cache, cache2):
|
||||||
|
ae(c.field_for('sort', 1), 'Moose, The')
|
||||||
|
ae(c.field_for('sort', 2), 'Cat')
|
||||||
|
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ from functools import partial
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from calibre.constants import preferred_encoding, ispy3
|
from calibre.constants import preferred_encoding, ispy3
|
||||||
from calibre.ebooks.metadata import author_to_author_sort
|
from calibre.ebooks.metadata import author_to_author_sort, title_sort
|
||||||
from calibre.utils.date import (parse_only_date, parse_date, UNDEFINED_DATE,
|
from calibre.utils.date import (parse_only_date, parse_date, UNDEFINED_DATE,
|
||||||
isoformat)
|
isoformat)
|
||||||
from calibre.utils.localization import canonicalize_lang
|
from calibre.utils.localization import canonicalize_lang
|
||||||
@ -174,6 +174,10 @@ def one_one_in_books(book_id_val_map, db, field, *args):
|
|||||||
db.conn.executemany(
|
db.conn.executemany(
|
||||||
'UPDATE books SET %s=? WHERE id=?'%field.metadata['column'], sequence)
|
'UPDATE books SET %s=? WHERE id=?'%field.metadata['column'], sequence)
|
||||||
field.table.book_col_map.update(book_id_val_map)
|
field.table.book_col_map.update(book_id_val_map)
|
||||||
|
if field.name == 'title':
|
||||||
|
# Set the title sort field
|
||||||
|
field.title_sort_field.writer.set_books(
|
||||||
|
{k:title_sort(v) for k, v in book_id_val_map.iteritems()}, db)
|
||||||
return set(book_id_val_map)
|
return set(book_id_val_map)
|
||||||
|
|
||||||
def one_one_in_other(book_id_val_map, db, field, *args):
|
def one_one_in_other(book_id_val_map, db, field, *args):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user