gramps/src/GrampsDb/_DbUtils.py

130 lines
4.2 KiB
Python
Raw Normal View History

2006-03-18 07:00:23 +05:30
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2004-2005 Donald N. Allingham
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# $Id: __init__.py 6086 2006-03-06 03:54:58Z dallingham $
import RelLib
2006-03-18 07:00:23 +05:30
def remove_family_relationships(db, family_handle, trans=None):
2006-03-18 08:51:03 +05:30
family = db.get_family_from_handle(family_handle)
2006-03-18 07:00:23 +05:30
if trans == None:
need_commit = True
trans = db.transaction_begin()
else:
need_commit = False
for phandle in [ family.get_father_handle(),
family.get_mother_handle()]:
if phandle:
person = db.get_person_from_handle(phandle)
2006-03-18 08:51:03 +05:30
person.remove_family_handle(family_handle)
db.commit_person(person, trans)
2006-03-18 07:00:23 +05:30
for phandle in family.get_child_handle_list():
person = db.get_person_from_handle(phandle)
2006-03-18 08:51:03 +05:30
person.remove_parent_family_handle(family_handle)
db.commit_person(person, trans)
2006-03-18 07:00:23 +05:30
2006-03-18 08:51:03 +05:30
db.remove_family(family_handle, trans)
2006-03-18 07:00:23 +05:30
if need_commit:
2006-03-18 08:51:03 +05:30
db.transaction_commit(trans, _("Remove Family"))
2006-03-18 07:00:23 +05:30
def remove_parent_from_family(db, person_handle, family_handle, trans=None):
"""
Removes a person as either the father or mother of a family,
deleting the family if it becomes empty.
"""
person = db.get_person_from_handle(person_handle)
family = db.get_family_from_handle(family_handle)
if trans == None:
need_commit = True
trans = db.transaction_begin()
else:
need_commit = False
person.remove_family_handle(family_handle)
if family.get_father_handle() == person_handle:
family.set_father_handle(None)
elif family.get_mother_handle() == person_handle:
family.set_mother_handle(None)
if (not family.get_father_handle() and not family.get_mother_handle() and
len(family.get_child_handle_list()) <= 1):
db.remove_family(family_handle, trans)
msg = _("Remove father from family")
else:
db.commit_family(family, trans)
msg = _("Remove mother from family")
db.commit_person(person, trans)
if need_commit:
db.transaction_commit(trans,msg)
def remove_child_from_family(db, person_handle, family_handle, trans=None):
"""
Removes a person as a child of the family, deleting the family if
it becomes empty.
"""
person = db.get_person_from_handle(person_handle)
family = db.get_family_from_handle(family_handle)
person.remove_parent_family_handle(family_handle)
family.remove_child_handle(person_handle)
if trans == None:
need_commit = True
trans = db.transaction_begin()
else:
need_commit = False
if (not family.get_father_handle() and not family.get_mother_handle() and
len(family.get_child_handle_list()) <= 1):
db.remove_family(family_handle, trans)
else:
db.commit_family(family, trans)
db.commit_person(person, trans)
if need_commit:
db.transaction_commit(trans,_("Remove child from family"))
def add_child_to_family(db, family, child, mrel=(RelLib.Person.CHILD_BIRTH,''),
frel=(RelLib.Person.CHILD_BIRTH,''), trans=None):
family.add_child_handle(child.handle)
child.add_parent_family_handle(family.handle, mrel, frel )
if trans == None:
need_commit = True
trans = db.transaction_begin()
else:
need_commit = False
db.commit_family(family,trans)
db.commit_person(person,trans)
if need_commit:
db.transaction_commit(trans, _('Add child to family') )