mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Allow calibredb ot set series index for series type custom columns
This commit is contained in:
parent
186532e795
commit
44be78af3d
@ -21,6 +21,7 @@ from calibre.utils.date import dt_factory, qt_to_dt, isoformat
|
||||
from calibre.ebooks.metadata.meta import set_metadata as _set_metadata
|
||||
from calibre.utils.search_query_parser import SearchQueryParser
|
||||
from calibre.library.caches import _match, CONTAINS_MATCH, EQUALS_MATCH, REGEXP_MATCH
|
||||
from calibre.library.cli import parse_series_string
|
||||
from calibre import strftime, isbytestring, prepare_string_for_xml
|
||||
from calibre.constants import filesystem_encoding
|
||||
from calibre.gui2.library import DEFAULT_SORT
|
||||
@ -708,17 +709,7 @@ class BooksModel(QAbstractTableModel): # {{{
|
||||
return False
|
||||
val = qt_to_dt(val, as_utc=False)
|
||||
elif typ == 'series':
|
||||
val = unicode(value.toString()).strip()
|
||||
pat = re.compile(r'\[([.0-9]+)\]')
|
||||
match = pat.search(val)
|
||||
if match is not None:
|
||||
val = pat.sub('', val).strip()
|
||||
s_index = float(match.group(1))
|
||||
elif val:
|
||||
if tweaks['series_index_auto_increment'] == 'next':
|
||||
s_index = self.db.get_next_cc_series_num_for(val, label=label)
|
||||
else:
|
||||
s_index = 1.0
|
||||
val, s_index = parse_series_string(self.db, label, value.toString())
|
||||
self.db.set_custom(self.db.id(row), val, extra=s_index,
|
||||
label=label, num=None, append=False, notify=True)
|
||||
return True
|
||||
|
@ -620,6 +620,10 @@ class ResultCache(SearchQueryParser):
|
||||
elif field == 'title': field = 'sort'
|
||||
elif field == 'authors': field = 'author_sort'
|
||||
as_string = field not in ('size', 'rating', 'timestamp')
|
||||
|
||||
if self.first_sort:
|
||||
subsort = True
|
||||
self.first_sort = False
|
||||
if self.field_metadata[field]['is_custom']:
|
||||
if self.field_metadata[field]['datatype'] == 'series':
|
||||
fcmp = functools.partial(self.seriescmp,
|
||||
@ -638,10 +642,6 @@ class ResultCache(SearchQueryParser):
|
||||
else:
|
||||
fcmp = functools.partial(self.cmp, self.FIELD_MAP[field],
|
||||
subsort=subsort, asstr=as_string)
|
||||
|
||||
if self.first_sort:
|
||||
subsort = True
|
||||
self.first_sort = False
|
||||
self._map.sort(cmp=fcmp, reverse=not ascending)
|
||||
self._map_filtered = [id for id in self._map if id in self._map_filtered]
|
||||
|
||||
|
@ -7,11 +7,11 @@ __docformat__ = 'restructuredtext en'
|
||||
Command line interface to the calibre database.
|
||||
'''
|
||||
|
||||
import sys, os, cStringIO
|
||||
import sys, os, cStringIO, re
|
||||
from textwrap import TextWrapper
|
||||
|
||||
from calibre import terminal_controller, preferred_encoding, prints
|
||||
from calibre.utils.config import OptionParser, prefs
|
||||
from calibre.utils.config import OptionParser, prefs, tweaks
|
||||
from calibre.ebooks.metadata.meta import get_metadata
|
||||
from calibre.library.database2 import LibraryDatabase2
|
||||
from calibre.ebooks.metadata.opf2 import OPFCreator, OPF
|
||||
@ -680,9 +680,31 @@ def command_catalog(args, dbpath):
|
||||
|
||||
# end of GR additions
|
||||
|
||||
def parse_series_string(db, label, value):
|
||||
val = unicode(value).strip()
|
||||
s_index = None
|
||||
pat = re.compile(r'\[([.0-9]+)\]')
|
||||
match = pat.search(val)
|
||||
if match is not None:
|
||||
val = pat.sub('', val).strip()
|
||||
s_index = float(match.group(1))
|
||||
elif val:
|
||||
if tweaks['series_index_auto_increment'] == 'next':
|
||||
s_index = db.get_next_cc_series_num_for(val, label=label)
|
||||
else:
|
||||
s_index = 1.0
|
||||
return val, s_index
|
||||
|
||||
def do_set_custom(db, col, id_, val, append):
|
||||
db.set_custom(id_, val, label=col, append=append)
|
||||
prints('Data set to: %r'%db.get_custom(id_, label=col, index_is_id=True))
|
||||
if db.custom_column_label_map[col]['datatype'] == 'series':
|
||||
val, s_index = parse_series_string(db, col, val)
|
||||
db.set_custom(id_, val, extra=s_index, label=col, append=append)
|
||||
prints('Data set to: %r[%4.2f]'%
|
||||
(db.get_custom(id_, label=col, index_is_id=True),
|
||||
db.get_custom_extra(id_, label=col, index_is_id=True)))
|
||||
else:
|
||||
db.set_custom(id_, val, label=col, append=append)
|
||||
prints('Data set to: %r'%db.get_custom(id_, label=col, index_is_id=True))
|
||||
|
||||
def set_custom_option_parser():
|
||||
parser = get_parser(_(
|
||||
|
@ -308,8 +308,8 @@ class CustomColumns(object):
|
||||
self.conn.commit()
|
||||
return changed
|
||||
|
||||
def set_custom(self, id_, val, extra=None, label=None, num=None,
|
||||
append=False, notify=True):
|
||||
def set_custom(self, id_, val, label=None, num=None,
|
||||
append=False, notify=True, extra=None):
|
||||
if label is not None:
|
||||
data = self.custom_column_label_map[label]
|
||||
if num is not None:
|
||||
|
Loading…
x
Reference in New Issue
Block a user