From 0802e3a811e167ac631cc53951ab1bcf2f9ac2ca Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Thu, 16 Jun 2005 03:56:13 +0000 Subject: [PATCH] * src/ReadXML.py: build child/family relationships properly on import, add missing event descriptions * src/RelLib.py: type checking for set_role relationship types svn: r4831 --- ChangeLog | 5 ++++ src/ReadXML.py | 63 ++++++++++++++++++++++++++++++++++++++++---------- src/RelLib.py | 15 +++++++----- 3 files changed, 65 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index 41ebb55f3..bc10d0359 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2005-06-15 Don Allingham + * src/ReadXML.py: build child/family relationships properly on + import, add missing event descriptions + * src/RelLib.py: type checking for set_role relationship types + 2005-06-15 Alex Roitman * src/ListBox.py (EventListBox.set_place): Fix place setting. diff --git a/src/ReadXML.py b/src/ReadXML.py index 8996963fe..517e4b108 100644 --- a/src/ReadXML.py +++ b/src/ReadXML.py @@ -43,6 +43,7 @@ import RelLib import const import Utils import DateHandler +import NameDisplay #------------------------------------------------------------------------- # @@ -298,6 +299,16 @@ class GrampsParser: self.gid2sid = {} self.change = change self.dp = DateHandler.parser + + self.child_relmap = { + "None" : RelLib.Person.CHILD_NONE, + "Birth" : RelLib.Person.CHILD_BIRTH, + "Adopted" : RelLib.Person.CHILD_ADOPTED, + "Stepchild" : RelLib.Person.CHILD_STEPCHILD, + "Sponsored" : RelLib.Person.CHILD_SPONSORED, + "Foster" : RelLib.Person.CHILD_FOSTER, + "Unknown" : RelLib.Person.CHILD_UNKNOWN, + } self.ord = None self.objref = None @@ -875,19 +886,17 @@ class GrampsParser: family = self.find_family_by_gramps_id(self.map_fid(attrs["ref"])) if attrs.has_key("mrel"): - try: - mrel = const.child_rel_notrans.index(attrs["mrel"]) - except: - mrel = RelLib.Person.CHILD_NONE + mval = attrs.has_key('mrel') + mrel = (self.child_relmap.get(mval,RelLib.Person.CHILD_CUSTOM), + mval) else: - mrel = RelLib.Person.CHILD_BIRTH + mrel = (RelLib.Person.CHILD_BIRTH,'Birth') if attrs.has_key("frel"): - try: - frel = const.child_rel_notrans.index(attrs["frel"]) - except: - frel = RelLib.Person.CHILD_NONE + fval = attrs.has_key('frel') + frel = (self.child_relmap.get(fval,RelLib.Person.CHILD_CUSTOM), + fval) else: - frel = RelLib.Person.CHILD_BIRTH + frel = (RelLib.Person.CHILD_BIRTH,'Birth') self.person.add_parent_family_handle(family.get_handle(),mrel,frel) def start_parentin(self,attrs): @@ -1244,16 +1253,46 @@ class GrampsParser: def stop_event(self,*tag): if self.family: - self.family.add_event_handle(self.event.get_handle()) + ref = RelLib.EventRef() + ref.set_reference_handle(self.event.get_handle()) + self.family.add_event_ref(ref) + + descr = self.event.get_description() + if not descr: + (code,val) = self.event.get_type() + if code == RelLib.Event.CUSTOM: + event_name = val + else: + event_name = Utils.family_events[code] + text = _("%(event_name)s of %(family)s") % { + 'event_name' : event_name, + 'family' : Utils.family_name(self.family,self.db), + } + self.event.set_description(text) + else: ref = RelLib.EventRef() - ref.ref = self.event.get_handle() + ref.set_reference_handle(self.event.get_handle()) + ref.set_role((RelLib.EventRef.PRIMARY,'')) if self.event.get_type()[0] == RelLib.Event.BIRTH: self.person.set_birth_ref(ref) elif self.event.get_type()[0] == RelLib.Event.DEATH: self.person.set_death_ref(ref) else: self.person.add_event_ref(ref) + + descr = self.event.get_description() + if not descr: + (code,val) = self.event.get_type() + if code == RelLib.Event.CUSTOM: + event_name = val + else: + event_name = Utils.personal_events[code] + text = _("%(event_name)s of %(person)s") % { + 'event_name' : event_name, + 'person' : NameDisplay.displayer.display(self.person), + } + self.event.set_description(text) self.db.commit_event(self.event,self.trans,self.change) self.event = None diff --git a/src/RelLib.py b/src/RelLib.py index 96137c1e3..ad18eb7f6 100644 --- a/src/RelLib.py +++ b/src/RelLib.py @@ -1253,7 +1253,7 @@ class Person(PrimaryObject,PrivateSourceNote,MediaBase,AttributeBase): # remove when transitition done. event_ref = EventRef() event_ref.set_reference_handle(event_handle) - event_ref.set_role( EventRef.PRIMARY) + event_ref.set_role((EventRef.PRIMARY,'')) self.set_birth_ref( event_ref) def set_birth_ref(self,event_ref): @@ -1276,7 +1276,7 @@ class Person(PrimaryObject,PrivateSourceNote,MediaBase,AttributeBase): # remove when transitition done. event_ref = EventRef() event_ref.set_reference_handle(event_handle) - event_ref.set_role( EventRef.PRIMARY) + event_ref.set_role((EventRef.PRIMARY,'')) self.set_death_ref( event_ref) def set_death_ref(self,event_ref): @@ -1339,7 +1339,7 @@ class Person(PrimaryObject,PrivateSourceNote,MediaBase,AttributeBase): # remove when transitition done. event_ref = EventRef() event_ref.set_reference_handle(event_handle) - event_ref.set_role( EventRef.PRIMARY) + event_ref.set_role((EventRef.PRIMARY,'')) self.add_event_ref( event_ref) def add_event_ref(self,event_ref): @@ -1384,7 +1384,7 @@ class Person(PrimaryObject,PrivateSourceNote,MediaBase,AttributeBase): for event_handle in event_list: event_ref = EventRef() event_ref.set_reference_handle(event_handle) - event_ref.set_role( EventRef.PRIMARY) + event_ref.set_role((EventRef.PRIMARY,'')) event_ref_list.append( event_ref) self.set_event_ref_list(event_ref_list) @@ -1562,6 +1562,8 @@ class Person(PrimaryObject,PrivateSourceNote,MediaBase,AttributeBase): @param frel: relationship between the Person and its father @type frel: tuple """ + assert type(mrel) == tuple + assert type(frel) == tuple self.parent_family_list.append((family_handle,mrel,frel)) def clear_parent_family_handle_list(self): @@ -2081,7 +2083,7 @@ class Family(PrimaryObject,SourceNote,MediaBase,AttributeBase): # remove when transitition done. event_ref = EventRef() event_ref.set_reference_handle(event_handle) - event_ref.set_role(EventRef.PRIMARY) + event_ref.set_role((EventRef.PRIMARY,'')) self.add_event_ref(event_ref) def add_event_ref(self,event_ref): @@ -2126,7 +2128,7 @@ class Family(PrimaryObject,SourceNote,MediaBase,AttributeBase): for event_handle in event_list: event_ref = EventRef() event_ref.set_reference_handle(event_handle) - event_ref.set_role(EventRef.PRIMARY) + event_ref.set_role((EventRef.PRIMARY,'')) event_ref_list.append( event_ref) self.set_event_ref_list(event_ref_list) @@ -4247,6 +4249,7 @@ class EventRef(BaseObject,PrivacyBase,NoteBase): """ Sets the role according to the given argument. """ + assert type(role) == tuple self.role = role class GenderStats: