* src/DataViews/_PersonView.py: use new delete function
* src/GrampsDb/_DbUtils.py: add person delete function * src/Editors/_EditFamily.py: catch signals to update window svn: r8021
This commit is contained in:
parent
167b009dcd
commit
ad26af3f60
@ -9,6 +9,9 @@
|
||||
* src/ReportBase.py: fix source citations (0000867)
|
||||
|
||||
2007-01-30 Don Allingham <don@gramps-project.org>
|
||||
* src/DataViews/_PersonView.py: use new delete function
|
||||
* src/GrampsDb/_DbUtils.py: add person delete function
|
||||
* src/Editors/_EditFamily.py: catch signals to update window
|
||||
* src/plugins/EventCmp.py: (#886) properly handle CANCEL on save dialog
|
||||
* src/ReportBase/_ReportDialog.py: error reporting
|
||||
* src/plugins/NarrativeWeb.py: error reporting
|
||||
|
@ -60,6 +60,7 @@ import TreeTips
|
||||
import Errors
|
||||
import Config
|
||||
import const
|
||||
import GrampsDb
|
||||
|
||||
from Editors import EditPerson
|
||||
from Filters import SearchBar
|
||||
@ -596,63 +597,31 @@ class PersonView(PageView.PersonNavView):
|
||||
self.delete_person_response)
|
||||
|
||||
def delete_person_response(self):
|
||||
self.uistate.set_busy_cursor(1)
|
||||
"""
|
||||
Deletes the person from the database.
|
||||
"""
|
||||
# set the busy cursor, so the user knows that we are working
|
||||
self.uistate.set_busy_cursor(True)
|
||||
|
||||
# create the transaction
|
||||
trans = self.dbstate.db.transaction_begin()
|
||||
|
||||
active_name = NameDisplay.displayer.display(self.active_person)
|
||||
|
||||
if self.dbstate.db.get_default_person() == self.active_person:
|
||||
self.dbstate.db.set_default_person_handle(None)
|
||||
|
||||
for family_handle in self.active_person.get_family_handle_list():
|
||||
if not family_handle:
|
||||
continue
|
||||
family = self.dbstate.db.get_family_from_handle(family_handle)
|
||||
family_to_remove = False
|
||||
if self.active_person.get_handle() == family.get_father_handle():
|
||||
if family.get_mother_handle():
|
||||
family.set_father_handle(None)
|
||||
else:
|
||||
family_to_remove = True
|
||||
else:
|
||||
if family.get_father_handle():
|
||||
family.set_mother_handle(None)
|
||||
else:
|
||||
family_to_remove = True
|
||||
if family_to_remove:
|
||||
for child_ref in family.get_child_ref_list():
|
||||
child = self.dbstate.db.get_person_from_handle(child_ref.ref)
|
||||
child.remove_parent_family_handle(family_handle)
|
||||
self.dbstate.db.commit_person(child, trans)
|
||||
self.dbstate.db.remove_family(family_handle, trans)
|
||||
else:
|
||||
self.dbstate.db.commit_family(family, trans)
|
||||
|
||||
for family_handle in self.active_person.get_parent_family_handle_list():
|
||||
if family_handle:
|
||||
family = self.dbstate.db.get_family_from_handle(family_handle)
|
||||
family.remove_child_handle(self.active_person.get_handle())
|
||||
self.dbstate.db.commit_family(family, trans)
|
||||
|
||||
handle = self.active_person.get_handle()
|
||||
|
||||
person_list = [
|
||||
item[1] for item in
|
||||
self.dbstate.db.find_backlink_handles(handle,['Person'])]
|
||||
|
||||
for phandle in person_list:
|
||||
person = self.dbstate.db.get_person_from_handle(phandle)
|
||||
person.remove_handle_references('Person', handle)
|
||||
self.dbstate.db.commit_person(person, trans)
|
||||
|
||||
# create name to save
|
||||
person = self.active_person
|
||||
self.remove_from_person_list(person)
|
||||
self.dbstate.db.remove_person(handle, trans)
|
||||
active_name = _("Delete Person (%s)") % NameDisplay.displayer.display(person)
|
||||
|
||||
# delete the person from the database
|
||||
GrampsDb.delete_person_from_database(self.dbstate.db, person, trans)
|
||||
|
||||
# remove the person from the list
|
||||
self.remove_from_person_list(person)
|
||||
|
||||
# commit the transaction
|
||||
self.dbstate.db.transaction_commit(trans, active_name)
|
||||
|
||||
# select the previously active person, turn off the busy cursor
|
||||
self.uistate.phistory.back()
|
||||
self.dbstate.db.transaction_commit(
|
||||
trans, _("Delete Person (%s)") % active_name)
|
||||
self.uistate.set_busy_cursor(0)
|
||||
self.uistate.set_busy_cursor(False)
|
||||
|
||||
def build_columns(self):
|
||||
for column in self.columns:
|
||||
|
@ -404,10 +404,19 @@ class EditFamily(EditPrimary):
|
||||
self.load_data()
|
||||
|
||||
def check_for_change(self,handles):
|
||||
|
||||
chandles = set([ c.ref for c in self.obj.get_child_ref_list() if c ])
|
||||
for node in handles:
|
||||
if node in self.phandles:
|
||||
if node == self.obj.get_father_handle():
|
||||
self.obj.set_father_handle(None)
|
||||
self.reload_people()
|
||||
elif node == self.obj.get_mother_handle():
|
||||
self.obj.set_mother_handle(None)
|
||||
self.reload_people()
|
||||
elif node in chandles:
|
||||
new_list = [ c for c in self.obj.get_child_ref_list() if c.ref != node ]
|
||||
self.obj.set_child_ref_list(new_list)
|
||||
self.reload_people()
|
||||
break;
|
||||
|
||||
def reload_people(self):
|
||||
fhandle = self.obj.get_father_handle()
|
||||
|
@ -25,6 +25,50 @@ from gettext import gettext as _
|
||||
import RelLib
|
||||
from BasicUtils import UpdateCallback
|
||||
|
||||
|
||||
def delete_person_from_database(db, person, trans):
|
||||
"""
|
||||
Deletes a person from the database, cleaning up all associated references.
|
||||
"""
|
||||
|
||||
# clear out the default person if the person is the default person
|
||||
if db.get_default_person() == person:
|
||||
db.set_default_person_handle(None)
|
||||
|
||||
# loop through the family list
|
||||
for family_handle in [ f for f in person.get_family_handle_list() if f ]:
|
||||
|
||||
family = db.get_family_from_handle(family_handle)
|
||||
|
||||
if person.get_handle() == family.get_father_handle():
|
||||
family.set_father_handle(None)
|
||||
else:
|
||||
family.set_mother_handle(None)
|
||||
|
||||
if not family.get_father_handle() and not family.get_mother_handle() and \
|
||||
not family.get_child_ref_list():
|
||||
db.remove_family(family_handle, trans)
|
||||
else:
|
||||
db.commit_family(family, trans)
|
||||
|
||||
for family_handle in person.get_parent_family_handle_list():
|
||||
if family_handle:
|
||||
family = db.get_family_from_handle(family_handle)
|
||||
family.remove_child_handle(person.get_handle())
|
||||
db.commit_family(family, trans)
|
||||
|
||||
handle = person.get_handle()
|
||||
|
||||
person_list = [
|
||||
item[1] for item in
|
||||
db.find_backlink_handles(handle,['Person'])]
|
||||
|
||||
for phandle in person_list:
|
||||
p = db.get_person_from_handle(phandle)
|
||||
p.remove_handle_references('Person', handle)
|
||||
db.commit_person(person, trans)
|
||||
db.remove_person(handle, trans)
|
||||
|
||||
def remove_family_relationships(db, family_handle, trans=None):
|
||||
family = db.get_family_from_handle(family_handle)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user