2005-03-30 01:45:14 +00:00
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2007-06-28 05:41:40 +00:00
|
|
|
# Copyright (C) 2000-2007 Donald N. Allingham
|
2005-03-30 01:45:14 +00:00
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
2007-10-07 03:19:35 +00:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
2005-03-30 01:45:14 +00:00
|
|
|
# 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
|
|
|
|
#
|
|
|
|
|
2008-02-18 10:09:50 +00:00
|
|
|
# $Id:_MergePerson.py 9912 2008-01-22 09:17:46Z acraphae $
|
2005-03-30 01:45:14 +00:00
|
|
|
|
2005-05-11 14:04:47 +00:00
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GTK/Gnome modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import gtk
|
|
|
|
import pango
|
|
|
|
|
2005-03-30 01:45:14 +00:00
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2008-02-21 08:56:39 +00:00
|
|
|
from TransUtils import sgettext as _
|
2007-10-08 16:41:39 +00:00
|
|
|
import gen.lib
|
2006-05-31 02:41:46 +00:00
|
|
|
from ReportBase import ReportUtils
|
2007-06-28 05:41:40 +00:00
|
|
|
from BasicUtils import name_displayer
|
2005-03-30 01:45:14 +00:00
|
|
|
import const
|
2005-08-06 02:57:37 +00:00
|
|
|
import DateHandler
|
2008-02-18 10:09:50 +00:00
|
|
|
from QuestionDialog import ErrorDialog
|
2005-12-06 06:38:09 +00:00
|
|
|
import GrampsDisplay
|
2006-04-26 23:38:32 +00:00
|
|
|
import ManagedWindow
|
2007-10-08 04:02:34 +00:00
|
|
|
import gen.utils
|
2009-05-14 20:15:59 +00:00
|
|
|
from glade import Glade
|
2005-03-30 01:45:14 +00:00
|
|
|
|
2009-02-26 10:02:00 +00:00
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS constants
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
WIKI_HELP_PAGE = '%s_-_Entering_and_Editing_Data:_Detailed_-_part_3' % const.URL_MANUAL_PAGE
|
|
|
|
WIKI_HELP_SEC = _('manual|Merge_People')
|
2009-05-14 20:15:59 +00:00
|
|
|
_GLADE_FILE = 'mergedata.glade'
|
2009-02-26 10:02:00 +00:00
|
|
|
|
2005-04-26 16:04:21 +00:00
|
|
|
sex = ( _("female"), _("male"), _("unknown"))
|
2005-03-30 01:45:14 +00:00
|
|
|
|
2006-05-25 21:02:49 +00:00
|
|
|
class PersonCompare(ManagedWindow.ManagedWindow):
|
2006-04-26 23:38:32 +00:00
|
|
|
|
2006-05-25 04:08:05 +00:00
|
|
|
def __init__(self, dbstate, uistate, person1, person2, update=None) :
|
2006-04-26 23:38:32 +00:00
|
|
|
|
2007-10-07 03:19:35 +00:00
|
|
|
ManagedWindow.ManagedWindow.__init__(self, uistate, [], self.__class__)
|
2009-05-14 20:15:59 +00:00
|
|
|
self.glade = Glade(_GLADE_FILE, toplevel='mergedata')
|
|
|
|
window = self.glade.toplevel
|
2005-03-30 01:45:14 +00:00
|
|
|
|
2009-04-18 03:10:50 +00:00
|
|
|
window.show()
|
|
|
|
self.text1 = self.glade.get_object('text1')
|
|
|
|
self.text2 = self.glade.get_object('text2')
|
2006-04-26 23:38:32 +00:00
|
|
|
self.db = dbstate.db
|
2005-03-30 01:45:14 +00:00
|
|
|
|
|
|
|
self.p1 = person1
|
|
|
|
self.p2 = person2
|
|
|
|
self.update = update
|
|
|
|
|
2009-04-18 03:10:50 +00:00
|
|
|
self.set_window(window, self.glade.get_object('merge_title'),
|
2006-04-26 23:38:32 +00:00
|
|
|
_("Compare People"))
|
2005-03-30 01:45:14 +00:00
|
|
|
self.display(self.text1.get_buffer(), person1)
|
|
|
|
self.display(self.text2.get_buffer(), person2)
|
|
|
|
|
2009-04-18 03:10:50 +00:00
|
|
|
self.glade.get_object('merge_cancel').connect('clicked', self.close)
|
|
|
|
self.glade.get_object('close').connect('clicked', self.merge)
|
|
|
|
self.glade.get_object('merge_help').connect('clicked', self.help)
|
2005-03-30 01:45:14 +00:00
|
|
|
|
2007-10-07 03:19:35 +00:00
|
|
|
def help(self, obj):
|
2005-05-11 14:04:47 +00:00
|
|
|
"""Display the relevant portion of GRAMPS manual"""
|
2008-04-05 14:17:15 +00:00
|
|
|
GrampsDisplay.help(webpage = WIKI_HELP_PAGE, section = WIKI_HELP_SEC)
|
2005-05-11 14:04:47 +00:00
|
|
|
|
2007-10-07 03:19:35 +00:00
|
|
|
def merge(self, obj):
|
|
|
|
if check_for_spouse(self.p1, self.p2):
|
2008-02-18 10:09:50 +00:00
|
|
|
ErrorDialog(
|
2007-10-07 03:19:35 +00:00
|
|
|
_("Cannot merge people"),
|
2005-08-18 05:58:28 +00:00
|
|
|
_("Spouses cannot be merged. To merge these people, "
|
|
|
|
"you must first break the relationship between them."))
|
2007-10-07 03:19:35 +00:00
|
|
|
elif check_for_child(self.p1, self.p2):
|
2008-02-18 10:09:50 +00:00
|
|
|
ErrorDialog(
|
2007-10-07 03:19:35 +00:00
|
|
|
_("Cannot merge people"),
|
2005-08-18 05:58:28 +00:00
|
|
|
_("A parent and child cannot be merged. To merge these "
|
|
|
|
"people, you must first break the relationship between "
|
|
|
|
"them."))
|
2005-03-30 01:45:14 +00:00
|
|
|
else:
|
2009-04-18 03:10:50 +00:00
|
|
|
if self.glade.get_object('select1').get_active():
|
2007-10-07 03:19:35 +00:00
|
|
|
merge = MergePeople(self.db, self.p1, self.p2)
|
2005-08-18 05:58:28 +00:00
|
|
|
else:
|
2007-10-07 03:19:35 +00:00
|
|
|
merge = MergePeople(self.db, self.p2, self.p1)
|
2006-04-26 23:38:32 +00:00
|
|
|
self.close()
|
2005-12-06 06:38:09 +00:00
|
|
|
merge.merge()
|
2006-05-25 04:08:05 +00:00
|
|
|
if self.update:
|
|
|
|
self.update()
|
2005-03-30 01:45:14 +00:00
|
|
|
|
|
|
|
def add(self, tobj, tag, text):
|
2005-03-31 03:30:16 +00:00
|
|
|
text += "\n"
|
2007-10-07 03:19:35 +00:00
|
|
|
tobj.insert_with_tags(tobj.get_end_iter(), text, tag)
|
2005-03-30 01:45:14 +00:00
|
|
|
|
|
|
|
def display(self, tobj, person):
|
|
|
|
normal = tobj.create_tag()
|
2007-10-07 03:19:35 +00:00
|
|
|
normal.set_property('indent', 10)
|
|
|
|
normal.set_property('pixels-above-lines', 1)
|
|
|
|
normal.set_property('pixels-below-lines', 1)
|
2005-03-30 01:45:14 +00:00
|
|
|
indent = tobj.create_tag()
|
2007-10-07 03:19:35 +00:00
|
|
|
indent.set_property('indent', 30)
|
|
|
|
indent.set_property('pixels-above-lines', 1)
|
|
|
|
indent.set_property('pixels-below-lines', 1)
|
2005-03-30 01:45:14 +00:00
|
|
|
title = tobj.create_tag()
|
2007-10-07 03:19:35 +00:00
|
|
|
title.set_property('weight', pango.WEIGHT_BOLD)
|
|
|
|
title.set_property('scale', pango.SCALE_LARGE)
|
|
|
|
self.add(tobj, title, name_displayer.display(person))
|
2009-04-18 03:10:50 +00:00
|
|
|
self.add(tobj, normal, "%s:\t%s" % (_('ID'),
|
|
|
|
person.get_gramps_id()))
|
|
|
|
self.add(tobj, normal, "%s:\t%s" % (_('Gender'),
|
|
|
|
sex[person.get_gender()]))
|
2006-03-31 04:19:06 +00:00
|
|
|
bref = person.get_birth_ref()
|
|
|
|
if bref:
|
2009-04-18 03:10:50 +00:00
|
|
|
self.add(tobj, normal, "%s:\t%s" % (_('Birth'),
|
|
|
|
self.get_event_info(bref.ref)))
|
2006-03-31 04:19:06 +00:00
|
|
|
dref = person.get_death_ref()
|
|
|
|
if dref:
|
2009-04-18 03:10:50 +00:00
|
|
|
self.add(tobj, normal, "%s:\t%s" % (_('Death'),
|
|
|
|
self.get_event_info(dref.ref)))
|
2005-03-31 03:30:16 +00:00
|
|
|
|
|
|
|
nlist = person.get_alternate_names()
|
|
|
|
if len(nlist) > 0:
|
2007-10-07 03:19:35 +00:00
|
|
|
self.add(tobj, title, _("Alternate Names"))
|
2005-03-31 03:30:16 +00:00
|
|
|
for name in nlist:
|
2009-04-18 03:10:50 +00:00
|
|
|
self.add(tobj, normal,
|
|
|
|
name_displayer.display_name(name))
|
2005-03-31 03:30:16 +00:00
|
|
|
|
2006-04-26 23:38:32 +00:00
|
|
|
elist = person.get_event_ref_list()
|
2005-03-30 01:45:14 +00:00
|
|
|
if len(elist) > 0:
|
2007-10-07 03:19:35 +00:00
|
|
|
self.add(tobj, title, _("Events"))
|
2006-04-26 23:38:32 +00:00
|
|
|
for event_ref in person.get_event_ref_list():
|
|
|
|
event_handle = event_ref.ref
|
|
|
|
name = str(
|
|
|
|
self.db.get_event_from_handle(event_handle).get_type())
|
2009-04-18 03:10:50 +00:00
|
|
|
self.add(tobj, normal, "%s:\t%s" %
|
|
|
|
(name, self.get_event_info(event_handle)))
|
2005-03-30 01:45:14 +00:00
|
|
|
plist = person.get_parent_family_handle_list()
|
2005-03-31 03:30:16 +00:00
|
|
|
|
2005-03-30 01:45:14 +00:00
|
|
|
if len(plist) > 0:
|
2007-10-07 03:19:35 +00:00
|
|
|
self.add(tobj, title, _("Parents"))
|
2005-03-30 01:45:14 +00:00
|
|
|
for fid in person.get_parent_family_handle_list():
|
2007-10-07 03:19:35 +00:00
|
|
|
(fn, mn, gid) = self.get_parent_info(fid)
|
|
|
|
self.add(tobj, normal, "%s:\t%s" % (_('Family ID'), gid))
|
2005-03-30 01:45:14 +00:00
|
|
|
if fn:
|
2007-10-07 03:19:35 +00:00
|
|
|
self.add(tobj, indent, "%s:\t%s" % (_('Father'), fn))
|
2005-03-30 01:45:14 +00:00
|
|
|
if mn:
|
2007-10-07 03:19:35 +00:00
|
|
|
self.add(tobj, indent, "%s:\t%s" % (_('Mother'), mn))
|
2005-03-30 01:45:14 +00:00
|
|
|
else:
|
2007-10-07 03:19:35 +00:00
|
|
|
self.add(tobj, normal, _("No parents found"))
|
2005-03-30 01:45:14 +00:00
|
|
|
|
2007-10-07 03:19:35 +00:00
|
|
|
self.add(tobj, title, _("Spouses"))
|
2005-03-30 01:45:14 +00:00
|
|
|
slist = person.get_family_handle_list()
|
|
|
|
if len(slist) > 0:
|
|
|
|
for fid in slist:
|
2007-10-07 03:19:35 +00:00
|
|
|
(fn, mn, pid) = self.get_parent_info(fid)
|
2005-03-30 01:45:14 +00:00
|
|
|
family = self.db.get_family_from_handle(fid)
|
2007-10-07 03:19:35 +00:00
|
|
|
self.add(tobj, normal, "%s:\t%s" % (_('Family ID'), pid))
|
|
|
|
spouse_id = ReportUtils.find_spouse(person, family)
|
2005-03-30 01:45:14 +00:00
|
|
|
if spouse_id:
|
|
|
|
spouse = self.db.get_person_from_handle(spouse_id)
|
2009-04-18 03:10:50 +00:00
|
|
|
self.add(tobj, indent, "%s:\t%s" % (_('Spouse'),
|
|
|
|
name_of(spouse)))
|
2006-04-23 04:29:14 +00:00
|
|
|
relstr = str(family.get_relationship())
|
2007-10-07 03:19:35 +00:00
|
|
|
self.add(tobj, indent, "%s:\t%s" % (_('Type'), relstr))
|
|
|
|
event = ReportUtils.find_marriage(self.db, family)
|
2005-03-30 01:45:14 +00:00
|
|
|
if event:
|
2007-10-07 03:19:35 +00:00
|
|
|
self.add(tobj, indent, "%s:\t%s" % (
|
2009-04-18 03:10:50 +00:00
|
|
|
_('Marriage'),
|
|
|
|
self.get_event_info(event.get_handle())))
|
2006-04-26 23:38:32 +00:00
|
|
|
for child_ref in family.get_child_ref_list():
|
|
|
|
child = self.db.get_person_from_handle(child_ref.ref)
|
2009-04-18 03:10:50 +00:00
|
|
|
self.add(tobj, indent, "%s:\t%s" % (_('Child'),
|
|
|
|
name_of(child)))
|
2005-03-30 01:45:14 +00:00
|
|
|
else:
|
2007-10-07 03:19:35 +00:00
|
|
|
self.add(tobj, normal, _("No spouses or children found"))
|
2005-03-31 03:30:16 +00:00
|
|
|
|
|
|
|
alist = person.get_address_list()
|
|
|
|
if len(alist) > 0:
|
2007-10-07 03:19:35 +00:00
|
|
|
self.add(tobj, title, _("Addresses"))
|
2005-03-31 03:30:16 +00:00
|
|
|
for addr in alist:
|
2007-10-07 03:19:35 +00:00
|
|
|
location = ", ".join([addr.get_street(), addr.get_city(),
|
2008-09-09 07:59:04 +00:00
|
|
|
addr.get_state(), addr.get_country(),
|
|
|
|
addr.get_postal_code(), addr.get_phone()])
|
2007-10-07 03:19:35 +00:00
|
|
|
self.add(tobj, normal, location.strip())
|
2005-03-30 01:45:14 +00:00
|
|
|
|
2007-10-07 03:19:35 +00:00
|
|
|
def get_parent_info(self, fid):
|
2005-03-30 01:45:14 +00:00
|
|
|
family = self.db.get_family_from_handle(fid)
|
|
|
|
father_id = family.get_father_handle()
|
|
|
|
mother_id = family.get_mother_handle()
|
|
|
|
if father_id:
|
|
|
|
father = self.db.get_person_from_handle(father_id)
|
|
|
|
fname = name_of(father)
|
|
|
|
else:
|
|
|
|
fname = u""
|
|
|
|
if mother_id:
|
|
|
|
mother = self.db.get_person_from_handle(mother_id)
|
|
|
|
mname = name_of(mother)
|
|
|
|
else:
|
|
|
|
mname = u""
|
2007-10-07 03:19:35 +00:00
|
|
|
return (fname, mname, family.get_gramps_id())
|
2005-03-30 01:45:14 +00:00
|
|
|
|
2007-10-07 03:19:35 +00:00
|
|
|
def get_event_info(self, handle):
|
2005-03-30 01:45:14 +00:00
|
|
|
date = ""
|
|
|
|
place = ""
|
|
|
|
if handle:
|
|
|
|
event = self.db.get_event_from_handle(handle)
|
2005-08-06 02:57:37 +00:00
|
|
|
date = DateHandler.get_date(event)
|
2005-03-30 01:45:14 +00:00
|
|
|
place = self.place_name(event)
|
|
|
|
if date:
|
2009-04-18 03:10:50 +00:00
|
|
|
return "%s, %s" % (date, place) if place else date
|
2005-03-30 01:45:14 +00:00
|
|
|
else:
|
2009-04-18 03:10:50 +00:00
|
|
|
return place if place else ""
|
2005-03-30 01:45:14 +00:00
|
|
|
else:
|
|
|
|
return ""
|
|
|
|
|
2007-10-07 03:19:35 +00:00
|
|
|
def place_name(self, event):
|
2005-03-30 01:45:14 +00:00
|
|
|
place_id = event.get_place_handle()
|
|
|
|
if place_id:
|
|
|
|
place = self.db.get_place_from_handle(place_id)
|
|
|
|
return place.get_title()
|
|
|
|
else:
|
|
|
|
return ""
|
|
|
|
|
|
|
|
|
2005-08-18 05:58:28 +00:00
|
|
|
def check_for_spouse(p1, p2):
|
|
|
|
|
2007-10-07 03:19:35 +00:00
|
|
|
f1 = set(p1.get_family_handle_list())
|
|
|
|
f2 = set(p2.get_family_handle_list())
|
2005-08-18 05:58:28 +00:00
|
|
|
|
|
|
|
return len(f1.intersection(f2)) != 0
|
|
|
|
|
|
|
|
def check_for_child(p1, p2):
|
|
|
|
|
2007-10-07 03:19:35 +00:00
|
|
|
fs1 = set(p1.get_family_handle_list())
|
|
|
|
fp1 = set(p1.get_parent_family_handle_list())
|
2005-08-18 05:58:28 +00:00
|
|
|
|
2007-10-07 03:19:35 +00:00
|
|
|
fs2 = set(p2.get_family_handle_list())
|
|
|
|
fp2 = set(p2.get_parent_family_handle_list())
|
2005-08-18 05:58:28 +00:00
|
|
|
|
|
|
|
return len(fs1.intersection(fp2)) != 0 or len(fs2.intersection(fp1))
|
|
|
|
|
2005-03-30 01:45:14 +00:00
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Merge People UI
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2006-05-25 04:08:05 +00:00
|
|
|
class MergePeopleUI(ManagedWindow.ManagedWindow):
|
2005-03-30 01:45:14 +00:00
|
|
|
|
2006-05-25 04:08:05 +00:00
|
|
|
def __init__(self, dbstate, uistate, person1, person2, update=None):
|
|
|
|
|
2006-11-26 22:34:02 +00:00
|
|
|
if check_for_spouse(person1, person2):
|
2008-02-18 10:09:50 +00:00
|
|
|
ErrorDialog(
|
2007-10-07 03:19:35 +00:00
|
|
|
_("Cannot merge people"),
|
2006-11-26 22:34:02 +00:00
|
|
|
_("Spouses cannot be merged. To merge these people, "
|
|
|
|
"you must first break the relationship between them."))
|
|
|
|
return
|
|
|
|
|
|
|
|
if check_for_child(person1, person2):
|
2008-02-18 10:09:50 +00:00
|
|
|
ErrorDialog(
|
2007-10-07 03:19:35 +00:00
|
|
|
_("Cannot merge people"),
|
2006-11-26 22:34:02 +00:00
|
|
|
_("A parent and child cannot be merged. To merge these "
|
|
|
|
"people, you must first break the relationship between "
|
|
|
|
"them."))
|
|
|
|
return
|
|
|
|
|
2007-10-07 03:19:35 +00:00
|
|
|
ManagedWindow.ManagedWindow.__init__(self, uistate, [], self.__class__)
|
2006-05-25 04:08:05 +00:00
|
|
|
|
2009-05-14 20:15:59 +00:00
|
|
|
|
|
|
|
glade_xml = Glade(_GLADE_FILE, toplevel='mergeperson')
|
|
|
|
window = glade_xml.toplevel
|
2006-05-25 04:08:05 +00:00
|
|
|
|
2009-04-18 03:10:50 +00:00
|
|
|
self.set_window(window, glade_xml.get_object('people_title'), _("Merge People"))
|
2006-05-25 04:08:05 +00:00
|
|
|
|
2009-04-18 03:10:50 +00:00
|
|
|
p1 = glade_xml.get_object('person1')
|
|
|
|
p2 = glade_xml.get_object('person2')
|
2005-03-30 01:45:14 +00:00
|
|
|
n1 = name_of(person1)
|
|
|
|
n2 = name_of(person2)
|
|
|
|
|
|
|
|
p1.set_label(n1)
|
|
|
|
p2.set_label(n2)
|
2006-05-25 04:08:05 +00:00
|
|
|
|
2009-04-18 03:10:50 +00:00
|
|
|
glade_xml.get_object('people_help').connect('clicked', self.help)
|
2005-03-30 01:45:14 +00:00
|
|
|
|
2005-05-11 14:04:47 +00:00
|
|
|
ret = gtk.RESPONSE_HELP
|
|
|
|
while ret == gtk.RESPONSE_HELP:
|
2006-08-23 16:11:47 +00:00
|
|
|
ret = self.window.run()
|
2005-03-30 01:45:14 +00:00
|
|
|
|
|
|
|
if ret == gtk.RESPONSE_OK:
|
2005-08-18 05:58:28 +00:00
|
|
|
|
2007-10-07 03:19:35 +00:00
|
|
|
if check_for_spouse(person1, person2):
|
2008-02-18 10:09:50 +00:00
|
|
|
ErrorDialog(
|
2007-10-07 03:19:35 +00:00
|
|
|
_("Cannot merge people"),
|
2005-08-18 05:58:28 +00:00
|
|
|
_("Spouses cannot be merged. To merge these people, "
|
|
|
|
"you must first break the relationship between them."))
|
2007-10-07 03:19:35 +00:00
|
|
|
elif check_for_child(person1, person2):
|
2008-02-18 10:09:50 +00:00
|
|
|
ErrorDialog(
|
2007-10-07 03:19:35 +00:00
|
|
|
_("Cannot merge people"),
|
2005-08-18 05:58:28 +00:00
|
|
|
_("A parent and child cannot be merged. To merge these "
|
|
|
|
"people, you must first break the relationship between "
|
|
|
|
"them."))
|
2005-03-30 01:45:14 +00:00
|
|
|
else:
|
2005-08-18 05:58:28 +00:00
|
|
|
if p1.get_active():
|
2007-10-07 03:19:35 +00:00
|
|
|
merge = MergePeople(dbstate.db, person1, person2)
|
2005-08-18 05:58:28 +00:00
|
|
|
else:
|
2007-10-07 03:19:35 +00:00
|
|
|
merge = MergePeople(dbstate.db, person2, person1)
|
2005-08-18 05:58:28 +00:00
|
|
|
merge.merge()
|
2006-05-25 04:08:05 +00:00
|
|
|
if update:
|
|
|
|
update()
|
2006-08-23 16:11:47 +00:00
|
|
|
self.close()
|
2006-05-25 04:08:05 +00:00
|
|
|
|
2007-10-07 03:19:35 +00:00
|
|
|
def build_menu_names(self, obj):
|
|
|
|
return (_('Merge People'), None)
|
2005-03-30 01:45:14 +00:00
|
|
|
|
2007-10-07 03:19:35 +00:00
|
|
|
def help(self, obj):
|
2005-05-11 14:04:47 +00:00
|
|
|
"""Display the relevant portion of GRAMPS manual"""
|
2008-04-05 14:17:15 +00:00
|
|
|
GrampsDisplay.help(webpage=WIKI_HELP_PAGE, section = WIKI_HELP_SEC)
|
2005-05-11 14:04:47 +00:00
|
|
|
|
|
|
|
|
2005-03-30 01:45:14 +00:00
|
|
|
def name_of(p):
|
|
|
|
if not p:
|
|
|
|
return ""
|
2007-10-07 03:19:35 +00:00
|
|
|
return "%s [%s]" % (name_displayer.display(p), p.get_gramps_id())
|
2005-03-30 01:45:14 +00:00
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Merge People
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2009-05-21 17:19:50 +00:00
|
|
|
class MergePeople(object):
|
2005-03-30 01:45:14 +00:00
|
|
|
|
2007-10-07 03:19:35 +00:00
|
|
|
def __init__(self, db, person1, person2):
|
2005-03-30 01:45:14 +00:00
|
|
|
self.db = db
|
|
|
|
self.p1 = person1
|
|
|
|
self.p2 = person2
|
2006-11-26 22:34:02 +00:00
|
|
|
|
2007-10-07 03:19:35 +00:00
|
|
|
def copy_note(self, one, two):
|
2007-07-19 04:33:10 +00:00
|
|
|
one.set_note_list(one.get_note_list() + two.get_note_list())
|
2005-03-30 01:45:14 +00:00
|
|
|
|
2007-10-07 03:19:35 +00:00
|
|
|
def copy_sources(self, one, two):
|
2005-03-30 01:45:14 +00:00
|
|
|
slist = one.get_source_references()[:]
|
|
|
|
for xsrc in two.get_source_references():
|
|
|
|
for src in slist:
|
2006-12-22 23:28:05 +00:00
|
|
|
if src.is_equal(xsrc):
|
2005-03-30 01:45:14 +00:00
|
|
|
break
|
|
|
|
else:
|
|
|
|
one.add_source_reference(xsrc)
|
|
|
|
|
2007-10-07 03:19:35 +00:00
|
|
|
def debug_person(self, person, msg=""):
|
2005-05-24 13:08:06 +00:00
|
|
|
if __debug__:
|
2007-10-07 03:19:35 +00:00
|
|
|
print "## %s person handle %s" % (msg, person.get_handle())
|
2005-05-24 13:08:06 +00:00
|
|
|
for h in person.get_family_handle_list():
|
|
|
|
fam = self.db.get_family_from_handle(h)
|
|
|
|
print " - family %s has father: %s, mother: %s" % \
|
2007-10-07 03:19:35 +00:00
|
|
|
(h, fam.get_father_handle(), fam.get_mother_handle())
|
2006-04-26 23:38:32 +00:00
|
|
|
for h in person.get_parent_family_handle_list():
|
2005-05-24 13:08:06 +00:00
|
|
|
print " - parent family %s" % h
|
|
|
|
|
|
|
|
def merge(self):
|
|
|
|
"""
|
|
|
|
Perform the actual merge. A new person is created to store the
|
|
|
|
merged data. First, the person information is merged. This is a
|
|
|
|
very straight forward process. Second, the families associated
|
|
|
|
with the merged people must be modified to handle the family
|
|
|
|
information. This process can be tricky.
|
|
|
|
|
|
|
|
Finally, the merged person is delete from the database and the
|
|
|
|
entire transaction is committed.
|
|
|
|
"""
|
2006-11-26 22:34:02 +00:00
|
|
|
|
2005-05-24 13:08:06 +00:00
|
|
|
self.debug_person(self.p1, "P1")
|
|
|
|
self.debug_person(self.p2, "P2")
|
|
|
|
|
2007-10-08 16:41:39 +00:00
|
|
|
new = gen.lib.Person()
|
2005-05-24 13:08:06 +00:00
|
|
|
trans = self.db.transaction_begin()
|
|
|
|
|
2007-10-07 03:19:35 +00:00
|
|
|
self.merge_person_information(new, trans)
|
2005-12-06 06:38:09 +00:00
|
|
|
self.debug_person(new, "NEW")
|
|
|
|
|
2007-10-07 03:19:35 +00:00
|
|
|
self.merge_family_information(new, trans)
|
2005-12-06 06:38:09 +00:00
|
|
|
self.debug_person(new, "NEW")
|
|
|
|
|
2007-10-07 03:19:35 +00:00
|
|
|
self.db.commit_person(new, trans)
|
2005-05-24 13:08:06 +00:00
|
|
|
self.debug_person(new, "NEW")
|
2007-10-07 03:19:35 +00:00
|
|
|
self.db.remove_person(self.old_handle, trans)
|
|
|
|
self.db.transaction_commit(trans, "Merge Person")
|
2005-05-24 13:08:06 +00:00
|
|
|
|
2007-10-07 03:19:35 +00:00
|
|
|
def merge_person_information(self, new, trans):
|
2005-05-24 13:08:06 +00:00
|
|
|
"""
|
|
|
|
Merging the person's individual information is pretty simple. The
|
|
|
|
person 'new' is a new, empty person. The data is loaded in this
|
|
|
|
new person. The idea is that all information that can possibly be
|
|
|
|
preserved is preserved.
|
|
|
|
"""
|
2005-03-30 01:45:14 +00:00
|
|
|
self.old_handle = self.p2.get_handle()
|
|
|
|
self.new_handle = self.p1.get_handle()
|
2005-05-24 13:08:06 +00:00
|
|
|
|
|
|
|
# Choose the handle from the target person. Since this is internal
|
|
|
|
# only information, no user visible information is lost.
|
2005-03-30 01:45:14 +00:00
|
|
|
new.set_handle(self.new_handle)
|
2005-05-24 13:08:06 +00:00
|
|
|
|
|
|
|
# The gender is chosen from the primary person. This is one case
|
|
|
|
# where data may be lost if you merge the data from two people of
|
|
|
|
# opposite genders.
|
2005-03-30 01:45:14 +00:00
|
|
|
new.set_gender(self.p1.get_gender())
|
2005-05-24 13:08:06 +00:00
|
|
|
|
|
|
|
# copy the GRAMPS Ids
|
2005-03-30 01:45:14 +00:00
|
|
|
self.merge_gramps_ids(new)
|
2005-05-24 13:08:06 +00:00
|
|
|
|
|
|
|
# copy names
|
2005-03-30 01:45:14 +00:00
|
|
|
self.merge_names(new)
|
2005-05-24 13:08:06 +00:00
|
|
|
|
|
|
|
# merge the event lists
|
2005-03-30 01:45:14 +00:00
|
|
|
self.merge_event_lists(new)
|
2005-05-24 13:08:06 +00:00
|
|
|
|
2007-10-08 04:02:34 +00:00
|
|
|
gen.utils.set_birth_death_index(self.db, new)
|
2006-05-25 04:08:05 +00:00
|
|
|
|
2005-03-30 01:45:14 +00:00
|
|
|
# copy attributes
|
|
|
|
new.set_attribute_list(self.p1.get_attribute_list() +
|
|
|
|
self.p2.get_attribute_list())
|
|
|
|
|
|
|
|
# copy addresses
|
2009-04-18 03:10:50 +00:00
|
|
|
new.set_address_list(self.p1.get_address_list() +
|
|
|
|
self.p2.get_address_list())
|
2005-03-30 01:45:14 +00:00
|
|
|
|
|
|
|
# copy urls
|
2009-04-18 03:10:50 +00:00
|
|
|
new.set_url_list(self.p1.get_url_list() +
|
|
|
|
self.p2.get_url_list())
|
2005-03-30 01:45:14 +00:00
|
|
|
|
2007-02-10 23:40:48 +00:00
|
|
|
# merge LDS
|
2009-04-18 03:10:50 +00:00
|
|
|
new.set_lds_ord_list(self.p1.get_lds_ord_list() +
|
|
|
|
self.p2.get_lds_ord_list())
|
2006-12-22 18:56:38 +00:00
|
|
|
|
2005-03-30 01:45:14 +00:00
|
|
|
# privacy
|
|
|
|
new.set_privacy(self.p1.get_privacy() or self.p2.get_privacy())
|
|
|
|
|
|
|
|
# sources
|
|
|
|
new.set_source_reference_list(self.p1.get_source_references() +
|
|
|
|
self.p2.get_source_references())
|
|
|
|
|
|
|
|
# media
|
|
|
|
for photo in self.p1.get_media_list():
|
|
|
|
new.add_media_reference(photo)
|
|
|
|
for photo in self.p2.get_media_list():
|
|
|
|
new.add_media_reference(photo)
|
|
|
|
|
|
|
|
# note
|
2009-04-18 03:10:50 +00:00
|
|
|
new.set_note_list(self.p1.get_note_list() +
|
|
|
|
self.p2.get_note_list())
|
2005-03-30 01:45:14 +00:00
|
|
|
|
2007-10-07 03:19:35 +00:00
|
|
|
def merge_gramps_ids(self, new):
|
2005-05-24 13:08:06 +00:00
|
|
|
"""
|
|
|
|
Merges the GRAMPS IDs. The new GRAMPS ID is taken from
|
|
|
|
destination person. The GRAMPS ID of the other person is added
|
|
|
|
to the merged person as an attribute.
|
|
|
|
"""
|
|
|
|
# copy of GRAMPS ID as an attribute
|
2007-10-08 16:41:39 +00:00
|
|
|
attr = gen.lib.Attribute()
|
2005-05-24 13:08:06 +00:00
|
|
|
attr.set_type('Merged GRAMPS ID')
|
|
|
|
attr.set_value(self.p2.get_gramps_id())
|
|
|
|
new.add_attribute(attr)
|
2005-03-30 01:45:14 +00:00
|
|
|
|
2005-05-24 13:08:06 +00:00
|
|
|
# store GRAMPS ID of the destination person
|
|
|
|
new.set_gramps_id(self.p1.get_gramps_id())
|
2005-03-30 01:45:14 +00:00
|
|
|
|
2005-05-24 13:08:06 +00:00
|
|
|
def merge_names(self, new):
|
|
|
|
"""
|
|
|
|
Merges the names of the two people into the destination. The
|
|
|
|
primary name of the destination person is kept as the primary
|
|
|
|
name.
|
2005-03-30 01:45:14 +00:00
|
|
|
|
2005-05-24 13:08:06 +00:00
|
|
|
The other person's name is stored as an alternate name if it is
|
|
|
|
not entirely identical to the destination person's primary name.
|
2005-03-30 01:45:14 +00:00
|
|
|
|
2005-05-24 13:08:06 +00:00
|
|
|
Remaining alternate names are then added to the merged
|
2006-12-31 05:17:35 +00:00
|
|
|
person's alternate names, removing exact duplicates.
|
2005-05-24 13:08:06 +00:00
|
|
|
"""
|
|
|
|
p1_name = self.p1.get_primary_name()
|
|
|
|
p2_name = self.p2.get_primary_name()
|
|
|
|
|
|
|
|
new.set_primary_name(self.p1.get_primary_name())
|
|
|
|
if not p2_name.is_equal(p1_name):
|
|
|
|
new.add_alternate_name(p2_name)
|
|
|
|
|
2009-04-18 03:10:50 +00:00
|
|
|
for name in (self.p1.get_alternate_names() +
|
|
|
|
self.p2.get_alternate_names()):
|
2006-12-31 05:17:35 +00:00
|
|
|
if name.is_equal(p1_name):
|
|
|
|
break
|
|
|
|
for item in new.get_alternate_names():
|
|
|
|
if item.is_equal(name):
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
new.add_alternate_name(name)
|
2005-05-24 13:08:06 +00:00
|
|
|
|
2007-10-07 03:19:35 +00:00
|
|
|
def merge_birth(self, new, trans):
|
2005-05-24 13:08:06 +00:00
|
|
|
"""
|
|
|
|
Merges the birth events of the two people. If the primary
|
|
|
|
person does not have a birth event, then the birth event from
|
|
|
|
the secodnary person is selected. If the primary person has
|
|
|
|
a birth date, then the merged person gets the primary person's
|
|
|
|
birth event, and the secondary person's birth event is added
|
|
|
|
as a 'Alternate Birth' event.
|
|
|
|
"""
|
2006-03-31 04:19:06 +00:00
|
|
|
ref1 = self.p1.get_birth_ref()
|
|
|
|
ref2 = self.p2.get_birth_ref()
|
2005-05-24 13:08:06 +00:00
|
|
|
|
2006-05-25 04:08:05 +00:00
|
|
|
if not ref1.is_equal(ref2):
|
|
|
|
new.add_event_ref(ref2)
|
2005-05-24 13:08:06 +00:00
|
|
|
|
|
|
|
def merge_death(self, new, trans):
|
|
|
|
"""
|
|
|
|
Merges the death events of the two people. If the primary
|
|
|
|
person does not have a death event, then the death event from
|
|
|
|
the secodnary person is selected. If the primary person has
|
|
|
|
a death date, then the merged person gets the primary person's
|
|
|
|
death event, and the secondary person's death event is added
|
|
|
|
as a 'Alternate Death' event.
|
|
|
|
"""
|
2006-04-26 23:38:32 +00:00
|
|
|
ref1 = self.p1.get_death_ref()
|
|
|
|
ref2 = self.p2.get_death_ref()
|
2005-05-24 13:08:06 +00:00
|
|
|
|
2006-05-25 04:08:05 +00:00
|
|
|
if not ref1.is_equal(ref2):
|
|
|
|
new.add_event_ref(ref2)
|
2005-05-24 13:08:06 +00:00
|
|
|
|
|
|
|
def merge_event_lists(self, new):
|
|
|
|
"""
|
|
|
|
Merges the events from the two people into the destination
|
|
|
|
person. Duplicates are not transferred.
|
|
|
|
"""
|
2006-04-26 23:38:32 +00:00
|
|
|
data_list = new.get_event_ref_list()
|
|
|
|
data_handle_list = [ref.ref for ref in data_list]
|
|
|
|
|
|
|
|
add_ref_list1 = [ref for ref in self.p1.get_event_ref_list()
|
|
|
|
if ref.ref not in data_handle_list]
|
|
|
|
|
|
|
|
add_ref_list2 = [ref for ref in self.p2.get_event_ref_list()
|
|
|
|
if ref.ref not in data_handle_list]
|
|
|
|
|
|
|
|
new.set_event_ref_list(data_list+add_ref_list1+add_ref_list2)
|
2005-05-24 13:08:06 +00:00
|
|
|
|
|
|
|
def merge_family_information(self, new, trans):
|
|
|
|
"""
|
|
|
|
Merge the parent families and the relationship families of the
|
|
|
|
selected people.
|
|
|
|
"""
|
|
|
|
self.merge_parents(new, trans)
|
|
|
|
self.merge_relationships(new, trans)
|
2005-12-06 06:38:09 +00:00
|
|
|
self.debug_person(new, "NEW")
|
2005-05-24 13:08:06 +00:00
|
|
|
|
|
|
|
def merge_parents(self, new, trans):
|
|
|
|
"""
|
|
|
|
Merging the parent list is not too difficult. We grab the
|
|
|
|
parent list of the destination person. We then loop through
|
|
|
|
the parent list of the secondary person, adding to the parent
|
|
|
|
list any parents that are not already there. This eliminates
|
|
|
|
any duplicates.
|
|
|
|
|
2007-10-07 03:19:35 +00:00
|
|
|
Once this has been completed, we loop through each family,
|
2005-05-24 13:08:06 +00:00
|
|
|
converting any child handles referring to the secondary person
|
|
|
|
to the destination person.
|
|
|
|
"""
|
|
|
|
parent_list = self.p1.get_parent_family_handle_list()
|
|
|
|
|
|
|
|
# copy handles of families that are not common between the
|
|
|
|
# two lists
|
|
|
|
for fid in self.p2.get_parent_family_handle_list():
|
|
|
|
if fid not in parent_list:
|
|
|
|
parent_list.append(fid)
|
2005-12-06 06:38:09 +00:00
|
|
|
if __debug__:
|
|
|
|
print "Adding family to parent list", fid
|
2005-05-24 13:08:06 +00:00
|
|
|
|
|
|
|
# loop through the combined list, converting the child handles
|
|
|
|
# of the families, and adding the families to the merged
|
|
|
|
# person
|
|
|
|
|
2006-04-23 04:29:14 +00:00
|
|
|
for family_handle in parent_list:
|
2007-10-07 03:19:35 +00:00
|
|
|
self.convert_child_ids(family_handle, self.new_handle,
|
2005-05-24 13:08:06 +00:00
|
|
|
self.old_handle, trans)
|
2006-04-26 23:38:32 +00:00
|
|
|
new.add_parent_family_handle(family_handle)
|
2005-05-24 13:08:06 +00:00
|
|
|
|
|
|
|
def convert_child_ids(self, fhandle, new_handle, old_handle, trans):
|
|
|
|
"""
|
2006-04-26 23:38:32 +00:00
|
|
|
Search the family associated with fhandle, and replace
|
|
|
|
old handle with the new handle in all child references.
|
2005-05-24 13:08:06 +00:00
|
|
|
"""
|
|
|
|
family = self.db.get_family_from_handle(fhandle)
|
2006-04-26 23:38:32 +00:00
|
|
|
orig_ref_list = family.get_child_ref_list()
|
|
|
|
new_ref_list = []
|
2005-05-24 13:08:06 +00:00
|
|
|
|
|
|
|
# loop through original child list. If a handle matches the
|
|
|
|
# old handle, replace it with the new handle if the new handle
|
|
|
|
# is not already in the list
|
2006-04-23 04:29:14 +00:00
|
|
|
|
2006-04-26 23:38:32 +00:00
|
|
|
for child_ref in orig_ref_list:
|
2006-04-23 04:29:14 +00:00
|
|
|
if child_ref.ref == old_handle:
|
2006-04-26 23:38:32 +00:00
|
|
|
if new_handle not in [ref.ref for ref in new_ref_list]:
|
2007-10-08 16:41:39 +00:00
|
|
|
new_ref = gen.lib.ChildRef()
|
2006-04-26 23:38:32 +00:00
|
|
|
new_ref.ref = new_handle
|
|
|
|
new_ref_list.append(new_ref)
|
|
|
|
elif child_ref.ref not in [ref.ref for ref in new_ref_list]:
|
|
|
|
new_ref_list.append(child_ref)
|
2005-05-24 13:08:06 +00:00
|
|
|
|
|
|
|
# compare the new list with the original list. If this list
|
|
|
|
# is different, we need to save the changes to the database.
|
2006-04-26 23:38:32 +00:00
|
|
|
if [ref.ref for ref in new_ref_list] \
|
|
|
|
!= [ref.ref for ref in orig_ref_list]:
|
|
|
|
family.set_child_ref_list(new_ref_list)
|
2007-10-07 03:19:35 +00:00
|
|
|
self.db.commit_family(family, trans)
|
2005-03-30 01:45:14 +00:00
|
|
|
|
2007-10-07 03:19:35 +00:00
|
|
|
def merge_relationships(self, new, trans):
|
2005-05-24 13:08:06 +00:00
|
|
|
"""
|
|
|
|
Merges the relationships associated with the merged people.
|
|
|
|
"""
|
|
|
|
|
2007-02-10 23:40:48 +00:00
|
|
|
if __debug__:
|
|
|
|
print "********Merging Relationships********"
|
2006-12-22 23:28:05 +00:00
|
|
|
|
2005-05-24 13:08:06 +00:00
|
|
|
family_num = 0
|
|
|
|
family_list = self.p1.get_family_handle_list()
|
2005-12-06 06:38:09 +00:00
|
|
|
new.set_family_handle_list(family_list)
|
2005-05-24 13:08:06 +00:00
|
|
|
|
|
|
|
for src_handle in self.p2.get_family_handle_list():
|
2005-03-30 01:45:14 +00:00
|
|
|
|
2005-05-24 13:08:06 +00:00
|
|
|
src_family = self.db.get_family_from_handle(src_handle)
|
|
|
|
family_num += 1
|
2005-03-30 01:45:14 +00:00
|
|
|
|
2005-05-24 13:08:06 +00:00
|
|
|
if not src_family or src_family in family_list:
|
|
|
|
continue
|
|
|
|
|
|
|
|
tgt_family = self.find_modified_family(src_family)
|
|
|
|
|
|
|
|
# existing family is found
|
|
|
|
if tgt_family:
|
|
|
|
# The target family is already a family in the person's
|
|
|
|
# family list.
|
2009-04-18 03:10:50 +00:00
|
|
|
if tgt_family.get_handle() in \
|
|
|
|
self.p1.get_family_handle_list():
|
2007-02-10 23:40:48 +00:00
|
|
|
if __debug__:
|
|
|
|
print "Merging existing family"
|
2009-04-18 03:10:50 +00:00
|
|
|
self.merge_existing_family(new, src_family,
|
|
|
|
tgt_family, trans)
|
2005-05-24 13:08:06 +00:00
|
|
|
continue
|
|
|
|
|
|
|
|
# This is the case the family is not already in the person's
|
|
|
|
# family list.
|
|
|
|
else:
|
2007-02-10 23:40:48 +00:00
|
|
|
if __debug__:
|
|
|
|
print "Merging family pair"
|
2007-10-07 03:19:35 +00:00
|
|
|
self.merge_family_pair(tgt_family, src_family, trans)
|
2005-03-30 01:45:14 +00:00
|
|
|
|
2005-05-24 13:08:06 +00:00
|
|
|
# change parents of the family to point to the new
|
|
|
|
# family
|
2009-04-18 03:10:50 +00:00
|
|
|
self.adjust_family_pointers(tgt_family, src_family,
|
|
|
|
trans)
|
2005-05-24 13:08:06 +00:00
|
|
|
|
|
|
|
new.remove_family_handle(src_handle)
|
2007-10-07 03:19:35 +00:00
|
|
|
self.db.remove_family(src_handle, trans)
|
2005-05-24 13:08:06 +00:00
|
|
|
if __debug__:
|
|
|
|
print "Deleted src_family %s" % src_handle
|
|
|
|
else:
|
|
|
|
for fid in self.p1.get_family_handle_list():
|
|
|
|
if fid not in new.get_family_handle_list():
|
|
|
|
new.add_family_handle(fid)
|
2005-12-06 06:38:09 +00:00
|
|
|
if __debug__:
|
|
|
|
print "Adding family %s" % fid
|
2005-05-24 13:08:06 +00:00
|
|
|
|
|
|
|
if src_handle in new.get_family_handle_list():
|
|
|
|
continue
|
|
|
|
src_family = self.db.get_family_from_handle(src_handle)
|
|
|
|
new.add_family_handle(src_handle)
|
|
|
|
if src_family.get_father_handle() == self.old_handle:
|
|
|
|
src_family.set_father_handle(self.new_handle)
|
|
|
|
if __debug__:
|
|
|
|
print "Family %s now has father %s" % (
|
|
|
|
src_handle, self.new_handle)
|
|
|
|
if src_family.get_mother_handle() == self.old_handle:
|
|
|
|
src_family.set_mother_handle(self.new_handle)
|
|
|
|
if __debug__:
|
|
|
|
print "Family %s now has mother %s" % (
|
|
|
|
src_handle, self.new_handle)
|
2007-10-07 03:19:35 +00:00
|
|
|
self.db.commit_family(src_family, trans)
|
2005-05-24 13:08:06 +00:00
|
|
|
|
|
|
|
# a little debugging here
|
|
|
|
|
2006-04-26 23:38:32 +00:00
|
|
|
## cursor = self.db.get_family_cursor()
|
|
|
|
## data = cursor.first()
|
|
|
|
## while data:
|
2007-10-08 16:41:39 +00:00
|
|
|
## fam = gen.lib.Family()
|
2006-04-26 23:38:32 +00:00
|
|
|
## fam.unserialize(data[1])
|
|
|
|
## if self.p2 in [ref.ref for ref in fam.get_child_ref_list()]:
|
|
|
|
## fam.remove_child_ref(self.p2)
|
|
|
|
## fam.add_child_ref(self.p1)
|
|
|
|
## if self.p2 == fam.get_father_handle():
|
|
|
|
## fam.set_father_handle(self.p1)
|
|
|
|
## if self.p2 == fam.get_mother_handle():
|
|
|
|
## fam.set_mother_handle(self.p1)
|
2008-06-16 15:01:46 +00:00
|
|
|
## if fam.get_father_handle() is None and fam.get_mother_handle() is None:
|
2007-10-07 03:19:35 +00:00
|
|
|
## self.delete_empty_family(fam, trans)
|
2006-04-26 23:38:32 +00:00
|
|
|
## data = cursor.next()
|
2005-05-24 13:08:06 +00:00
|
|
|
|
2007-10-07 03:19:35 +00:00
|
|
|
def find_modified_family(self, family):
|
2005-05-24 13:08:06 +00:00
|
|
|
"""
|
|
|
|
Look for a existing family that matches the merged person. This means
|
|
|
|
looking at the current family, and replacing the secondary person's
|
|
|
|
handle with the merged person's handle. Search the family table for
|
|
|
|
a family that matches this new mother/father pair.
|
|
|
|
|
|
|
|
If no family is found, return None
|
|
|
|
"""
|
|
|
|
|
|
|
|
family_handle = family.get_handle()
|
|
|
|
|
|
|
|
if __debug__:
|
|
|
|
print "SourceFamily: %s" % family_handle
|
|
|
|
|
|
|
|
# Determine the mother and father handles for the search.
|
|
|
|
# This is determined by replacing the secodnary person's
|
|
|
|
# handle with the primary person's handle in the mother/father
|
|
|
|
# pair.
|
2005-03-30 01:45:14 +00:00
|
|
|
|
2005-05-24 13:08:06 +00:00
|
|
|
mhandle = family.get_mother_handle()
|
|
|
|
if mhandle == self.old_handle:
|
|
|
|
mhandle = self.new_handle
|
|
|
|
|
|
|
|
fhandle = family.get_father_handle()
|
|
|
|
if fhandle == self.old_handle:
|
|
|
|
fhandle = self.new_handle
|
|
|
|
|
|
|
|
# loop through the families using a cursor. Check the handles
|
|
|
|
# for a mother/father match.
|
|
|
|
|
|
|
|
cursor = self.db.get_family_cursor()
|
|
|
|
node = cursor.next()
|
|
|
|
myfamily = None
|
|
|
|
while node:
|
|
|
|
# data[2] == father_handle field, data[2] == mother_handle field
|
2007-10-07 03:19:35 +00:00
|
|
|
(thandle, data) = node
|
2009-04-18 03:10:50 +00:00
|
|
|
if (data[2] == fhandle and
|
|
|
|
data[3] == mhandle and
|
|
|
|
thandle != family_handle):
|
2007-10-08 16:41:39 +00:00
|
|
|
myfamily = gen.lib.Family()
|
2005-05-24 13:08:06 +00:00
|
|
|
myfamily.unserialize(data)
|
|
|
|
break
|
|
|
|
node = cursor.next()
|
|
|
|
|
|
|
|
if __debug__:
|
|
|
|
if myfamily:
|
|
|
|
print "TargetFamily: %s" % myfamily.get_handle()
|
|
|
|
else:
|
|
|
|
print "TargetFamily: None"
|
|
|
|
|
|
|
|
cursor.close()
|
|
|
|
return myfamily
|
|
|
|
|
|
|
|
def merge_existing_family(self, new, src_family, tgt_family, trans):
|
|
|
|
|
|
|
|
src_family_handle = src_family.get_handle()
|
|
|
|
|
|
|
|
father_id = tgt_family.get_father_handle()
|
|
|
|
father = self.db.get_person_from_handle(father_id)
|
|
|
|
|
|
|
|
mother_id = tgt_family.get_mother_handle()
|
|
|
|
mother = self.db.get_person_from_handle(mother_id)
|
|
|
|
|
|
|
|
if father and src_family_handle in father.get_family_handle_list():
|
|
|
|
father.remove_family_handle(src_family_handle)
|
|
|
|
if __debug__:
|
2009-04-18 03:10:50 +00:00
|
|
|
print "Removed family %s from father %s" % \
|
|
|
|
(src_family_handle, father_id)
|
2007-10-07 03:19:35 +00:00
|
|
|
self.db.commit_person(father, trans)
|
2005-05-24 13:08:06 +00:00
|
|
|
if mother and src_family_handle in mother.get_family_handle_list():
|
|
|
|
mother.remove_family_handle(src_family_handle)
|
|
|
|
if __debug__:
|
2009-04-18 03:10:50 +00:00
|
|
|
print "Removed family %s from mother %s" % \
|
|
|
|
(src_family_handle, mother_id)
|
2007-10-07 03:19:35 +00:00
|
|
|
self.db.commit_person(mother, trans)
|
2005-05-24 13:08:06 +00:00
|
|
|
|
2007-10-07 03:19:35 +00:00
|
|
|
self.merge_family_pair(tgt_family, src_family, trans)
|
2005-05-24 13:08:06 +00:00
|
|
|
|
2006-07-25 20:23:28 +00:00
|
|
|
for child_ref in src_family.get_child_ref_list():
|
|
|
|
child_handle = child_ref.ref
|
2005-05-24 13:08:06 +00:00
|
|
|
if child_handle != self.new_handle:
|
|
|
|
child = self.db.get_person_from_handle(child_handle)
|
|
|
|
if child.remove_parent_family_handle(src_family_handle):
|
2005-12-06 06:38:09 +00:00
|
|
|
if __debug__:
|
2006-07-25 20:23:28 +00:00
|
|
|
print "Remove parent family %s from %s" \
|
2007-10-07 03:19:35 +00:00
|
|
|
% (src_family_handle, child_handle)
|
2007-02-10 23:40:48 +00:00
|
|
|
child.add_parent_family_handle(tgt_family.handle)
|
2007-10-07 03:19:35 +00:00
|
|
|
self.db.commit_person(child, trans)
|
2005-05-24 13:08:06 +00:00
|
|
|
|
|
|
|
# delete the old source family
|
2007-10-07 03:19:35 +00:00
|
|
|
self.db.remove_family(src_family_handle, trans)
|
2005-05-24 13:08:06 +00:00
|
|
|
if __debug__:
|
|
|
|
print "Deleted src_family %s" % src_family_handle
|
2007-10-07 03:19:35 +00:00
|
|
|
self.db.commit_family(tgt_family, trans)
|
2005-12-06 06:38:09 +00:00
|
|
|
if tgt_family.get_handle() not in new.get_family_handle_list():
|
|
|
|
new.add_family_handle(tgt_family.get_handle())
|
2005-03-30 01:45:14 +00:00
|
|
|
|
2007-10-07 03:19:35 +00:00
|
|
|
def merge_family_pair(self, tgt_family, src_family, trans):
|
2005-03-30 01:45:14 +00:00
|
|
|
|
2009-04-18 03:10:50 +00:00
|
|
|
tgt_family_child_handles = \
|
|
|
|
[ref.ref for ref in tgt_family.get_child_ref_list()]
|
2005-03-30 01:45:14 +00:00
|
|
|
# copy children from source to target
|
2006-07-25 20:23:28 +00:00
|
|
|
for child_ref in src_family.get_child_ref_list():
|
|
|
|
child_handle = child_ref.ref
|
|
|
|
if child_handle not in tgt_family_child_handles:
|
2005-03-30 01:45:14 +00:00
|
|
|
child = self.db.get_person_from_handle(child_handle)
|
|
|
|
parents = child.get_parent_family_handle_list()
|
2006-07-25 20:23:28 +00:00
|
|
|
tgt_family.add_child_ref(child_ref)
|
2005-05-24 13:08:06 +00:00
|
|
|
if child.get_main_parents_family_handle() == src_family.get_handle():
|
|
|
|
child.set_main_parent_family_handle(tgt_family.get_handle())
|
2005-03-30 01:45:14 +00:00
|
|
|
i = 0
|
|
|
|
for fam in parents[:]:
|
|
|
|
if fam[0] == src_family.get_handle():
|
2009-04-18 03:10:50 +00:00
|
|
|
parents[i] = (tgt_family.get_handle(),
|
|
|
|
fam[1], fam[2])
|
2005-03-30 01:45:14 +00:00
|
|
|
i += 1
|
2007-10-07 03:19:35 +00:00
|
|
|
self.db.commit_person(child, trans)
|
2005-03-30 01:45:14 +00:00
|
|
|
|
|
|
|
# merge family events
|
|
|
|
|
2006-04-26 23:38:32 +00:00
|
|
|
ereflist = tgt_family.get_event_ref_list()
|
|
|
|
eref_handle_list = [ref.ref for ref in ereflist]
|
|
|
|
|
|
|
|
add_ref_list = [ref for ref in src_family.get_event_ref_list()
|
|
|
|
if ref.ref not in eref_handle_list]
|
|
|
|
tgt_family.set_event_ref_list(ereflist+add_ref_list)
|
|
|
|
|
2005-03-30 01:45:14 +00:00
|
|
|
|
|
|
|
# merge family attributes
|
|
|
|
|
|
|
|
for xdata in src_family.get_attribute_list():
|
2005-03-31 03:30:16 +00:00
|
|
|
tgt_family.add_attribute(xdata)
|
2005-03-30 01:45:14 +00:00
|
|
|
|
|
|
|
# merge family notes
|
2009-04-18 03:10:50 +00:00
|
|
|
tgt_family.set_note_list(tgt_family.get_note_list() +
|
|
|
|
src_family.get_note_list())
|
2005-03-30 01:45:14 +00:00
|
|
|
|
|
|
|
# merge family top-level sources
|
|
|
|
|
2007-10-07 03:19:35 +00:00
|
|
|
self.copy_sources(tgt_family, src_family)
|
2005-03-30 01:45:14 +00:00
|
|
|
|
|
|
|
# merge multimedia objects
|
|
|
|
|
|
|
|
for photo in src_family.get_media_list():
|
|
|
|
tgt_family.add_media_reference(photo)
|
|
|
|
|
2005-05-24 13:08:06 +00:00
|
|
|
def adjust_family_pointers(self, tgt_family, src_family, trans):
|
|
|
|
"""
|
|
|
|
Remove the people from one family and merge them into the other.
|
|
|
|
It is not necessary to remove from the src_family, since the
|
|
|
|
src_family is going to be removed.
|
|
|
|
"""
|
|
|
|
src_family_handle = src_family.get_handle()
|
|
|
|
tgt_family_handle = tgt_family.get_handle()
|
2005-03-30 01:45:14 +00:00
|
|
|
|
2005-05-24 13:08:06 +00:00
|
|
|
father_handle = src_family.get_father_handle()
|
|
|
|
if father_handle:
|
|
|
|
father = self.db.get_person_from_handle(father_handle)
|
2005-03-30 01:45:14 +00:00
|
|
|
|
2005-05-24 13:08:06 +00:00
|
|
|
# add to new family
|
|
|
|
father.add_family_handle(tgt_family_handle)
|
|
|
|
if __debug__:
|
|
|
|
print "Added family %s to father %s" % (
|
|
|
|
tgt_family_handle, father_handle)
|
2005-03-30 01:45:14 +00:00
|
|
|
|
2005-05-24 13:08:06 +00:00
|
|
|
# commit the change
|
2007-10-07 03:19:35 +00:00
|
|
|
self.db.commit_person(father, trans)
|
2005-03-30 01:45:14 +00:00
|
|
|
|
2005-05-24 13:08:06 +00:00
|
|
|
mother_handle = src_family.get_mother_handle()
|
|
|
|
if mother_handle:
|
|
|
|
mother = self.db.get_person_from_handle(mother_handle)
|
2005-03-30 01:45:14 +00:00
|
|
|
|
2005-05-24 13:08:06 +00:00
|
|
|
# add to new family
|
|
|
|
mother.add_family_handle(tgt_family_handle)
|
|
|
|
if __debug__:
|
|
|
|
print "Added family %s to mother %s" % (
|
|
|
|
tgt_family_handle, mother_handle)
|
2005-03-30 01:45:14 +00:00
|
|
|
|
2005-05-24 13:08:06 +00:00
|
|
|
# commit the change
|
2007-10-07 03:19:35 +00:00
|
|
|
self.db.commit_person(mother, trans)
|
2005-03-30 01:45:14 +00:00
|
|
|
|
2005-05-24 13:08:06 +00:00
|
|
|
# remove the children from the old family
|
2006-07-25 20:23:28 +00:00
|
|
|
for child_ref in src_family.get_child_ref_list():
|
|
|
|
child_handle = child_ref.ref
|
2005-05-24 13:08:06 +00:00
|
|
|
if child_handle != self.new_handle:
|
|
|
|
child = self.db.get_person_from_handle(child_handle)
|
|
|
|
if child.remove_parent_family_handle(src_family_handle):
|
2007-10-07 03:19:35 +00:00
|
|
|
self.db.commit_person(child, trans)
|
2005-03-30 01:45:14 +00:00
|
|
|
|
|
|
|
|
2007-10-07 03:19:35 +00:00
|
|
|
def remove_marriage(self, family, person, trans):
|
2005-03-30 01:45:14 +00:00
|
|
|
if person:
|
|
|
|
person.remove_family_handle(family.get_handle())
|
2009-04-18 03:10:50 +00:00
|
|
|
if (family.get_father_handle() is
|
|
|
|
family.get_mother_handle() is None):
|
2007-10-07 03:19:35 +00:00
|
|
|
self.delete_empty_family(family, trans)
|
2005-03-30 01:45:14 +00:00
|
|
|
|
2007-10-07 03:19:35 +00:00
|
|
|
def delete_empty_family(self, family, trans):
|
2005-03-30 01:45:14 +00:00
|
|
|
family_handle = family.get_handle()
|
2006-07-25 20:23:28 +00:00
|
|
|
for child_ref in family.get_child_ref_list():
|
|
|
|
child_handle = child_ref.ref
|
2005-03-30 01:45:14 +00:00
|
|
|
child = self.db.get_person_from_handle(child_handle)
|
|
|
|
if child.get_main_parents_family_handle() == family_handle:
|
|
|
|
child.set_main_parent_family_handle(None)
|
|
|
|
else:
|
|
|
|
child.remove_parent_family_handle(family_handle)
|
2007-10-07 03:19:35 +00:00
|
|
|
self.db.commit_person(child, trans)
|
|
|
|
self.db.remove_family(family_handle, trans)
|
2005-05-24 13:08:06 +00:00
|
|
|
if __debug__:
|
|
|
|
print "Deleted empty family %s" % family_handle
|
2005-03-30 01:45:14 +00:00
|
|
|
|
|
|
|
def merge_notes(self, note1, note2):
|
2008-03-13 10:44:22 +00:00
|
|
|
t1 = note1.get()
|
|
|
|
t2 = note2.get()
|
2006-08-12 21:59:32 +00:00
|
|
|
if not t2:
|
2005-03-30 01:45:14 +00:00
|
|
|
return note1
|
2006-08-12 21:59:32 +00:00
|
|
|
elif not t1:
|
2005-03-30 01:45:14 +00:00
|
|
|
return note2
|
2006-08-12 21:59:32 +00:00
|
|
|
elif t1 and t2:
|
|
|
|
note1.append("\n" + t2)
|
2005-03-30 01:45:14 +00:00
|
|
|
note1.set_format(note1.get_format() or note2.get_format())
|
|
|
|
return note1
|
|
|
|
return None
|
|
|
|
|