Protection from null objects

This commit is contained in:
Doug Blank 2016-02-07 11:58:59 -05:00
parent 429b91d357
commit 202e1f5594
6 changed files with 23 additions and 18 deletions

View File

@ -1922,9 +1922,8 @@ class DbGeneric(DbWriteBase, DbReadBase, UpdateCallback, Callback):
def iter_sources(self, order_by=None):
return self.iter_items(order_by, Source)
def iter_tags(self):
return (Tag.create(data[1]) for data in self.get_tag_cursor())
def iter_tags(self, order_by=None):
return self.iter_items(order_by, Tag)
def set_prefixes(self, person, media, family, source, citation,
place, event, repository, note):

View File

@ -161,10 +161,12 @@ def insert_image(database, doc, photo, user,
#
#-------------------------------------------------------------------------
def find_spouse(person, family):
if person.get_handle() == family.get_father_handle():
spouse_handle = family.get_mother_handle()
else:
spouse_handle = family.get_father_handle()
spouse_handle = None
if family:
if person.get_handle() == family.get_father_handle():
spouse_handle = family.get_mother_handle()
else:
spouse_handle = family.get_father_handle()
return spouse_handle
#-------------------------------------------------------------------------

View File

@ -393,8 +393,9 @@ def find_children(db,p):
childlist = []
for family_handle in p.get_family_handle_list():
family = db.get_family_from_handle(family_handle)
for child_ref in family.get_child_ref_list():
childlist.append(child_ref.ref)
if family:
for child_ref in family.get_child_ref_list():
childlist.append(child_ref.ref)
return childlist
#-------------------------------------------------------------------------

View File

@ -75,6 +75,8 @@ class PersonEventEmbedList(EventEmbedList):
if family_handle_list:
for family_handle in family_handle_list:
family = self.dbstate.db.get_family_from_handle(family_handle)
if family is None:
continue
father_handle = family.get_father_handle()
mother_handle = family.get_mother_handle()
if self.obj.get_handle() == father_handle:

View File

@ -187,12 +187,13 @@ class Citations(Gramplet, DbGUIElement):
return False
def check_eventref_citations(self, obj):
for event_ref in obj.get_event_ref_list():
if self.check_attribute_citations(event_ref):
return True
event = self.dbstate.db.get_event_from_handle(event_ref.ref)
if self.check_event_citations(event):
return True
if obj:
for event_ref in obj.get_event_ref_list():
if self.check_attribute_citations(event_ref):
return True
event = self.dbstate.db.get_event_from_handle(event_ref.ref)
if self.check_event_citations(event):
return True
return False
def check_event_citations(self, event):

View File

@ -212,9 +212,9 @@ class PersonEvents(Events):
spouse = self.dbstate.db.get_person_from_handle(spouse_handle)
else:
spouse = None
for event_ref in family.get_event_ref_list():
self.add_event_ref(event_ref, spouse)
if family:
for event_ref in family.get_event_ref_list():
self.add_event_ref(event_ref, spouse)
def get_start_date(self):
"""