Store original object during editor initialisation

This commit is contained in:
Nick Hall 2015-12-29 19:45:05 +00:00
parent 715277d9ac
commit 40ca8a2da4
2 changed files with 11 additions and 13 deletions

View File

@ -769,10 +769,9 @@ class EditPerson(EditPrimary):
f.set_child_ref_list(new_order)
error = False
if not self.added:
original = self.db.get_person_from_handle(self.obj.handle)
if self.original:
(female, male, unknown) = _select_gender[self.obj.get_gender()]
if male and original.get_gender() != Person.MALE:
if male and self.original.get_gender() != Person.MALE:
for tmp_handle in self.obj.get_family_handle_list():
temp_family = self.db.get_family_from_handle(tmp_handle)
if self.obj == temp_family.get_mother_handle():
@ -781,7 +780,7 @@ class EditPerson(EditPrimary):
else:
temp_family.set_mother_handle(None)
temp_family.set_father_handle(self.obj)
elif female and original != Person.FEMALE:
elif female and self.original != Person.FEMALE:
for tmp_handle in self.obj.get_family_handle_list():
temp_family = self.db.get_family_from_handle(tmp_handle)
if self.obj == temp_family.get_father_handle():
@ -790,7 +789,7 @@ class EditPerson(EditPrimary):
else:
temp_family.set_father_handle(None)
temp_family.set_mother_handle(self.obj)
elif unknown and original.get_gender() != Person.UNKNOWN:
elif unknown and self.original.get_gender() != Person.UNKNOWN:
for tmp_handle in self.obj.get_family_handle_list():
temp_family = self.db.get_family_from_handle(tmp_handle)
if self.obj == temp_family.get_father_handle():

View File

@ -78,6 +78,10 @@ class EditPrimary(ManagedWindow, DbGUIElement):
ManagedWindow.__init__(self, uistate, track, obj)
DbGUIElement.__init__(self, self.db)
self.original = None
if self.obj.handle:
self.original = self.get_from_handle(self.obj.handle)
self._local_init()
self._set_size()
self._create_tabbed_pages()
@ -251,16 +255,11 @@ class EditPrimary(ManagedWindow, DbGUIElement):
def data_has_changed(self):
if self.db.readonly:
return False
elif self.obj.handle:
orig = self.get_from_handle(self.obj.handle)
if orig:
cmp_obj = orig
else:
cmp_obj = self.empty_object()
return cmp_obj.serialize()[1:] != self.obj.serialize()[1:]
if self.original:
cmp_obj = self.original
else:
cmp_obj = self.empty_object()
return cmp_obj.serialize()[1:] != self.obj.serialize()[1:]
return cmp_obj.serialize()[1:] != self.obj.serialize()[1:]
def save(self, *obj):
""" Save changes and close. Inheriting classes must implement this