mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add case change to series, publishers, and custom columns
This commit is contained in:
parent
975f1a7707
commit
947ae40a97
@ -44,8 +44,10 @@ class Base(object):
|
|||||||
val = self.gui_val
|
val = self.gui_val
|
||||||
val = self.normalize_ui_val(val)
|
val = self.normalize_ui_val(val)
|
||||||
if val != self.initial_val:
|
if val != self.initial_val:
|
||||||
self.db.set_custom(book_id, val, num=self.col_id, notify=notify,
|
return self.db.set_custom(book_id, val, num=self.col_id,
|
||||||
commit=False)
|
notify=notify, commit=False, allow_case_change=True)
|
||||||
|
else:
|
||||||
|
return set()
|
||||||
|
|
||||||
def normalize_db_val(self, val):
|
def normalize_db_val(self, val):
|
||||||
return val
|
return val
|
||||||
@ -330,8 +332,10 @@ class Series(Base):
|
|||||||
num=self.col_id)
|
num=self.col_id)
|
||||||
else:
|
else:
|
||||||
s_index = None
|
s_index = None
|
||||||
self.db.set_custom(book_id, val, extra=s_index,
|
return self.db.set_custom(book_id, val, extra=s_index, num=self.col_id,
|
||||||
num=self.col_id, notify=notify, commit=False)
|
notify=notify, commit=False, allow_case_change=True)
|
||||||
|
else:
|
||||||
|
return set()
|
||||||
|
|
||||||
class Enumeration(Base):
|
class Enumeration(Base):
|
||||||
|
|
||||||
|
@ -923,12 +923,12 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog):
|
|||||||
self.db.set_rating(self.id, 2*self.rating.value(), notify=False,
|
self.db.set_rating(self.id, 2*self.rating.value(), notify=False,
|
||||||
commit=False)
|
commit=False)
|
||||||
self.books_to_refresh |= self.apply_tags()
|
self.books_to_refresh |= self.apply_tags()
|
||||||
self.db.set_publisher(self.id,
|
self.books_to_refresh |= self.db.set_publisher(self.id,
|
||||||
unicode(self.publisher.currentText()).strip(),
|
unicode(self.publisher.currentText()).strip(),
|
||||||
notify=False, commit=False)
|
notify=False, commit=False, allow_case_change=True)
|
||||||
self.db.set_series(self.id,
|
self.books_to_refresh |= self.db.set_series(self.id,
|
||||||
unicode(self.series.currentText()).strip(), notify=False,
|
unicode(self.series.currentText()).strip(), notify=False,
|
||||||
commit=False)
|
commit=False, allow_case_change=True)
|
||||||
self.db.set_series_index(self.id, self.series_index.value(),
|
self.db.set_series_index(self.id, self.series_index.value(),
|
||||||
notify=False, commit=False)
|
notify=False, commit=False)
|
||||||
self.db.set_comment(self.id,
|
self.db.set_comment(self.id,
|
||||||
@ -949,7 +949,7 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog):
|
|||||||
else:
|
else:
|
||||||
self.db.remove_cover(self.id)
|
self.db.remove_cover(self.id)
|
||||||
for w in getattr(self, 'custom_column_widgets', []):
|
for w in getattr(self, 'custom_column_widgets', []):
|
||||||
w.commit(self.id)
|
self.books_to_refresh |= w.commit(self.id)
|
||||||
self.db.commit()
|
self.db.commit()
|
||||||
except IOError, err:
|
except IOError, err:
|
||||||
if err.errno == 13: # Permission denied
|
if err.errno == 13: # Permission denied
|
||||||
|
@ -800,9 +800,10 @@ class BooksModel(QAbstractTableModel): # {{{
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
id = self.db.id(row)
|
id = self.db.id(row)
|
||||||
self.db.set_custom(id, val, extra=s_index,
|
books_to_refresh = set([id])
|
||||||
|
books_to_refresh |= self.db.set_custom(id, val, extra=s_index,
|
||||||
label=label, num=None, append=False, notify=True)
|
label=label, num=None, append=False, notify=True)
|
||||||
self.refresh_ids([id], current_row=row)
|
self.refresh_ids(list(books_to_refresh), current_row=row)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def setData(self, index, value, role):
|
def setData(self, index, value, role):
|
||||||
@ -827,7 +828,8 @@ class BooksModel(QAbstractTableModel): # {{{
|
|||||||
elif column == 'series':
|
elif column == 'series':
|
||||||
val = val.strip()
|
val = val.strip()
|
||||||
if not val:
|
if not val:
|
||||||
self.db.set_series(id, val)
|
books_to_refresh |= self.db.set_series(id, val,
|
||||||
|
allow_case_change=True)
|
||||||
self.db.set_series_index(id, 1.0)
|
self.db.set_series_index(id, 1.0)
|
||||||
else:
|
else:
|
||||||
pat = re.compile(r'\[([.0-9]+)\]')
|
pat = re.compile(r'\[([.0-9]+)\]')
|
||||||
@ -841,7 +843,8 @@ class BooksModel(QAbstractTableModel): # {{{
|
|||||||
if ni != 1:
|
if ni != 1:
|
||||||
self.db.set_series_index(id, ni)
|
self.db.set_series_index(id, ni)
|
||||||
if val:
|
if val:
|
||||||
self.db.set_series(id, val)
|
books_to_refresh |= self.db.set_series(id, val,
|
||||||
|
allow_case_change=True)
|
||||||
elif column == 'timestamp':
|
elif column == 'timestamp':
|
||||||
if val.isNull() or not val.isValid():
|
if val.isNull() or not val.isValid():
|
||||||
return False
|
return False
|
||||||
|
@ -440,22 +440,24 @@ class CustomColumns(object):
|
|||||||
self.dirtied(ids, commit=False)
|
self.dirtied(ids, commit=False)
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
|
|
||||||
def set_custom(self, id, val, label=None, num=None,
|
def set_custom(self, id, val, label=None, num=None, append=False,
|
||||||
append=False, notify=True, extra=None, commit=True):
|
notify=True, extra=None, commit=True, allow_case_change=False):
|
||||||
self._set_custom(id, val, label=label, num=num, append=append,
|
rv = self._set_custom(id, val, label=label, num=num, append=append,
|
||||||
notify=notify, extra=extra)
|
notify=notify, extra=extra,
|
||||||
|
allow_case_change=allow_case_change)
|
||||||
self.dirtied([id], commit=False)
|
self.dirtied([id], commit=False)
|
||||||
if commit:
|
if commit:
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
|
return rv
|
||||||
|
|
||||||
def _set_custom(self, id_, val, label=None, num=None,
|
def _set_custom(self, id_, val, label=None, num=None, append=False,
|
||||||
append=False, notify=True, extra=None):
|
notify=True, extra=None, allow_case_change=False):
|
||||||
if label is not None:
|
if label is not None:
|
||||||
data = self.custom_column_label_map[label]
|
data = self.custom_column_label_map[label]
|
||||||
if num is not None:
|
if num is not None:
|
||||||
data = self.custom_column_num_map[num]
|
data = self.custom_column_num_map[num]
|
||||||
if data['datatype'] == 'composite':
|
if data['datatype'] == 'composite':
|
||||||
return None
|
return set()
|
||||||
if not data['editable']:
|
if not data['editable']:
|
||||||
raise ValueError('Column %r is not editable'%data['label'])
|
raise ValueError('Column %r is not editable'%data['label'])
|
||||||
table, lt = self.custom_table_names(data['num'])
|
table, lt = self.custom_table_names(data['num'])
|
||||||
@ -466,10 +468,11 @@ class CustomColumns(object):
|
|||||||
if data['datatype'] == 'series' and extra is None:
|
if data['datatype'] == 'series' and extra is None:
|
||||||
(val, extra) = self._get_series_values(val)
|
(val, extra) = self._get_series_values(val)
|
||||||
|
|
||||||
|
books_to_refresh = set()
|
||||||
if data['normalized']:
|
if data['normalized']:
|
||||||
if data['datatype'] == 'enumeration' and (
|
if data['datatype'] == 'enumeration' and (
|
||||||
val and val not in data['display']['enum_values']):
|
val and val not in data['display']['enum_values']):
|
||||||
return None
|
return books_to_refresh
|
||||||
if not append or not data['is_multiple']:
|
if not append or not data['is_multiple']:
|
||||||
self.conn.execute('DELETE FROM %s WHERE book=?'%lt, (id_,))
|
self.conn.execute('DELETE FROM %s WHERE book=?'%lt, (id_,))
|
||||||
self.conn.execute(
|
self.conn.execute(
|
||||||
@ -483,6 +486,7 @@ class CustomColumns(object):
|
|||||||
for x in set(set_val) - set(existing):
|
for x in set(set_val) - set(existing):
|
||||||
if x is None:
|
if x is None:
|
||||||
continue
|
continue
|
||||||
|
case_change = False
|
||||||
existing = list(self.all_custom(num=data['num']))
|
existing = list(self.all_custom(num=data['num']))
|
||||||
lx = [t.lower() if hasattr(t, 'lower') else t for t in existing]
|
lx = [t.lower() if hasattr(t, 'lower') else t for t in existing]
|
||||||
try:
|
try:
|
||||||
@ -492,13 +496,14 @@ class CustomColumns(object):
|
|||||||
if idx > -1:
|
if idx > -1:
|
||||||
ex = existing[idx]
|
ex = existing[idx]
|
||||||
xid = self.conn.get(
|
xid = self.conn.get(
|
||||||
'SELECT id FROM %s WHERE value=?'%table, (ex,), all=False)
|
'SELECT id FROM %s WHERE value=?'%table, (ex,), all=False)
|
||||||
if ex != x:
|
if ex != x:
|
||||||
|
case_change = True
|
||||||
self.conn.execute(
|
self.conn.execute(
|
||||||
'UPDATE %s SET value=? WHERE id=?'%table, (x, xid))
|
'UPDATE %s SET value=? WHERE id=?'%table, (x, xid))
|
||||||
else:
|
else:
|
||||||
xid = self.conn.execute(
|
xid = self.conn.execute(
|
||||||
'INSERT INTO %s(value) VALUES(?)'%table, (x,)).lastrowid
|
'INSERT INTO %s(value) VALUES(?)'%table, (x,)).lastrowid
|
||||||
if not self.conn.get(
|
if not self.conn.get(
|
||||||
'SELECT book FROM %s WHERE book=? AND value=?'%lt,
|
'SELECT book FROM %s WHERE book=? AND value=?'%lt,
|
||||||
(id_, xid), all=False):
|
(id_, xid), all=False):
|
||||||
@ -512,6 +517,10 @@ class CustomColumns(object):
|
|||||||
self.conn.execute(
|
self.conn.execute(
|
||||||
'''INSERT INTO %s(book, value)
|
'''INSERT INTO %s(book, value)
|
||||||
VALUES (?,?)'''%lt, (id_, xid))
|
VALUES (?,?)'''%lt, (id_, xid))
|
||||||
|
if case_change:
|
||||||
|
bks = self.conn.get('SELECT book FROM %s WHERE value=?'%lt,
|
||||||
|
(xid,))
|
||||||
|
books_to_refresh |= set([bk[0] for bk in bks])
|
||||||
nval = self.conn.get(
|
nval = self.conn.get(
|
||||||
'SELECT custom_%s FROM meta2 WHERE id=?'%data['num'],
|
'SELECT custom_%s FROM meta2 WHERE id=?'%data['num'],
|
||||||
(id_,), all=False)
|
(id_,), all=False)
|
||||||
@ -530,7 +539,7 @@ class CustomColumns(object):
|
|||||||
row_is_id=True)
|
row_is_id=True)
|
||||||
if notify:
|
if notify:
|
||||||
self.notify('metadata', [id_])
|
self.notify('metadata', [id_])
|
||||||
return nval
|
return books_to_refresh
|
||||||
|
|
||||||
def clean_custom(self):
|
def clean_custom(self):
|
||||||
st = ('DELETE FROM {table} WHERE (SELECT COUNT(id) FROM {lt} WHERE'
|
st = ('DELETE FROM {table} WHERE (SELECT COUNT(id) FROM {lt} WHERE'
|
||||||
|
@ -1495,7 +1495,8 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
elif column == 'title':
|
elif column == 'title':
|
||||||
self.set_title(id, val, notify=False)
|
self.set_title(id, val, notify=False)
|
||||||
elif column == 'publisher':
|
elif column == 'publisher':
|
||||||
self.set_publisher(id, val, notify=False)
|
books_to_refresh |= self.set_publisher(id, val, notify=False,
|
||||||
|
allow_case_change=allow_case_change)
|
||||||
elif column == 'rating':
|
elif column == 'rating':
|
||||||
self.set_rating(id, val, notify=False)
|
self.set_rating(id, val, notify=False)
|
||||||
elif column == 'tags':
|
elif column == 'tags':
|
||||||
@ -1637,35 +1638,32 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
self.conn.execute('DELETE FROM books_authors_link WHERE book=?',(id,))
|
self.conn.execute('DELETE FROM books_authors_link WHERE book=?',(id,))
|
||||||
books_to_refresh = set()
|
books_to_refresh = set()
|
||||||
for a in authors:
|
for a in authors:
|
||||||
|
case_change = False
|
||||||
if not a:
|
if not a:
|
||||||
continue
|
continue
|
||||||
a = a.strip().replace(',', '|')
|
a = a.strip().replace(',', '|')
|
||||||
if not isinstance(a, unicode):
|
if not isinstance(a, unicode):
|
||||||
a = a.decode(preferred_encoding, 'replace')
|
a = a.decode(preferred_encoding, 'replace')
|
||||||
aus = self.conn.get('SELECT id, name from authors WHERE name=?', (a,))
|
aus = self.conn.get('SELECT id, name FROM authors WHERE name=?', (a,))
|
||||||
if aus:
|
if aus:
|
||||||
author_id, name = aus[0]
|
aid, name = aus[0]
|
||||||
else:
|
|
||||||
author_id, name = (None, None)
|
|
||||||
if author_id:
|
|
||||||
aid = author_id
|
|
||||||
# Handle change of case
|
# Handle change of case
|
||||||
if allow_case_change and name != a:
|
if allow_case_change and name != a:
|
||||||
self.conn.execute('UPDATE authors SET name=? WHERE id=?', (a, aid))
|
self.conn.execute('''UPDATE authors
|
||||||
case_change = True
|
SET name=? WHERE id=?''', (a, aid))
|
||||||
|
case_change = True
|
||||||
else:
|
else:
|
||||||
aid = self.conn.execute('INSERT INTO authors(name) VALUES (?)', (a,)).lastrowid
|
aid = self.conn.execute('''INSERT INTO authors(name)
|
||||||
case_change = False
|
VALUES (?)''', (a,)).lastrowid
|
||||||
try:
|
try:
|
||||||
self.conn.execute('INSERT INTO books_authors_link(book, author) VALUES (?,?)',
|
self.conn.execute('''INSERT INTO books_authors_link(book, author)
|
||||||
(id, aid))
|
VALUES (?,?)''', (id, aid))
|
||||||
except IntegrityError: # Sometimes books specify the same author twice in their metadata
|
except IntegrityError: # Sometimes books specify the same author twice in their metadata
|
||||||
pass
|
pass
|
||||||
if case_change:
|
if case_change:
|
||||||
bks = self.conn.get('SELECT book FROM books_authors_link WHERE author=?',
|
bks = self.conn.get('''SELECT book FROM books_authors_link
|
||||||
(aid,))
|
WHERE author=?''', (aid,))
|
||||||
books_to_refresh |= set([bk[0] for bk in bks])
|
books_to_refresh |= set([bk[0] for bk in bks])
|
||||||
|
|
||||||
ss = self.author_sort_from_book(id, index_is_id=True)
|
ss = self.author_sort_from_book(id, index_is_id=True)
|
||||||
self.conn.execute('UPDATE books SET author_sort=? WHERE id=?',
|
self.conn.execute('UPDATE books SET author_sort=? WHERE id=?',
|
||||||
(ss, id))
|
(ss, id))
|
||||||
@ -1755,24 +1753,41 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
self.notify('metadata', [id])
|
self.notify('metadata', [id])
|
||||||
|
|
||||||
|
|
||||||
def set_publisher(self, id, publisher, notify=True, commit=True):
|
def set_publisher(self, id, publisher, notify=True, commit=True,
|
||||||
|
allow_case_change=False):
|
||||||
self.conn.execute('DELETE FROM books_publishers_link WHERE book=?',(id,))
|
self.conn.execute('DELETE FROM books_publishers_link WHERE book=?',(id,))
|
||||||
self.conn.execute('DELETE FROM publishers WHERE (SELECT COUNT(id) FROM books_publishers_link WHERE publisher=publishers.id) < 1')
|
self.conn.execute('''DELETE FROM publishers WHERE (SELECT COUNT(id)
|
||||||
|
FROM books_publishers_link
|
||||||
|
WHERE publisher=publishers.id) < 1''')
|
||||||
|
books_to_refresh = set()
|
||||||
if publisher:
|
if publisher:
|
||||||
|
case_change = False
|
||||||
if not isinstance(publisher, unicode):
|
if not isinstance(publisher, unicode):
|
||||||
publisher = publisher.decode(preferred_encoding, 'replace')
|
publisher = publisher.decode(preferred_encoding, 'replace')
|
||||||
pub = self.conn.get('SELECT id from publishers WHERE name=?', (publisher,), all=False)
|
pubx = self.conn.get('''SELECT id,name from publishers
|
||||||
if pub:
|
WHERE name=?''', (publisher,))
|
||||||
aid = pub
|
if pubx:
|
||||||
|
aid, cur_name = pubx[0]
|
||||||
|
if allow_case_change and publisher != cur_name:
|
||||||
|
self.conn.execute('''UPDATE publishers SET name=?
|
||||||
|
WHERE id=?''', (publisher, aid))
|
||||||
|
case_change = True
|
||||||
else:
|
else:
|
||||||
aid = self.conn.execute('INSERT INTO publishers(name) VALUES (?)', (publisher,)).lastrowid
|
aid = self.conn.execute('''INSERT INTO publishers(name)
|
||||||
self.conn.execute('INSERT INTO books_publishers_link(book, publisher) VALUES (?,?)', (id, aid))
|
VALUES (?)''', (publisher,)).lastrowid
|
||||||
self.dirtied([id], commit=False)
|
self.conn.execute('''INSERT INTO books_publishers_link(book, publisher)
|
||||||
if commit:
|
VALUES (?,?)''', (id, aid))
|
||||||
self.conn.commit()
|
if case_change:
|
||||||
self.data.set(id, self.FIELD_MAP['publisher'], publisher, row_is_id=True)
|
bks = self.conn.get('''SELECT book FROM books_publishers_link
|
||||||
if notify:
|
WHERE publisher=?''', (aid,))
|
||||||
self.notify('metadata', [id])
|
books_to_refresh |= set([bk[0] for bk in bks])
|
||||||
|
self.dirtied([id], commit=False)
|
||||||
|
if commit:
|
||||||
|
self.conn.commit()
|
||||||
|
self.data.set(id, self.FIELD_MAP['publisher'], publisher, row_is_id=True)
|
||||||
|
if notify:
|
||||||
|
self.notify('metadata', [id])
|
||||||
|
return books_to_refresh
|
||||||
|
|
||||||
def set_uuid(self, id, uuid, notify=True, commit=True):
|
def set_uuid(self, id, uuid, notify=True, commit=True):
|
||||||
if uuid:
|
if uuid:
|
||||||
@ -2144,7 +2159,8 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
'''
|
'''
|
||||||
if not append:
|
if not append:
|
||||||
self.conn.execute('DELETE FROM books_tags_link WHERE book=?', (id,))
|
self.conn.execute('DELETE FROM books_tags_link WHERE book=?', (id,))
|
||||||
self.conn.execute('DELETE FROM tags WHERE (SELECT COUNT(id) FROM books_tags_link WHERE tag=tags.id) < 1')
|
self.conn.execute('''DELETE FROM tags WHERE (SELECT COUNT(id)
|
||||||
|
FROM books_tags_link WHERE tag=tags.id) < 1''')
|
||||||
otags = self.get_tags(id)
|
otags = self.get_tags(id)
|
||||||
tags = self.cleanup_tags(tags)
|
tags = self.cleanup_tags(tags)
|
||||||
books_to_refresh = set()
|
books_to_refresh = set()
|
||||||
@ -2170,10 +2186,10 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
else:
|
else:
|
||||||
tid = self.conn.execute('INSERT INTO tags(name) VALUES(?)', (tag,)).lastrowid
|
tid = self.conn.execute('INSERT INTO tags(name) VALUES(?)', (tag,)).lastrowid
|
||||||
|
|
||||||
if not self.conn.get('SELECT book FROM books_tags_link WHERE book=? AND tag=?',
|
if not self.conn.get('''SELECT book FROM books_tags_link
|
||||||
(id, tid), all=False):
|
WHERE book=? AND tag=?''', (id, tid), all=False):
|
||||||
self.conn.execute('INSERT INTO books_tags_link(book, tag) VALUES (?,?)',
|
self.conn.execute('''INSERT INTO books_tags_link(book, tag)
|
||||||
(id, tid))
|
VALUES (?,?)''', (id, tid))
|
||||||
if case_changed:
|
if case_changed:
|
||||||
bks = self.conn.get('SELECT book FROM books_tags_link WHERE tag=?',
|
bks = self.conn.get('SELECT book FROM books_tags_link WHERE tag=?',
|
||||||
(tid,))
|
(tid,))
|
||||||
@ -2191,7 +2207,8 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
for tag in tags:
|
for tag in tags:
|
||||||
id = self.conn.get('SELECT id FROM tags WHERE name=?', (tag,), all=False)
|
id = self.conn.get('SELECT id FROM tags WHERE name=?', (tag,), all=False)
|
||||||
if id:
|
if id:
|
||||||
self.conn.execute('DELETE FROM books_tags_link WHERE tag=? AND book=?', (id, book_id))
|
self.conn.execute('''DELETE FROM books_tags_link
|
||||||
|
WHERE tag=? AND book=?''', (id, book_id))
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
self.data.refresh_ids(self, [book_id])
|
self.data.refresh_ids(self, [book_id])
|
||||||
if notify:
|
if notify:
|
||||||
@ -2235,31 +2252,41 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
pass
|
pass
|
||||||
return (val, None)
|
return (val, None)
|
||||||
|
|
||||||
def set_series(self, id, series, notify=True, commit=True):
|
def set_series(self, id, series, notify=True, commit=True, allow_case_change=True):
|
||||||
self.conn.execute('DELETE FROM books_series_link WHERE book=?',(id,))
|
self.conn.execute('DELETE FROM books_series_link WHERE book=?',(id,))
|
||||||
self.conn.execute('''DELETE FROM series
|
self.conn.execute('''DELETE FROM series
|
||||||
WHERE (SELECT COUNT(id) FROM books_series_link
|
WHERE (SELECT COUNT(id) FROM books_series_link
|
||||||
WHERE series=series.id) < 1''')
|
WHERE series=series.id) < 1''')
|
||||||
(series, idx) = self._get_series_values(series)
|
(series, idx) = self._get_series_values(series)
|
||||||
|
books_to_refresh = set()
|
||||||
if series:
|
if series:
|
||||||
|
case_change = False
|
||||||
if not isinstance(series, unicode):
|
if not isinstance(series, unicode):
|
||||||
series = series.decode(preferred_encoding, 'replace')
|
series = series.decode(preferred_encoding, 'replace')
|
||||||
series = series.strip()
|
series = series.strip()
|
||||||
series = u' '.join(series.split())
|
series = u' '.join(series.split())
|
||||||
s = self.conn.get('SELECT id from series WHERE name=?', (series,), all=False)
|
sx = self.conn.get('SELECT id,name from series WHERE name=?', (series,))
|
||||||
if s:
|
if sx:
|
||||||
aid = s
|
aid, cur_name = sx[0]
|
||||||
|
if allow_case_change and cur_name != series:
|
||||||
|
self.conn.execute('UPDATE series SET name=? WHERE id=?', (series, aid))
|
||||||
|
case_change = True
|
||||||
else:
|
else:
|
||||||
aid = self.conn.execute('INSERT INTO series(name) VALUES (?)', (series,)).lastrowid
|
aid = self.conn.execute('INSERT INTO series(name) VALUES (?)', (series,)).lastrowid
|
||||||
self.conn.execute('INSERT INTO books_series_link(book, series) VALUES (?,?)', (id, aid))
|
self.conn.execute('INSERT INTO books_series_link(book, series) VALUES (?,?)', (id, aid))
|
||||||
if idx:
|
if idx:
|
||||||
self.set_series_index(id, idx, notify=notify, commit=commit)
|
self.set_series_index(id, idx, notify=notify, commit=commit)
|
||||||
|
if case_change:
|
||||||
|
bks = self.conn.get('SELECT book FROM books_series_link WHERE series=?',
|
||||||
|
(aid,))
|
||||||
|
books_to_refresh |= set([bk[0] for bk in bks])
|
||||||
self.dirtied([id], commit=False)
|
self.dirtied([id], commit=False)
|
||||||
if commit:
|
if commit:
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
self.data.set(id, self.FIELD_MAP['series'], series, row_is_id=True)
|
self.data.set(id, self.FIELD_MAP['series'], series, row_is_id=True)
|
||||||
if notify:
|
if notify:
|
||||||
self.notify('metadata', [id])
|
self.notify('metadata', [id])
|
||||||
|
return books_to_refresh
|
||||||
|
|
||||||
def set_series_index(self, id, idx, notify=True, commit=True):
|
def set_series_index(self, id, idx, notify=True, commit=True):
|
||||||
if idx is None:
|
if idx is None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user