* src/GrampsDb/_GrampsBSDDB.py (gramps_upgrade_9): Convert upgrade
to using new birth/death reference approach. * src/GrampsDb/_GrampsDbBase.py (commit_person): Simplify updating of the custom event roles. * src/GrampsDb/_WriteXML.py (write_person): Use methods to get birth/death ref, not raw attributes. * src/RelLib/_Person.py: Convert to using birth and death ref indices. birth/deat reference; use methods to get birth/death ref, not raw attributes. svn: r6762
This commit is contained in:
parent
b2e8acc59d
commit
9e45d663b6
11
ChangeLog
11
ChangeLog
@ -3,8 +3,17 @@
|
|||||||
sync with db and active person.
|
sync with db and active person.
|
||||||
|
|
||||||
2006-05-23 Alex Roitman <shura@gramps-project.org>
|
2006-05-23 Alex Roitman <shura@gramps-project.org>
|
||||||
|
* src/GrampsDb/_GrampsBSDDB.py (gramps_upgrade_9): Convert upgrade
|
||||||
|
to using new birth/death reference approach.
|
||||||
|
* src/GrampsDb/_GrampsDbBase.py (commit_person): Simplify updating
|
||||||
|
of the custom event roles.
|
||||||
|
* src/GrampsDb/_WriteXML.py (write_person): Use methods to get
|
||||||
|
birth/death ref, not raw attributes.
|
||||||
|
* src/RelLib/_Person.py: Convert to using birth and death ref
|
||||||
|
indices.
|
||||||
* src/GrampsDb/_ReadXML.py (start_eventref): Do not reset existing
|
* src/GrampsDb/_ReadXML.py (start_eventref): Do not reset existing
|
||||||
birth/deat reference.
|
birth/deat reference; use methods to get birth/death ref, not raw
|
||||||
|
attributes.
|
||||||
|
|
||||||
2006-05-23 Don Allingham <don@gramps-project.org>
|
2006-05-23 Don Allingham <don@gramps-project.org>
|
||||||
* src/DataViews/_RelationView.py: renamed from _FamilyView
|
* src/DataViews/_RelationView.py: renamed from _FamilyView
|
||||||
|
@ -1439,12 +1439,14 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
|
|||||||
if birth_handle:
|
if birth_handle:
|
||||||
event_ref = EventRef()
|
event_ref = EventRef()
|
||||||
event_ref.ref = birth_handle
|
event_ref.ref = birth_handle
|
||||||
person.birth_ref = event_ref
|
person.event_ref_list.append(event_ref)
|
||||||
|
person.birth_ref_index = len(person.event_ref_list) - 1
|
||||||
|
|
||||||
if death_handle:
|
if death_handle:
|
||||||
event_ref = EventRef()
|
event_ref = EventRef()
|
||||||
event_ref.ref = death_handle
|
event_ref.ref = death_handle
|
||||||
person.death_ref = event_ref
|
person.event_ref_list.append(event_ref)
|
||||||
|
person.death_ref_index = len(person.event_ref_list) - 1
|
||||||
|
|
||||||
for event_handle in event_list:
|
for event_handle in event_list:
|
||||||
event_ref = EventRef()
|
event_ref = EventRef()
|
||||||
|
@ -453,12 +453,9 @@ class GrampsDbBase(GrampsDBCallback):
|
|||||||
if person.marker.is_custom():
|
if person.marker.is_custom():
|
||||||
self.marker_names.add(str(person.marker))
|
self.marker_names.add(str(person.marker))
|
||||||
|
|
||||||
eref_list = [eref for eref in (person.event_ref_list
|
self.event_role_names.update([str(eref.role)
|
||||||
+ [person.birth_ref,person.death_ref])
|
for eref in person.event_ref_list
|
||||||
if eref]
|
if eref.role.is_custom()])
|
||||||
|
|
||||||
self.event_role_names.update(
|
|
||||||
[str(eref.role) for eref in eref_list if eref.role.is_custom()])
|
|
||||||
|
|
||||||
self.name_types.update([str(name.type)
|
self.name_types.update([str(name.type)
|
||||||
for name in ([person.primary_name]
|
for name in ([person.primary_name]
|
||||||
|
@ -773,11 +773,11 @@ class GrampsParser(UpdateCallback):
|
|||||||
elif self.person:
|
elif self.person:
|
||||||
event.personal = True
|
event.personal = True
|
||||||
if (event.type == RelLib.EventType.BIRTH) \
|
if (event.type == RelLib.EventType.BIRTH) \
|
||||||
and (self.person.birth_ref == None):
|
and (self.person.get_birth_ref() == None):
|
||||||
self.person.birth_ref = self.eventref
|
self.person.set_birth_ref(self.eventref)
|
||||||
elif (event.type == RelLib.EventType.DEATH) \
|
elif (event.type == RelLib.EventType.DEATH) \
|
||||||
and (self.person.death_ref == None):
|
and (self.person.get_death_ref() == None):
|
||||||
self.person.death_ref = self.eventref
|
self.person.set_death_ref(self.eventref)
|
||||||
else:
|
else:
|
||||||
self.person.add_event_ref(self.eventref)
|
self.person.add_event_ref(self.eventref)
|
||||||
|
|
||||||
|
@ -411,8 +411,8 @@ class XmlWriter(UpdateCallback):
|
|||||||
for name in person.get_alternate_names():
|
for name in person.get_alternate_names():
|
||||||
self.dump_name(name,True,index+1)
|
self.dump_name(name,True,index+1)
|
||||||
|
|
||||||
self.dump_event_ref(person.birth_ref,index+1)
|
self.dump_event_ref(person.get_birth_ref(),index+1)
|
||||||
self.dump_event_ref(person.death_ref,index+1)
|
self.dump_event_ref(person.get_death_ref(),index+1)
|
||||||
for event_ref in person.get_event_ref_list():
|
for event_ref in person.get_event_ref_list():
|
||||||
self.dump_event_ref(event_ref,index+1)
|
self.dump_event_ref(event_ref,index+1)
|
||||||
|
|
||||||
|
@ -106,8 +106,8 @@ class Person(PrimaryObject,SourceBase,NoteBase,MediaBase,
|
|||||||
self.alternate_names = []
|
self.alternate_names = []
|
||||||
self.person_ref_list = []
|
self.person_ref_list = []
|
||||||
self.gender = Person.UNKNOWN
|
self.gender = Person.UNKNOWN
|
||||||
self.death_ref = None
|
self.death_ref_index = -1
|
||||||
self.birth_ref = None
|
self.birth_ref_index = -1
|
||||||
|
|
||||||
if data:
|
if data:
|
||||||
self.unserialize(data)
|
self.unserialize(data)
|
||||||
@ -132,23 +132,14 @@ class Person(PrimaryObject,SourceBase,NoteBase,MediaBase,
|
|||||||
be considered persistent.
|
be considered persistent.
|
||||||
@rtype: tuple
|
@rtype: tuple
|
||||||
"""
|
"""
|
||||||
if self.birth_ref == None:
|
|
||||||
birth_ref = None
|
|
||||||
else:
|
|
||||||
birth_ref = self.birth_ref.serialize()
|
|
||||||
if self.death_ref == None:
|
|
||||||
death_ref = None
|
|
||||||
else:
|
|
||||||
death_ref = self.death_ref.serialize()
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
self.handle, # 0
|
self.handle, # 0
|
||||||
self.gramps_id, # 1
|
self.gramps_id, # 1
|
||||||
self.gender, # 2
|
self.gender, # 2
|
||||||
self.primary_name.serialize(), # 3
|
self.primary_name.serialize(), # 3
|
||||||
[name.serialize() for name in self.alternate_names], # 4
|
[name.serialize() for name in self.alternate_names], # 4
|
||||||
death_ref, # 5
|
self.death_ref_index, # 5
|
||||||
birth_ref, # 6
|
self.birth_ref_index, # 6
|
||||||
[er.serialize() for er in self.event_ref_list], # 7
|
[er.serialize() for er in self.event_ref_list], # 7
|
||||||
self.family_list, # 8
|
self.family_list, # 8
|
||||||
self.parent_family_list, # 9
|
self.parent_family_list, # 9
|
||||||
@ -180,8 +171,8 @@ class Person(PrimaryObject,SourceBase,NoteBase,MediaBase,
|
|||||||
self.gender, # 2
|
self.gender, # 2
|
||||||
primary_name, # 3
|
primary_name, # 3
|
||||||
alternate_names, # 4
|
alternate_names, # 4
|
||||||
death_ref, # 5
|
self.death_ref_index, # 5
|
||||||
birth_ref, # 6
|
self.birth_ref_index, # 6
|
||||||
event_ref_list, # 7
|
event_ref_list, # 7
|
||||||
self.family_list, # 8
|
self.family_list, # 8
|
||||||
self.parent_family_list, # 9
|
self.parent_family_list, # 9
|
||||||
@ -200,10 +191,6 @@ class Person(PrimaryObject,SourceBase,NoteBase,MediaBase,
|
|||||||
|
|
||||||
self.marker.unserialize(marker)
|
self.marker.unserialize(marker)
|
||||||
self.primary_name.unserialize(primary_name)
|
self.primary_name.unserialize(primary_name)
|
||||||
if death_ref:
|
|
||||||
self.death_ref = EventRef().unserialize(death_ref)
|
|
||||||
if birth_ref:
|
|
||||||
self.birth_ref = EventRef().unserialize(birth_ref)
|
|
||||||
self.alternate_names = [Name().unserialize(name)
|
self.alternate_names = [Name().unserialize(name)
|
||||||
for name in alternate_names]
|
for name in alternate_names]
|
||||||
self.event_ref_list = [EventRef().unserialize(er)
|
self.event_ref_list = [EventRef().unserialize(er)
|
||||||
@ -220,10 +207,7 @@ class Person(PrimaryObject,SourceBase,NoteBase,MediaBase,
|
|||||||
|
|
||||||
def _has_handle_reference(self, classname, handle):
|
def _has_handle_reference(self, classname, handle):
|
||||||
if classname == 'Event':
|
if classname == 'Event':
|
||||||
return handle in [ref.ref for ref in
|
return handle in [ref.ref for ref in self.event_ref_list]
|
||||||
self.event_ref_list + [self.birth_ref,
|
|
||||||
self.death_ref]
|
|
||||||
if ref]
|
|
||||||
elif classname == 'Person':
|
elif classname == 'Person':
|
||||||
return handle in [ref.ref for ref in self.person_ref_list]
|
return handle in [ref.ref for ref in self.person_ref_list]
|
||||||
elif classname == 'Family':
|
elif classname == 'Family':
|
||||||
@ -235,19 +219,25 @@ class Person(PrimaryObject,SourceBase,NoteBase,MediaBase,
|
|||||||
|
|
||||||
def _remove_handle_references(self, classname, handle_list):
|
def _remove_handle_references(self, classname, handle_list):
|
||||||
if classname == 'Event':
|
if classname == 'Event':
|
||||||
new_list = [ ref for ref in self.event_ref_list \
|
new_list = [ref for ref in self.event_ref_list
|
||||||
if ref and ref.ref not in handle_list ]
|
if ref.ref not in handle_list]
|
||||||
|
# If deleting removing the reference to the event
|
||||||
|
# to which birth or death ref_index points, unset the index
|
||||||
|
if (self.birth_ref_index != -1) \
|
||||||
|
and (self.event_ref_list[self.birth_ref_index]
|
||||||
|
in handle_list):
|
||||||
|
self.birth_ref_index = -1
|
||||||
|
if (self.death_ref_index != -1) \
|
||||||
|
and (self.event_ref_list[self.death_ref_index]
|
||||||
|
in handle_list):
|
||||||
|
self.death_ref_index = -1
|
||||||
self.event_ref_list = new_list
|
self.event_ref_list = new_list
|
||||||
if self.death_ref and self.death_ref.ref in handle_list:
|
|
||||||
self.death_ref = None
|
|
||||||
if self.birth_ref and self.birth_ref.ref in handle_list:
|
|
||||||
self.birth_ref = None
|
|
||||||
elif classname == 'Person':
|
elif classname == 'Person':
|
||||||
new_list = [ref for ref in self.person_ref_list \
|
new_list = [ref for ref in self.person_ref_list
|
||||||
if ref not in handle_list]
|
if ref not in handle_list]
|
||||||
self.person_ref_list = new_list
|
self.person_ref_list = new_list
|
||||||
elif classname == 'Family':
|
elif classname == 'Family':
|
||||||
new_list = [ handle for handle in self.family_list \
|
new_list = [ handle for handle in self.family_list
|
||||||
if handle not in handle_list ]
|
if handle not in handle_list ]
|
||||||
self.family_list = new_list
|
self.family_list = new_list
|
||||||
new_list = [ handle for handle in self.parent_family_list \
|
new_list = [ handle for handle in self.parent_family_list \
|
||||||
@ -265,10 +255,6 @@ class Person(PrimaryObject,SourceBase,NoteBase,MediaBase,
|
|||||||
ix = handle_list.index(old_handle)
|
ix = handle_list.index(old_handle)
|
||||||
self.event_ref_list[ix].ref = new_handle
|
self.event_ref_list[ix].ref = new_handle
|
||||||
handle_list[ix] = ''
|
handle_list[ix] = ''
|
||||||
if self.death_ref and self.death_ref.ref == old_handle:
|
|
||||||
self.death_ref.ref = new_handle
|
|
||||||
if self.birth_ref and self.birth_ref.ref == old_handle:
|
|
||||||
self.birth_ref.ref = new_handle
|
|
||||||
elif classname == 'Person':
|
elif classname == 'Person':
|
||||||
handle_list = [ref.ref for ref in self.person_ref_list]
|
handle_list = [ref.ref for ref in self.person_ref_list]
|
||||||
while old_handle in handle_list:
|
while old_handle in handle_list:
|
||||||
@ -344,9 +330,8 @@ class Person(PrimaryObject,SourceBase,NoteBase,MediaBase,
|
|||||||
@return: Returns the list of objects refereincing primary objects.
|
@return: Returns the list of objects refereincing primary objects.
|
||||||
@rtype: list
|
@rtype: list
|
||||||
"""
|
"""
|
||||||
birth_death = [i for i in [self.birth_ref, self.death_ref] if i]
|
|
||||||
return self.get_sourcref_child_list() + self.source_list \
|
return self.get_sourcref_child_list() + self.source_list \
|
||||||
+ self.event_ref_list + birth_death + self.person_ref_list
|
+ self.event_ref_list
|
||||||
|
|
||||||
def get_complete_flag(self):
|
def get_complete_flag(self):
|
||||||
warn( "Use get_marker instead of get_complete_flag",
|
warn( "Use get_marker instead of get_complete_flag",
|
||||||
@ -433,15 +418,6 @@ class Person(PrimaryObject,SourceBase,NoteBase,MediaBase,
|
|||||||
"""
|
"""
|
||||||
return self.gender
|
return self.gender
|
||||||
|
|
||||||
def set_birth_handle(self, event_handle):
|
|
||||||
warn( "Use set_birth_ref instead of set_birth_handle",
|
|
||||||
DeprecationWarning, 2)
|
|
||||||
# Wrapper for old API
|
|
||||||
# remove when transitition done.
|
|
||||||
event_ref = EventRef()
|
|
||||||
event_ref.set_reference_handle(event_handle)
|
|
||||||
self.set_birth_ref( event_ref)
|
|
||||||
|
|
||||||
def set_birth_ref(self, event_ref):
|
def set_birth_ref(self, event_ref):
|
||||||
"""
|
"""
|
||||||
Assigns the birth event to the Person object. This is accomplished
|
Assigns the birth event to the Person object. This is accomplished
|
||||||
@ -454,16 +430,14 @@ class Person(PrimaryObject,SourceBase,NoteBase,MediaBase,
|
|||||||
"""
|
"""
|
||||||
if event_ref and not isinstance(event_ref, EventRef):
|
if event_ref and not isinstance(event_ref, EventRef):
|
||||||
raise ValueError("Expecting EventRef instance")
|
raise ValueError("Expecting EventRef instance")
|
||||||
self.birth_ref = event_ref
|
|
||||||
|
|
||||||
def set_death_handle(self, event_handle):
|
# check whether we already have this ref in the list
|
||||||
warn( "Use set_death_ref instead of set_death_handle",
|
matches = [event_ref.is_equal(ref) for ref in self.event_ref_list]
|
||||||
DeprecationWarning, 2)
|
try:
|
||||||
# Wrapper for old API
|
self.birth_ref_index = matches.index(True)
|
||||||
# remove when transitition done.
|
except ValueError:
|
||||||
event_ref = EventRef()
|
self.event_ref_list.append(event_ref)
|
||||||
event_ref.set_reference_handle(event_handle)
|
self.birth_ref_index = len(self.event_ref_list)-1
|
||||||
self.set_death_ref( event_ref)
|
|
||||||
|
|
||||||
def set_death_ref(self, event_ref):
|
def set_death_ref(self, event_ref):
|
||||||
"""
|
"""
|
||||||
@ -477,7 +451,13 @@ class Person(PrimaryObject,SourceBase,NoteBase,MediaBase,
|
|||||||
"""
|
"""
|
||||||
if event_ref and not isinstance(event_ref, EventRef):
|
if event_ref and not isinstance(event_ref, EventRef):
|
||||||
raise ValueError("Expecting EventRef instance")
|
raise ValueError("Expecting EventRef instance")
|
||||||
self.death_ref = event_ref
|
# check whether we already have this ref in the list
|
||||||
|
matches = [event_ref.is_equal(ref) for ref in self.event_ref_list]
|
||||||
|
try:
|
||||||
|
self.death_ref_index = matches.index(True)
|
||||||
|
except ValueError:
|
||||||
|
self.event_ref_list.append(event_ref)
|
||||||
|
self.death_ref_index = len(self.event_ref_list)-1
|
||||||
|
|
||||||
def get_birth_ref(self):
|
def get_birth_ref(self):
|
||||||
"""
|
"""
|
||||||
@ -488,7 +468,13 @@ class Person(PrimaryObject,SourceBase,NoteBase,MediaBase,
|
|||||||
L{Event} has been assigned.
|
L{Event} has been assigned.
|
||||||
@rtype: EventRef
|
@rtype: EventRef
|
||||||
"""
|
"""
|
||||||
return self.birth_ref
|
if self.birth_ref_index == -1:
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
return self.event_ref_list[self.birth_ref_index]
|
||||||
|
except IndexError:
|
||||||
|
return None
|
||||||
|
|
||||||
def get_death_ref(self):
|
def get_death_ref(self):
|
||||||
"""
|
"""
|
||||||
@ -499,16 +485,13 @@ class Person(PrimaryObject,SourceBase,NoteBase,MediaBase,
|
|||||||
L{Event} has been assigned.
|
L{Event} has been assigned.
|
||||||
@rtype: event_ref
|
@rtype: event_ref
|
||||||
"""
|
"""
|
||||||
return self.death_ref
|
if self.death_ref_index == -1:
|
||||||
|
return None
|
||||||
def add_event_handle(self, event_handle):
|
else:
|
||||||
warn( "Use add_event_ref instead of add_event_handle",
|
try:
|
||||||
DeprecationWarning, 2)
|
return self.event_ref_list[self.death_ref_index]
|
||||||
# Wrapper for old API
|
except IndexError:
|
||||||
# remove when transitition done.
|
return None
|
||||||
event_ref = EventRef()
|
|
||||||
event_ref.set_reference_handle(event_handle)
|
|
||||||
self.add_event_ref( event_ref)
|
|
||||||
|
|
||||||
def add_event_ref(self, event_ref):
|
def add_event_ref(self, event_ref):
|
||||||
"""
|
"""
|
||||||
@ -522,18 +505,11 @@ class Person(PrimaryObject,SourceBase,NoteBase,MediaBase,
|
|||||||
"""
|
"""
|
||||||
if event_ref and not isinstance(event_ref, EventRef):
|
if event_ref and not isinstance(event_ref, EventRef):
|
||||||
raise ValueError("Expecting EventRef instance")
|
raise ValueError("Expecting EventRef instance")
|
||||||
|
# check whether we already have this ref in the list
|
||||||
|
matches = [event_ref.is_equal(ref) for ref in self.event_ref_list]
|
||||||
|
if matches.count(True) == 0:
|
||||||
self.event_ref_list.append(event_ref)
|
self.event_ref_list.append(event_ref)
|
||||||
|
|
||||||
def get_event_list(self):
|
|
||||||
warn( "Use get_event_ref_list instead of get_event_list",
|
|
||||||
DeprecationWarning, 2)
|
|
||||||
# Wrapper for old API
|
|
||||||
# remove when transitition done.
|
|
||||||
event_handle_list = []
|
|
||||||
for event_ref in self.get_event_ref_list():
|
|
||||||
event_handle_list.append( event_ref.get_reference_handle())
|
|
||||||
return event_handle_list
|
|
||||||
|
|
||||||
def get_event_ref_list(self):
|
def get_event_ref_list(self):
|
||||||
"""
|
"""
|
||||||
Returns the list of L{EventRef} objects associated with L{Event}
|
Returns the list of L{EventRef} objects associated with L{Event}
|
||||||
@ -545,18 +521,6 @@ class Person(PrimaryObject,SourceBase,NoteBase,MediaBase,
|
|||||||
"""
|
"""
|
||||||
return self.event_ref_list
|
return self.event_ref_list
|
||||||
|
|
||||||
def set_event_list(self, event_list):
|
|
||||||
warn( "Use set_event_ref_list instead of set_event_list",
|
|
||||||
DeprecationWarning, 2)
|
|
||||||
# Wrapper for old API
|
|
||||||
# remove when transitition done.
|
|
||||||
event_ref_list = []
|
|
||||||
for event_handle in event_list:
|
|
||||||
event_ref = EventRef()
|
|
||||||
event_ref.set_reference_handle(event_handle)
|
|
||||||
event_ref_list.append( event_ref)
|
|
||||||
self.set_event_ref_list(event_ref_list)
|
|
||||||
|
|
||||||
def set_event_ref_list(self, event_ref_list):
|
def set_event_ref_list(self, event_ref_list):
|
||||||
"""
|
"""
|
||||||
Sets the Person instance's L{EventRef} list to the passed list.
|
Sets the Person instance's L{EventRef} list to the passed list.
|
||||||
|
Loading…
Reference in New Issue
Block a user