mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-08-11 09:13:57 -04:00
Fix #815573 (Series number Tweak will not accept constant value)
This commit is contained in:
commit
919011f8e5
@ -11,7 +11,7 @@ defaults.
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
#: Auto increment series index
|
#: Auto increment series index
|
||||||
# The algorithm used to assign a new book in an existing series a series number.
|
# The algorithm used to assign a book added to an existing series a series number.
|
||||||
# New series numbers assigned using this tweak are always integer values, except
|
# New series numbers assigned using this tweak are always integer values, except
|
||||||
# if a constant non-integer is specified.
|
# if a constant non-integer is specified.
|
||||||
# Possible values are:
|
# Possible values are:
|
||||||
@ -27,7 +27,19 @@ defaults.
|
|||||||
# series_index_auto_increment = 'next'
|
# series_index_auto_increment = 'next'
|
||||||
# series_index_auto_increment = 'next_free'
|
# series_index_auto_increment = 'next_free'
|
||||||
# series_index_auto_increment = 16.5
|
# series_index_auto_increment = 16.5
|
||||||
|
#
|
||||||
|
# Set the use_series_auto_increment_tweak_when_importing tweak to True to
|
||||||
|
# use the above values when importing/adding books. If this tweak is set to
|
||||||
|
# False (the default) then the series number will be set to 1 if it is not
|
||||||
|
# explicitly set to during the import. If set to True, then the
|
||||||
|
# series index will be set according to the series_index_auto_increment setting.
|
||||||
|
# Note that the use_series_auto_increment_tweak_when_importing tweak is used
|
||||||
|
# only when a value is not provided during import. If the importing regular
|
||||||
|
# expression produces a value for series_index, or if you are reading metadata
|
||||||
|
# from books and the import plugin produces a value, than that value will
|
||||||
|
# be used irrespective of the setting of the tweak.
|
||||||
series_index_auto_increment = 'next'
|
series_index_auto_increment = 'next'
|
||||||
|
use_series_auto_increment_tweak_when_importing = False
|
||||||
|
|
||||||
#: Add separator after completing an author name
|
#: Add separator after completing an author name
|
||||||
# Should the completion separator be append
|
# Should the completion separator be append
|
||||||
|
@ -22,6 +22,7 @@ from calibre.utils.date import parse_date, isoformat
|
|||||||
from calibre.utils.localization import get_lang
|
from calibre.utils.localization import get_lang
|
||||||
from calibre import prints, guess_type
|
from calibre import prints, guess_type
|
||||||
from calibre.utils.cleantext import clean_ascii_chars
|
from calibre.utils.cleantext import clean_ascii_chars
|
||||||
|
from calibre.utils.config import tweaks
|
||||||
|
|
||||||
class Resource(object): # {{{
|
class Resource(object): # {{{
|
||||||
'''
|
'''
|
||||||
@ -527,7 +528,12 @@ class OPF(object): # {{{
|
|||||||
category = MetadataField('type')
|
category = MetadataField('type')
|
||||||
rights = MetadataField('rights')
|
rights = MetadataField('rights')
|
||||||
series = MetadataField('series', is_dc=False)
|
series = MetadataField('series', is_dc=False)
|
||||||
series_index = MetadataField('series_index', is_dc=False, formatter=float, none_is=1)
|
if tweaks['use_series_auto_increment_tweak_when_importing']:
|
||||||
|
series_index = MetadataField('series_index', is_dc=False,
|
||||||
|
formatter=float, none_is=None)
|
||||||
|
else:
|
||||||
|
series_index = MetadataField('series_index', is_dc=False,
|
||||||
|
formatter=float, none_is=1)
|
||||||
title_sort = TitleSortField('title_sort', is_dc=False)
|
title_sort = TitleSortField('title_sort', is_dc=False)
|
||||||
rating = MetadataField('rating', is_dc=False, formatter=int)
|
rating = MetadataField('rating', is_dc=False, formatter=int)
|
||||||
pubdate = MetadataField('date', formatter=parse_date,
|
pubdate = MetadataField('date', formatter=parse_date,
|
||||||
|
@ -1892,6 +1892,8 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
yield r[iindex]
|
yield r[iindex]
|
||||||
|
|
||||||
def get_next_series_num_for(self, series):
|
def get_next_series_num_for(self, series):
|
||||||
|
series_id = None
|
||||||
|
if series:
|
||||||
series_id = self.conn.get('SELECT id from series WHERE name=?',
|
series_id = self.conn.get('SELECT id from series WHERE name=?',
|
||||||
(series,), all=False)
|
(series,), all=False)
|
||||||
if series_id is None:
|
if series_id is None:
|
||||||
@ -3023,8 +3025,8 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
stream.seek(0)
|
stream.seek(0)
|
||||||
mi = get_metadata(stream, format, use_libprs_metadata=False)
|
mi = get_metadata(stream, format, use_libprs_metadata=False)
|
||||||
stream.seek(0)
|
stream.seek(0)
|
||||||
if not mi.series_index:
|
if mi.series_index is None:
|
||||||
mi.series_index = 1.0
|
mi.series_index = self.get_next_series_num_for(mi.series)
|
||||||
mi.tags = [_('News')]
|
mi.tags = [_('News')]
|
||||||
if arg['add_title_tag']:
|
if arg['add_title_tag']:
|
||||||
mi.tags += [arg['title']]
|
mi.tags += [arg['title']]
|
||||||
@ -3076,7 +3078,8 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
self._add_newbook_tag(mi)
|
self._add_newbook_tag(mi)
|
||||||
if not add_duplicates and self.has_book(mi):
|
if not add_duplicates and self.has_book(mi):
|
||||||
return None
|
return None
|
||||||
series_index = 1.0 if mi.series_index is None else mi.series_index
|
series_index = self.get_next_series_num_for(mi.series) \
|
||||||
|
if mi.series_index is None else mi.series_index
|
||||||
aus = mi.author_sort if mi.author_sort else self.author_sort_from_authors(mi.authors)
|
aus = mi.author_sort if mi.author_sort else self.author_sort_from_authors(mi.authors)
|
||||||
title = mi.title
|
title = mi.title
|
||||||
if isbytestring(aus):
|
if isbytestring(aus):
|
||||||
@ -3123,7 +3126,8 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
if not add_duplicates and self.has_book(mi):
|
if not add_duplicates and self.has_book(mi):
|
||||||
duplicates.append((path, format, mi))
|
duplicates.append((path, format, mi))
|
||||||
continue
|
continue
|
||||||
series_index = 1.0 if mi.series_index is None else mi.series_index
|
series_index = self.get_next_series_num_for(mi.series) \
|
||||||
|
if mi.series_index is None else mi.series_index
|
||||||
aus = mi.author_sort if mi.author_sort else self.author_sort_from_authors(mi.authors)
|
aus = mi.author_sort if mi.author_sort else self.author_sort_from_authors(mi.authors)
|
||||||
title = mi.title
|
title = mi.title
|
||||||
if isinstance(aus, str):
|
if isinstance(aus, str):
|
||||||
@ -3157,7 +3161,8 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
|
|
||||||
def import_book(self, mi, formats, notify=True, import_hooks=True,
|
def import_book(self, mi, formats, notify=True, import_hooks=True,
|
||||||
apply_import_tags=True, preserve_uuid=False):
|
apply_import_tags=True, preserve_uuid=False):
|
||||||
series_index = 1.0 if mi.series_index is None else mi.series_index
|
series_index = self.get_next_series_num_for(mi.series) \
|
||||||
|
if mi.series_index is None else mi.series_index
|
||||||
if apply_import_tags:
|
if apply_import_tags:
|
||||||
self._add_newbook_tag(mi)
|
self._add_newbook_tag(mi)
|
||||||
if not mi.title:
|
if not mi.title:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user