* 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
This commit is contained in:
Don Allingham 2005-06-16 03:56:13 +00:00
parent f9a01d5854
commit 0802e3a811
3 changed files with 65 additions and 18 deletions

View File

@ -1,3 +1,8 @@
2005-06-15 Don Allingham <don@gramps-project.org>
* 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 <shura@gramps-project.org> 2005-06-15 Alex Roitman <shura@gramps-project.org>
* src/ListBox.py (EventListBox.set_place): Fix place setting. * src/ListBox.py (EventListBox.set_place): Fix place setting.

View File

@ -43,6 +43,7 @@ import RelLib
import const import const
import Utils import Utils
import DateHandler import DateHandler
import NameDisplay
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -299,6 +300,16 @@ class GrampsParser:
self.change = change self.change = change
self.dp = DateHandler.parser 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.ord = None
self.objref = None self.objref = None
self.object = None self.object = None
@ -875,19 +886,17 @@ class GrampsParser:
family = self.find_family_by_gramps_id(self.map_fid(attrs["ref"])) family = self.find_family_by_gramps_id(self.map_fid(attrs["ref"]))
if attrs.has_key("mrel"): if attrs.has_key("mrel"):
try: mval = attrs.has_key('mrel')
mrel = const.child_rel_notrans.index(attrs["mrel"]) mrel = (self.child_relmap.get(mval,RelLib.Person.CHILD_CUSTOM),
except: mval)
mrel = RelLib.Person.CHILD_NONE
else: else:
mrel = RelLib.Person.CHILD_BIRTH mrel = (RelLib.Person.CHILD_BIRTH,'Birth')
if attrs.has_key("frel"): if attrs.has_key("frel"):
try: fval = attrs.has_key('frel')
frel = const.child_rel_notrans.index(attrs["frel"]) frel = (self.child_relmap.get(fval,RelLib.Person.CHILD_CUSTOM),
except: fval)
frel = RelLib.Person.CHILD_NONE
else: else:
frel = RelLib.Person.CHILD_BIRTH frel = (RelLib.Person.CHILD_BIRTH,'Birth')
self.person.add_parent_family_handle(family.get_handle(),mrel,frel) self.person.add_parent_family_handle(family.get_handle(),mrel,frel)
def start_parentin(self,attrs): def start_parentin(self,attrs):
@ -1244,16 +1253,46 @@ class GrampsParser:
def stop_event(self,*tag): def stop_event(self,*tag):
if self.family: 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: else:
ref = RelLib.EventRef() 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: if self.event.get_type()[0] == RelLib.Event.BIRTH:
self.person.set_birth_ref(ref) self.person.set_birth_ref(ref)
elif self.event.get_type()[0] == RelLib.Event.DEATH: elif self.event.get_type()[0] == RelLib.Event.DEATH:
self.person.set_death_ref(ref) self.person.set_death_ref(ref)
else: else:
self.person.add_event_ref(ref) 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.db.commit_event(self.event,self.trans,self.change)
self.event = None self.event = None

View File

@ -1253,7 +1253,7 @@ class Person(PrimaryObject,PrivateSourceNote,MediaBase,AttributeBase):
# remove when transitition done. # remove when transitition done.
event_ref = EventRef() event_ref = EventRef()
event_ref.set_reference_handle(event_handle) 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) self.set_birth_ref( event_ref)
def set_birth_ref(self,event_ref): def set_birth_ref(self,event_ref):
@ -1276,7 +1276,7 @@ class Person(PrimaryObject,PrivateSourceNote,MediaBase,AttributeBase):
# remove when transitition done. # remove when transitition done.
event_ref = EventRef() event_ref = EventRef()
event_ref.set_reference_handle(event_handle) 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) self.set_death_ref( event_ref)
def set_death_ref(self,event_ref): def set_death_ref(self,event_ref):
@ -1339,7 +1339,7 @@ class Person(PrimaryObject,PrivateSourceNote,MediaBase,AttributeBase):
# remove when transitition done. # remove when transitition done.
event_ref = EventRef() event_ref = EventRef()
event_ref.set_reference_handle(event_handle) 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) self.add_event_ref( event_ref)
def add_event_ref(self,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: for event_handle in event_list:
event_ref = EventRef() event_ref = EventRef()
event_ref.set_reference_handle(event_handle) 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) event_ref_list.append( event_ref)
self.set_event_ref_list(event_ref_list) 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 @param frel: relationship between the Person and its father
@type frel: tuple @type frel: tuple
""" """
assert type(mrel) == tuple
assert type(frel) == tuple
self.parent_family_list.append((family_handle,mrel,frel)) self.parent_family_list.append((family_handle,mrel,frel))
def clear_parent_family_handle_list(self): def clear_parent_family_handle_list(self):
@ -2081,7 +2083,7 @@ class Family(PrimaryObject,SourceNote,MediaBase,AttributeBase):
# remove when transitition done. # remove when transitition done.
event_ref = EventRef() event_ref = EventRef()
event_ref.set_reference_handle(event_handle) 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) self.add_event_ref(event_ref)
def add_event_ref(self,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: for event_handle in event_list:
event_ref = EventRef() event_ref = EventRef()
event_ref.set_reference_handle(event_handle) 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) event_ref_list.append( event_ref)
self.set_event_ref_list(event_ref_list) 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. Sets the role according to the given argument.
""" """
assert type(role) == tuple
self.role = role self.role = role
class GenderStats: class GenderStats: