Add bulk setting of the rest of the custom column types

This commit is contained in:
Charles Haley 2010-08-18 08:08:28 +01:00
parent 2464da207e
commit d3e2c90a23
2 changed files with 35 additions and 14 deletions

View File

@ -403,9 +403,7 @@ class BulkBase(Base):
val = self.getter() val = self.getter()
val = self.normalize_ui_val(val) val = self.normalize_ui_val(val)
if val != self.initial_val: if val != self.initial_val:
for book_id in book_ids: self.db.set_custom_bulk(book_ids, val, num=self.col_id, notify=notify)
QCoreApplication.processEvents()
self.db.set_custom(book_id, val, num=self.col_id, notify=notify)
class BulkBool(BulkBase, Bool): class BulkBool(BulkBase, Bool):
pass pass
@ -448,18 +446,21 @@ class BulkSeries(BulkBase):
val = self.normalize_ui_val(val) val = self.normalize_ui_val(val)
update_indices = self.idx_widget.checkState() update_indices = self.idx_widget.checkState()
if val != '': if val != '':
extras = []
next_index = self.db.get_next_cc_series_num_for(val, num=self.col_id)
for book_id in book_ids: for book_id in book_ids:
QCoreApplication.processEvents() QCoreApplication.processEvents()
if update_indices: if update_indices:
if tweaks['series_index_auto_increment'] == 'next': if tweaks['series_index_auto_increment'] == 'next':
s_index = self.db.get_next_cc_series_num_for\ s_index = next_index
(val, num=self.col_id) next_index += 1
else: else:
s_index = 1.0 s_index = 1.0
else: else:
s_index = self.db.get_custom_extra(book_id, num=self.col_id, s_index = self.db.get_custom_extra(book_id, num=self.col_id,
index_is_id=True) index_is_id=True)
self.db.set_custom(book_id, val, extra=s_index, extras.append(s_index)
self.db.set_custom_bulk(book_ids, val, extras=extras,
num=self.col_id, notify=notify) num=self.col_id, notify=notify)
class RemoveTags(QWidget): class RemoveTags(QWidget):
@ -540,14 +541,13 @@ class BulkText(BulkBase):
add = set([v.strip() for v in txt.split(',')]) add = set([v.strip() for v in txt.split(',')])
else: else:
add = set() add = set()
self.db.set_custom_bulk(book_ids, add=add, remove=remove, num=self.col_id) self.db.set_custom_bulk_multiple(book_ids, add=add, remove=remove,
num=self.col_id)
else: else:
val = self.getter() val = self.getter()
val = self.normalize_ui_val(val) val = self.normalize_ui_val(val)
if val != self.initial_val: if val != self.initial_val:
for book_id in book_ids: self.db.set_custom_bulk(book_ids, val, num=self.col_id, notify=notify)
QCoreApplication.processEvents()
self.db.set_custom(book_id, val, num=self.col_id, notify=notify)
def getter(self, original_value = None): def getter(self, original_value = None):
if self.col_metadata['is_multiple']: if self.col_metadata['is_multiple']:

View File

@ -313,7 +313,7 @@ class CustomColumns(object):
self.conn.commit() self.conn.commit()
return changed return changed
def set_custom_bulk(self, ids, add=[], remove=[], def set_custom_bulk_multiple(self, ids, add=[], remove=[],
label=None, num=None, notify=False): label=None, num=None, notify=False):
''' '''
Fast algorithm for updating custom column is_multiple datatypes. Fast algorithm for updating custom column is_multiple datatypes.
@ -394,7 +394,30 @@ class CustomColumns(object):
if notify: if notify:
self.notify('metadata', ids) self.notify('metadata', ids)
def set_custom(self, id_, val, label=None, num=None, def set_custom_bulk(self, ids, val, label=None, num=None,
append=False, notify=True, extras=None):
'''
Change the value of a column for a set of books. The ids parameter is a
list of book ids to change. The extra field must be None or a list the
same length as ids.
'''
if extras is not None and len(extras) != len(ids):
raise ValueError('Lentgh of ids and extras is not the same')
ev = None
for idx,id in enumerate(ids):
if extras is not None:
ev = extras[idx]
self._set_custom(id, val, label=label, num=num, append=append,
notify=notify, extra=ev)
self.conn.commit()
def set_custom(self, id, val, label=None, num=None,
append=False, notify=True, extra=None):
self._set_custom(id, val, label=label, num=num, append=append,
notify=notify, extra=extra)
self.conn.commit()
def _set_custom(self, id_, val, label=None, num=None,
append=False, notify=True, extra=None): append=False, notify=True, extra=None):
if label is not None: if label is not None:
data = self.custom_column_label_map[label] data = self.custom_column_label_map[label]
@ -450,7 +473,6 @@ 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))
self.conn.commit()
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)
@ -462,7 +484,6 @@ class CustomColumns(object):
self.conn.execute( self.conn.execute(
'INSERT INTO %s(book,value) VALUES (?,?)'%table, 'INSERT INTO %s(book,value) VALUES (?,?)'%table,
(id_, val)) (id_, val))
self.conn.commit()
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)