diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index e33b4ab65..1324a7d56 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,3 +1,7 @@ +2005-07-28 Don Allingham + * src/MergePeople.py: prevent attempts to merge a person and his/her + spouse, prevent merging of child and parent. + 2005-07-28 Alex Roitman * src/plugins/WebPage.py (WebReportOptions.set_new_options): Define help dictionary to document options. diff --git a/gramps2/src/MergePeople.py b/gramps2/src/MergePeople.py index bad53da47..26cc1f46c 100644 --- a/gramps2/src/MergePeople.py +++ b/gramps2/src/MergePeople.py @@ -26,6 +26,7 @@ # #------------------------------------------------------------------------- from gettext import gettext as _ +import sets #------------------------------------------------------------------------- # @@ -46,6 +47,7 @@ import ReportUtils import Utils import NameDisplay import const +import QuestionDialog sex = ( _("female"), _("male"), _("unknown")) @@ -79,13 +81,27 @@ class Compare: help_display('gramps-manual','adv-merge-people') def merge(self,obj): - if self.glade.get_widget('select1').get_active(): - merge = MergePeople(self.db,self.p1,self.p2) + + if check_for_spouse(self.p1,self.p2): + QuestionDialog.ErrorDialog( + _("Cannot merge people"), + _("Spouses cannot be merged. To merge these people, " + "you must first break the relationship between the " + "two people.")) + elif check_for_child(self.p1,self.p2): + QuestionDialog.ErrorDialog( + _("Cannot merge people"), + _("A parent and child cannot be merged. To merge these " + "people, you must first break the relationship between " + "the two people.")) else: - merge = MergePeople(self.db,self.p2,self.p1) - self.top.destroy() - merge.merge() - self.update() + if self.glade.get_widget('select1').get_active(): + merge = MergePeople(self.db,self.p1,self.p2) + else: + merge = MergePeople(self.db,self.p2,self.p1) + self.top.destroy() + merge.merge() + self.update() def add(self, tobj, tag, text): text += "\n" @@ -213,6 +229,23 @@ class Compare: return "" +def check_for_spouse(p1, p2): + + f1 = sets.Set(p1.get_family_handle_list()) + f2 = sets.Set(p2.get_family_handle_list()) + + return len(f1.intersection(f2)) != 0 + +def check_for_child(p1, p2): + + fs1 = sets.Set(p1.get_family_handle_list()) + fp1 = sets.Set(map(lambda x: x[0], p1.get_parent_family_handle_list())) + + fs2 = sets.Set(p2.get_family_handle_list()) + fp2 = sets.Set(map(lambda x: x[0], p2.get_parent_family_handle_list())) + + return len(fs1.intersection(fp2)) != 0 or len(fs2.intersection(fp1)) + #------------------------------------------------------------------------- # # Merge People UI @@ -238,12 +271,26 @@ class MergePeopleUI: ret = top.run() if ret == gtk.RESPONSE_OK: - if p1.get_active(): - merge = MergePeople(db,person1,person2) + + if check_for_spouse(person1,person2): + QuestionDialog.ErrorDialog( + _("Cannot merge people"), + _("Spouses cannot be merged. To merge these people, " + "you must first break the relationship between the " + "two people.")) + elif check_for_child(person1,person2): + QuestionDialog.ErrorDialog( + _("Cannot merge people"), + _("A parent and child cannot be merged. To merge these " + "people, you must first break the relationship between " + "the two people.")) else: - merge = MergePeople(db,person2,person1) - merge.merge() - update() + if p1.get_active(): + merge = MergePeople(db,person1,person2) + else: + merge = MergePeople(db,person2,person1) + merge.merge() + update() top.destroy() def help(self,obj):