* src/RelLib/_PersonRef.py: Add to repository.

* src/RelLib/Makefile.am: Ship new file.
	* src/RelLib/_Person.py: Add person_ref_list to store person-to-
	person references.


svn: r6317
This commit is contained in:
Alex Roitman 2006-04-12 06:57:14 +00:00
parent b4b3ef0492
commit a7123580a7
3 changed files with 101 additions and 43 deletions

View File

@ -5,6 +5,11 @@
* src/ViewManager.py (ViewManager.change_page): Always toggle the * src/ViewManager.py (ViewManager.change_page): Always toggle the
sidebar buttons, even if no data is loaded. sidebar buttons, even if no data is loaded.
* src/RelLib/_PersonRef.py: Add to repository.
* src/RelLib/Makefile.am: Ship new file.
* src/RelLib/_Person.py: Add person_ref_list to store person-to-
person references.
2006-04-11 Martin Hawlisch <Martin.Hawlisch@gmx.de> 2006-04-11 Martin Hawlisch <Martin.Hawlisch@gmx.de>
* src/images/mk_blue_marble.py: Properly exit on error to let `make` * src/images/mk_blue_marble.py: Properly exit on error to let `make`
stop in that case; Provide fallback if jpegtrans does not work/exist. stop in that case; Provide fallback if jpegtrans does not work/exist.

View File

@ -30,6 +30,7 @@ pkgdata_PYTHON = \
_NoteBase.py\ _NoteBase.py\
_Note.py\ _Note.py\
_Person.py\ _Person.py\
_PersonRef.py\
_PlaceBase.py\ _PlaceBase.py\
_Place.py\ _Place.py\
_PrimaryObject.py\ _PrimaryObject.py\

View File

@ -46,7 +46,7 @@ from _UrlBase import UrlBase
from _Name import Name from _Name import Name
from _EventRef import EventRef from _EventRef import EventRef
from _LdsOrd import LdsOrd from _LdsOrd import LdsOrd
from _PersonRef import PersonRef
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# Person class # Person class
@ -109,6 +109,7 @@ class Person(PrimaryObject, SourceNote,
self.parent_family_list = [] self.parent_family_list = []
self.nickname = "" self.nickname = ""
self.alternate_names = [] self.alternate_names = []
self.person_ref_list = []
self.gender = Person.UNKNOWN self.gender = Person.UNKNOWN
self.death_ref = None self.death_ref = None
self.birth_ref = None self.birth_ref = None
@ -145,26 +146,29 @@ class Person(PrimaryObject, SourceNote,
else: else:
death_ref = self.death_ref.serialize() death_ref = self.death_ref.serialize()
return (self.handle, return (
self.gramps_id, self.handle, # 0
self.gender, self.gramps_id, # 1
self.primary_name.serialize(), self.gender, # 2
[name.serialize() for name in self.alternate_names], self.primary_name.serialize(), # 3
unicode(self.nickname), [name.serialize() for name in self.alternate_names], # 4
death_ref, unicode(self.nickname), # 5
birth_ref, death_ref, # 6
[er.serialize() for er in self.event_ref_list], birth_ref, # 7
self.family_list, [er.serialize() for er in self.event_ref_list], # 8
self.parent_family_list, self.family_list, # 9
MediaBase.serialize(self), self.parent_family_list, # 10
AddressBase.serialize(self), MediaBase.serialize(self), # 11
AttributeBase.serialize(self), AddressBase.serialize(self), # 12
UrlBase.serialize(self), AttributeBase.serialize(self), # 13
LdsOrdBase.serialize(self), UrlBase.serialize(self), # 14
SourceNote.serialize(self), LdsOrdBase.serialize(self), # 15
self.change, SourceNote.serialize(self), # 16
self.marker, self.change, # 17
self.private) self.marker, # 18
self.private, # 19
[pr.serialize() for pr in self.person_ref_list] # 20
)
def unserialize(self, data): def unserialize(self, data):
""" """
@ -175,26 +179,29 @@ class Person(PrimaryObject, SourceNote,
Person object Person object
@type data: tuple @type data: tuple
""" """
(self.handle, (
self.gramps_id, self.handle, # 0
self.gender, self.gramps_id, # 1
primary_name, self.gender, # 2
alternate_names, primary_name, # 3
self.nickname, alternate_names, # 4
death_ref, self.nickname, # 5
birth_ref, death_ref, # 6
event_ref_list, birth_ref, # 7
self.family_list, event_ref_list, # 8
self.parent_family_list, self.family_list, # 9
media_list, self.parent_family_list, # 10
address_list, media_list, # 11
attribute_list, address_list, # 12
urls, attribute_list, # 13
lds_ord_list, urls, # 14
sn, lds_ord_list, # 15
self.change, sn, # 16
self.marker, self.change, # 17
self.private) = data self.marker, # 18
self.private, # 19
person_ref_list, # 20
) = data
self.primary_name.unserialize(primary_name) self.primary_name.unserialize(primary_name)
if death_ref: if death_ref:
@ -205,6 +212,8 @@ class Person(PrimaryObject, SourceNote,
for name in alternate_names] for name in alternate_names]
self.event_ref_list = [EventRef().unserialize(er) self.event_ref_list = [EventRef().unserialize(er)
for er in event_ref_list] for er in event_ref_list]
self.person_ref_list = [PersonRef().unserialize(pr)
for pr in person_ref_list]
MediaBase.unserialize(self, media_list) MediaBase.unserialize(self, media_list)
LdsOrdBase.unserialize(self, lds_ord_list) LdsOrdBase.unserialize(self, lds_ord_list)
AddressBase.unserialize(self, address_list) AddressBase.unserialize(self, address_list)
@ -218,6 +227,8 @@ class Person(PrimaryObject, SourceNote,
self.event_ref_list + [self.birth_ref, self.event_ref_list + [self.birth_ref,
self.death_ref] self.death_ref]
if ref] if ref]
elif classname == 'Person':
return handle in [ref.ref for ref in self.person_ref_list]
elif classname == 'Family': elif classname == 'Family':
return handle in self.family_list + \ return handle in self.family_list + \
[item[0] for item in self.parent_family_list ] [item[0] for item in self.parent_family_list ]
@ -234,6 +245,10 @@ class Person(PrimaryObject, SourceNote,
self.death_ref = None self.death_ref = None
if self.birth_ref and self.birth_ref.ref in handle_list: if self.birth_ref and self.birth_ref.ref in handle_list:
self.birth_ref = None self.birth_ref = None
elif classname == 'Person':
new_list = [ref for ref in self.person_ref_list \
if ref not in handle_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 ]
@ -257,6 +272,12 @@ class Person(PrimaryObject, SourceNote,
self.death_ref.ref = new_handle self.death_ref.ref = new_handle
if self.birth_ref and self.birth_ref.ref == old_handle: if self.birth_ref and self.birth_ref.ref == old_handle:
self.birth_ref.ref = new_handle self.birth_ref.ref = new_handle
elif classname == 'Person':
handle_list = [ref.ref for ref in self.person_ref_list]
while old_handle in handle_list:
ix = handle_list.index(old_handle)
self.person_ref_list[ix].ref = new_handle
handle_list[ix] = ''
elif classname == 'Family': elif classname == 'Family':
while old_handle in self.family_list: while old_handle in self.family_list:
ix = self.family_list.index(old_handle) ix = self.family_list.index(old_handle)
@ -295,7 +316,8 @@ class Person(PrimaryObject, SourceNote,
return [self.primary_name] + self.media_list + \ return [self.primary_name] + self.media_list + \
self.alternate_names + self.address_list + \ self.alternate_names + self.address_list + \
self.attribute_list + self.urls + \ self.attribute_list + self.urls + \
self.source_list + self.event_ref_list + add_list self.source_list + self.event_ref_list + add_list + \
self.person_ref_list
def get_sourcref_child_list(self): def get_sourcref_child_list(self):
""" """
@ -329,7 +351,7 @@ class Person(PrimaryObject, SourceNote,
""" """
birth_death = [i for i in [self.birth_ref, self.death_ref] if i] 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.event_ref_list + birth_death + self.person_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",
@ -803,3 +825,33 @@ class Person(PrimaryObject, SourceNote,
return None return None
else: else:
return self.parent_family_list[0][0] return self.parent_family_list[0][0]
def add_person_ref(self,person_ref):
"""
Adds the L{PersonRef} to the Person instance's L{PersonRef} list.
@param person_ref: the L{PersonRef} to be added to the
Person's L{PersonRef} list.
@type person_ref: PersonRef
"""
if person_ref and not isinstance(person_ref, PersonRef):
raise ValueError("Expecting PersonRef instance")
self.person_ref_list.append(person_ref)
def get_person_ref_list(self):
"""
Returns the list of L{PersonRef} objects.
@returns: Returns the list of L{PersonRef} objects.
@rtype: list
"""
return self.person_ref_list
def set_person_ref_list(self, person_ref_list):
"""
Sets the Person instance's L{PersonRef} list to the passed list.
@param event_ref_list: List of valid L{PersonRef} objects
@type event_ref_list: list
"""
self.person_ref_list = person_ref_list