parent
3150fae2b8
commit
c1aeb6b203
@ -44,7 +44,7 @@ import glob
|
|||||||
from . import (DbReadBase, DbWriteBase, DbUndo, DBLOGNAME, DBUNDOFN,
|
from . import (DbReadBase, DbWriteBase, DbUndo, DBLOGNAME, DBUNDOFN,
|
||||||
KEY_TO_CLASS_MAP, REFERENCE_KEY, PERSON_KEY, FAMILY_KEY,
|
KEY_TO_CLASS_MAP, REFERENCE_KEY, PERSON_KEY, FAMILY_KEY,
|
||||||
CITATION_KEY, SOURCE_KEY, EVENT_KEY, MEDIA_KEY, PLACE_KEY,
|
CITATION_KEY, SOURCE_KEY, EVENT_KEY, MEDIA_KEY, PLACE_KEY,
|
||||||
REPOSITORY_KEY, NOTE_KEY, TAG_KEY)
|
REPOSITORY_KEY, NOTE_KEY, TAG_KEY, TXNADD, TXNDEL)
|
||||||
from ..errors import HandleError
|
from ..errors import HandleError
|
||||||
from ..utils.callback import Callback
|
from ..utils.callback import Callback
|
||||||
from ..updatecallback import UpdateCallback
|
from ..updatecallback import UpdateCallback
|
||||||
@ -150,8 +150,8 @@ class DbGenericUndo(DbUndo):
|
|||||||
pickle.loads(self.undodb[record_id])
|
pickle.loads(self.undodb[record_id])
|
||||||
|
|
||||||
if key != REFERENCE_KEY:
|
if key != REFERENCE_KEY:
|
||||||
self.undo_signals(new_data, handle, key,
|
self.undo_signals(trans_type, handle,
|
||||||
db.emit, SIGBASE[key])
|
db.emit, SIGBASE[key], False)
|
||||||
self.db._txn_commit()
|
self.db._txn_commit()
|
||||||
except:
|
except:
|
||||||
self.db._txn_abort()
|
self.db._txn_abort()
|
||||||
@ -201,8 +201,8 @@ class DbGenericUndo(DbUndo):
|
|||||||
pickle.loads(self.undodb[record_id])
|
pickle.loads(self.undodb[record_id])
|
||||||
|
|
||||||
if key != REFERENCE_KEY:
|
if key != REFERENCE_KEY:
|
||||||
self.undo_signals(old_data, handle, key,
|
self.undo_signals(trans_type, handle,
|
||||||
db.emit, SIGBASE[key])
|
db.emit, SIGBASE[key], True)
|
||||||
self.db._txn_commit()
|
self.db._txn_commit()
|
||||||
except:
|
except:
|
||||||
self.db._txn_abort()
|
self.db._txn_abort()
|
||||||
@ -257,20 +257,19 @@ class DbGenericUndo(DbUndo):
|
|||||||
obj = self.db._get_table_func(cls)["class_func"].create(data)
|
obj = self.db._get_table_func(cls)["class_func"].create(data)
|
||||||
self.db._update_secondary_values(obj)
|
self.db._update_secondary_values(obj)
|
||||||
|
|
||||||
def undo_signals(self, data, handle, obj_key, emit, signal_root):
|
def undo_signals(self, trans_type, handle, emit, signal_root, reverse):
|
||||||
"""
|
"""
|
||||||
Helper method to undo/redo the changes made
|
Helper method to undo/redo the changes made
|
||||||
"""
|
"""
|
||||||
cls = KEY_TO_CLASS_MAP[obj_key]
|
if ((not reverse) and trans_type == TXNADD) \
|
||||||
table = cls.lower()
|
or (reverse and trans_type == TXNDEL):
|
||||||
if data is None:
|
typ = '-add'
|
||||||
emit(signal_root + '-delete', ([handle],))
|
elif not reverse and trans_type == TXNDEL \
|
||||||
else:
|
or reverse and trans_type == TXNADD:
|
||||||
if self.db.has_handle(obj_key, handle):
|
typ = '-delete'
|
||||||
signal = signal_root + '-update'
|
else: # TXNUPD
|
||||||
else:
|
typ = '-update'
|
||||||
signal = signal_root + '-add'
|
emit(signal_root + typ, ([handle],))
|
||||||
emit(signal, ([handle],))
|
|
||||||
|
|
||||||
class Cursor:
|
class Cursor:
|
||||||
def __init__(self, iterator):
|
def __init__(self, iterator):
|
||||||
|
@ -244,8 +244,9 @@ class DbUndo:
|
|||||||
pickle.loads(self.undodb[record_id])
|
pickle.loads(self.undodb[record_id])
|
||||||
|
|
||||||
if key != REFERENCE_KEY:
|
if key != REFERENCE_KEY:
|
||||||
self.undo_signals(old_data, handle, self.mapbase[key],
|
self.undo_signals(trans_type, handle,
|
||||||
db.emit, _SIGBASE[key])
|
db.emit, _SIGBASE[key], True)
|
||||||
|
|
||||||
# Notify listeners
|
# Notify listeners
|
||||||
if db.undo_callback:
|
if db.undo_callback:
|
||||||
if self.undo_count > 0:
|
if self.undo_count > 0:
|
||||||
@ -289,8 +290,8 @@ class DbUndo:
|
|||||||
pickle.loads(self.undodb[record_id])
|
pickle.loads(self.undodb[record_id])
|
||||||
|
|
||||||
if key != REFERENCE_KEY:
|
if key != REFERENCE_KEY:
|
||||||
self.undo_signals(new_data, handle, self.mapbase[key],
|
self.undo_signals(trans_type, handle,
|
||||||
db.emit, _SIGBASE[key])
|
db.emit, _SIGBASE[key], False)
|
||||||
# Notify listeners
|
# Notify listeners
|
||||||
if db.undo_callback:
|
if db.undo_callback:
|
||||||
db.undo_callback(_("_Undo %s")
|
db.undo_callback(_("_Undo %s")
|
||||||
@ -336,24 +337,19 @@ class DbUndo:
|
|||||||
self.db._log_error()
|
self.db._log_error()
|
||||||
raise DbError(msg)
|
raise DbError(msg)
|
||||||
|
|
||||||
def undo_signals(self, data, handle, db_map, emit, signal_root):
|
def undo_signals(self, trans_type, handle, emit, signal_root, reverse):
|
||||||
"""
|
"""
|
||||||
Helper method to undo/redo the changes made
|
Helper method to undo/redo the changes made
|
||||||
"""
|
"""
|
||||||
try:
|
if ((not reverse) and trans_type == TXNADD) \
|
||||||
if data is None:
|
or (reverse and trans_type == TXNDEL):
|
||||||
emit(signal_root + '-delete', ([handle.decode('utf-8')],))
|
typ = '-add'
|
||||||
else:
|
elif not reverse and trans_type == TXNDEL \
|
||||||
ex_data = db_map.get(handle, txn=self.txn)
|
or reverse and trans_type == TXNADD:
|
||||||
if ex_data:
|
typ = '-delete'
|
||||||
signal = signal_root + '-update'
|
else: # TXNUPD
|
||||||
else:
|
typ = '-update'
|
||||||
signal = signal_root + '-add'
|
emit(signal_root + typ, ([handle.decode('utf-8')],))
|
||||||
emit(signal, ([handle.decode('utf-8')],))
|
|
||||||
|
|
||||||
except DBERRS as msg:
|
|
||||||
self.db._log_error()
|
|
||||||
raise DbError(msg)
|
|
||||||
|
|
||||||
undo_count = property(lambda self:len(self.undoq))
|
undo_count = property(lambda self:len(self.undoq))
|
||||||
redo_count = property(lambda self:len(self.redoq))
|
redo_count = property(lambda self:len(self.redoq))
|
||||||
|
Loading…
Reference in New Issue
Block a user