Fix set_custom legacy API for series fields with index in value

Fixes #1220914 [db.set_custom on custom series column ignores [number]](https://bugs.launchpad.net/calibre/+bug/1220914)
This commit is contained in:
Kovid Goyal 2013-09-05 10:07:30 +05:30
parent ff18978f1c
commit 58ac84cb57
2 changed files with 11 additions and 3 deletions

View File

@ -20,7 +20,7 @@ from calibre.db.cache import Cache
from calibre.db.errors import NoSuchFormat from calibre.db.errors import NoSuchFormat
from calibre.db.categories import CATEGORY_SORTS from calibre.db.categories import CATEGORY_SORTS
from calibre.db.view import View from calibre.db.view import View
from calibre.db.write import clean_identifier from calibre.db.write import clean_identifier, get_series_values
from calibre.utils.date import utcnow from calibre.utils.date import utcnow
from calibre.utils.search_query_parser import set_saved_searches from calibre.utils.search_query_parser import set_saved_searches
@ -645,8 +645,10 @@ class LibraryDatabase(object):
else: else:
affected_books = self.new_api._set_field(field, {book_id:val}, allow_case_change=allow_case_change) affected_books = self.new_api._set_field(field, {book_id:val}, allow_case_change=allow_case_change)
if data['datatype'] == 'series': if data['datatype'] == 'series':
extra = 1.0 if extra is None else extra s, sidx = get_series_values(val)
self.new_api._set_field(field + '_index', {book_id:extra}) if sidx is None:
extra = 1.0 if extra is None else extra
self.new_api._set_field(field + '_index', {book_id:extra})
if notify and affected_books: if notify and affected_books:
self.notify('metadata', list(affected_books)) self.notify('metadata', list(affected_books))
return affected_books return affected_books

View File

@ -760,6 +760,12 @@ class LegacyTest(BaseTest):
ndb.delete_custom_column('created') ndb.delete_custom_column('created')
ndb = self.init_legacy(n) ndb = self.init_legacy(n)
self.assertRaises(KeyError, ndb.custom_field_name, num=num) self.assertRaises(KeyError, ndb.custom_field_name, num=num)
# Test setting custom series
ndb = self.init_legacy(self.cloned_library)
ndb.set_custom(1, 'TS [9]', label='series')
self.assertEqual(ndb.new_api.field_for('#series', 1), 'TS')
self.assertEqual(ndb.new_api.field_for('#series_index', 1), 9)
# }}} # }}}
def test_legacy_original_fmt(self): # {{{ def test_legacy_original_fmt(self): # {{{