Protection against null objects; added ability to get fallback object rather than just date
svn: r15396
This commit is contained in:
parent
b3b100747e
commit
958a0fe898
@ -509,7 +509,7 @@ class SimpleAccess(object):
|
|||||||
return self.__event_date_obj(person, gen.lib.Person.get_birth_ref)
|
return self.__event_date_obj(person, gen.lib.Person.get_birth_ref)
|
||||||
|
|
||||||
|
|
||||||
def birth_or_fallback(self, person):
|
def birth_or_fallback(self, person, get_event=False):
|
||||||
"""
|
"""
|
||||||
Return the date of the person's birth or fallback event.
|
Return the date of the person's birth or fallback event.
|
||||||
|
|
||||||
@ -522,7 +522,9 @@ class SimpleAccess(object):
|
|||||||
person = self.dbase.get_person_from_handle(person)
|
person = self.dbase.get_person_from_handle(person)
|
||||||
event = gen.utils.get_birth_or_fallback(self.dbase,
|
event = gen.utils.get_birth_or_fallback(self.dbase,
|
||||||
person, "<i>%s</i>")
|
person, "<i>%s</i>")
|
||||||
if event:
|
if get_event:
|
||||||
|
return event
|
||||||
|
elif event:
|
||||||
return event.date
|
return event.date
|
||||||
else:
|
else:
|
||||||
return gen.lib.Date()
|
return gen.lib.Date()
|
||||||
@ -566,7 +568,7 @@ class SimpleAccess(object):
|
|||||||
person = self.dbase.get_person_from_handle(person)
|
person = self.dbase.get_person_from_handle(person)
|
||||||
return self.__event_date_obj(person, gen.lib.Person.get_death_ref)
|
return self.__event_date_obj(person, gen.lib.Person.get_death_ref)
|
||||||
|
|
||||||
def death_or_fallback(self, person):
|
def death_or_fallback(self, person, get_event=False):
|
||||||
"""
|
"""
|
||||||
Return the date of the person's death or fallback event.
|
Return the date of the person's death or fallback event.
|
||||||
|
|
||||||
@ -579,7 +581,9 @@ class SimpleAccess(object):
|
|||||||
person = self.dbase.get_person_from_handle(person)
|
person = self.dbase.get_person_from_handle(person)
|
||||||
event = gen.utils.get_death_or_fallback(self.dbase,
|
event = gen.utils.get_death_or_fallback(self.dbase,
|
||||||
person, "<i>%s</i>")
|
person, "<i>%s</i>")
|
||||||
if event:
|
if get_event:
|
||||||
|
return event
|
||||||
|
elif event:
|
||||||
return event.date
|
return event.date
|
||||||
else:
|
else:
|
||||||
return gen.lib.Date()
|
return gen.lib.Date()
|
||||||
@ -654,6 +658,7 @@ class SimpleAccess(object):
|
|||||||
@rtype: unicode
|
@rtype: unicode
|
||||||
"""
|
"""
|
||||||
assert(isinstance(event, (gen.lib.Event, NoneType)))
|
assert(isinstance(event, (gen.lib.Event, NoneType)))
|
||||||
|
if event:
|
||||||
return event.get_date_object()
|
return event.get_date_object()
|
||||||
|
|
||||||
def event_type(self, event):
|
def event_type(self, event):
|
||||||
@ -942,4 +947,11 @@ def by_date(event1, event2):
|
|||||||
1 if they are the same.
|
1 if they are the same.
|
||||||
@rtype: int
|
@rtype: int
|
||||||
"""
|
"""
|
||||||
|
if event1 and event2:
|
||||||
return cmp(event1.get_date_object() , event2.get_date_object())
|
return cmp(event1.get_date_object() , event2.get_date_object())
|
||||||
|
elif event1:
|
||||||
|
return -1
|
||||||
|
elif event2:
|
||||||
|
return 1
|
||||||
|
else:
|
||||||
|
return 0
|
||||||
|
Loading…
Reference in New Issue
Block a user