Add validation to gender field

This commit is contained in:
Nick Hall 2016-01-01 19:19:26 +00:00
parent be70956e90
commit 22c160f2bd

View File

@ -99,7 +99,7 @@ class Person(CitationBase, NoteBase, AttributeBase, MediaBase,
self.parent_family_list = [] self.parent_family_list = []
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_index = -1 self.death_ref_index = -1
self.birth_ref_index = -1 self.birth_ref_index = -1
if data: if data:
@ -136,7 +136,7 @@ class Person(CitationBase, NoteBase, AttributeBase, MediaBase,
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
self.death_ref_index, # 5 self.death_ref_index, # 5
@ -181,7 +181,7 @@ class Person(CitationBase, NoteBase, AttributeBase, MediaBase,
"_class": "Person", "_class": "Person",
"handle": Handle("Person", self.handle), # 0 "handle": Handle("Person", self.handle), # 0
"gramps_id": self.gramps_id, # 1 "gramps_id": self.gramps_id, # 1
"gender": self.gender, # 2 "gender": self.__gender, # 2
"primary_name": self.primary_name.to_struct(), # 3 "primary_name": self.primary_name.to_struct(), # 3
"alternate_names": [name.to_struct() "alternate_names": [name.to_struct()
for name in self.alternate_names], # 4 for name in self.alternate_names], # 4
@ -276,7 +276,7 @@ class Person(CitationBase, NoteBase, AttributeBase, MediaBase,
""" """
(self.handle, # 0 (self.handle, # 0
self.gramps_id, # 1 self.gramps_id, # 1
self.gender, # 2 self.__gender, # 2
primary_name, # 3 primary_name, # 3
alternate_names, # 4 alternate_names, # 4
self.death_ref_index, # 5 self.death_ref_index, # 5
@ -675,7 +675,9 @@ class Person(CitationBase, NoteBase, AttributeBase, MediaBase,
- Person.UNKNOWN - Person.UNKNOWN
:type gender: int :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) : def get_gender(self) :
""" """
@ -688,7 +690,10 @@ class Person(CitationBase, NoteBase, AttributeBase, MediaBase,
- Person.UNKNOWN - Person.UNKNOWN
:rtype: int :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): def set_birth_ref(self, event_ref):
""" """