Add validation to gender field

This commit is contained in:
Nick Hall 2016-01-01 19:19:26 +00:00
parent 895f8a1cfc
commit 8717839809

View File

@ -99,7 +99,7 @@ class Person(CitationBase, NoteBase, AttributeBase, MediaBase,
self.parent_family_list = []
self.alternate_names = []
self.person_ref_list = []
self.gender = Person.UNKNOWN
self.__gender = Person.UNKNOWN
self.death_ref_index = -1
self.birth_ref_index = -1
if data:
@ -136,7 +136,7 @@ class Person(CitationBase, NoteBase, AttributeBase, MediaBase,
return (
self.handle, # 0
self.gramps_id, # 1
self.gender, # 2
self.__gender, # 2
self.primary_name.serialize(), # 3
[name.serialize() for name in self.alternate_names], # 4
self.death_ref_index, # 5
@ -181,7 +181,7 @@ class Person(CitationBase, NoteBase, AttributeBase, MediaBase,
"_class": "Person",
"handle": Handle("Person", self.handle), # 0
"gramps_id": self.gramps_id, # 1
"gender": self.gender, # 2
"gender": self.__gender, # 2
"primary_name": self.primary_name.to_struct(), # 3
"alternate_names": [name.to_struct()
for name in self.alternate_names], # 4
@ -319,7 +319,7 @@ class Person(CitationBase, NoteBase, AttributeBase, MediaBase,
"""
(self.handle, # 0
self.gramps_id, # 1
self.gender, # 2
self.__gender, # 2
primary_name, # 3
alternate_names, # 4
self.death_ref_index, # 5
@ -717,7 +717,9 @@ class Person(CitationBase, NoteBase, AttributeBase, MediaBase,
- Person.UNKNOWN
:type gender: int
"""
self.gender = gender
if gender not in (Person.MALE, Person.FEMALE, Person.UNKNOWN):
raise ValueError('Attempt to assign invalid gender')
self.__gender = gender
def get_gender(self):
"""
@ -730,7 +732,10 @@ class Person(CitationBase, NoteBase, AttributeBase, MediaBase,
- Person.UNKNOWN
:rtype: int
"""
return self.gender
return self.__gender
gender = property(get_gender, set_gender, None,
'Returns or sets the gender of the person')
def set_birth_ref(self, event_ref):
"""