From 8717839809200f7882865202a7bf399ec1497c22 Mon Sep 17 00:00:00 2001 From: Nick Hall Date: Fri, 1 Jan 2016 19:19:26 +0000 Subject: [PATCH] Add validation to gender field --- gramps/gen/lib/person.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/gramps/gen/lib/person.py b/gramps/gen/lib/person.py index 247f75f9f..e2270f6c2 100644 --- a/gramps/gen/lib/person.py +++ b/gramps/gen/lib/person.py @@ -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): """