Take advantage of refactored functionality in EventType and EventRoleType

svn: r13861
This commit is contained in:
Doug Blank 2009-12-20 22:21:00 +00:00
parent dcb926bf87
commit f4ca61c117
3 changed files with 30 additions and 38 deletions

View File

@ -41,8 +41,6 @@ from gettext import gettext as _
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
import DateHandler import DateHandler
from gen.lib.eventroletype import EventRoleType
from gen.lib.eventtype import EventType
from Utils import media_path_full from Utils import media_path_full
from gen.plug.docgen import IndexMark, INDEX_TYPE_ALP from gen.plug.docgen import IndexMark, INDEX_TYPE_ALP
@ -163,8 +161,8 @@ def find_spouse(person, family):
def find_marriage(database, family): def find_marriage(database, family):
for event_ref in family.get_event_ref_list(): for event_ref in family.get_event_ref_list():
event = database.get_event_from_handle(event_ref.ref) event = database.get_event_from_handle(event_ref.ref)
if event and event.type.value == EventType.MARRIAGE \ if (event and event.type.is_marriage() and
and event_ref.role.value == EventRoleType.FAMILY: event_ref.role.is_family()):
return event return event
return None return None
@ -175,8 +173,8 @@ def get_birth_or_fallback(database, person):
# now search the event list for fallbacks # now search the event list for fallbacks
for event_ref in person.get_primary_event_ref_list(): for event_ref in person.get_primary_event_ref_list():
event = database.get_event_from_handle(event_ref.ref) event = database.get_event_from_handle(event_ref.ref)
if event.type.value in [EventType.CHRISTEN, EventType.BAPTISM] \ if (event.type.is_birth_fallback() and
and event_ref.role.value == EventRoleType.PRIMARY: event_ref.role.is_primary()):
return event return event
return None return None
@ -187,10 +185,8 @@ def get_death_or_fallback(database, person):
# now search the event list for fallbacks # now search the event list for fallbacks
for event_ref in person.get_primary_event_ref_list(): for event_ref in person.get_primary_event_ref_list():
event = database.get_event_from_handle(event_ref.ref) event = database.get_event_from_handle(event_ref.ref)
if (event.type.value in [EventType.BURIAL, if (event.type.is_death_fallback() and
EventType.CREMATION, event_ref.role.is_primary()):
EventType.CAUSE_DEATH]
and event_ref.role.value == EventRoleType.PRIMARY):
return event return event
return None return None

View File

@ -479,7 +479,7 @@ def probably_alive(person, db, current_date=None, limit=0):
# If the recorded death year is before current year then # If the recorded death year is before current year then
# things are simple. # things are simple.
death_ref = person.get_death_ref() death_ref = person.get_death_ref()
if death_ref and death_ref.get_role() == gen.lib.EventRoleType.PRIMARY: if death_ref and death_ref.get_role().is_primary():
# If they have a prmary death ref # If they have a prmary death ref
if now: if now:
# If you are asking today, then they are dead # If you are asking today, then they are dead
@ -494,10 +494,8 @@ def probably_alive(person, db, current_date=None, limit=0):
# These are fairly good indications that someone's not alive. # These are fairly good indications that someone's not alive.
for ev_ref in person.get_primary_event_ref_list(): for ev_ref in person.get_primary_event_ref_list():
ev = db.get_event_from_handle(ev_ref.ref) ev = db.get_event_from_handle(ev_ref.ref)
if ev and ev.type in [gen.lib.EventType.CAUSE_DEATH, if ev and ev.type.is_death_fallback():
gen.lib.EventType.BURIAL, # If they have a primary death-related event
gen.lib.EventType.CREMATION]:
# If they have a prmary death-related event
if now: if now:
# If you are asking today, then they are dead # If you are asking today, then they are dead
return False return False
@ -515,7 +513,7 @@ def probably_alive(person, db, current_date=None, limit=0):
# If they were born within 100 years before current year then # If they were born within 100 years before current year then
# assume they are alive (we already know they are not dead). # assume they are alive (we already know they are not dead).
birth_ref = person.get_birth_ref() birth_ref = person.get_birth_ref()
if birth_ref and birth_ref.get_role() == gen.lib.EventRoleType.PRIMARY: if birth_ref and birth_ref.get_role().is_primary():
birth = db.get_event_from_handle(birth_ref.ref) birth = db.get_event_from_handle(birth_ref.ref)
if (birth.get_date_object().get_start_date() != gen.lib.Date.EMPTY): if (birth.get_date_object().get_start_date() != gen.lib.Date.EMPTY):
if not birth_date: if not birth_date:
@ -631,7 +629,7 @@ def probably_alive(person, db, current_date=None, limit=0):
if father_handle: if father_handle:
father = db.get_person_from_handle(father_handle) father = db.get_person_from_handle(father_handle)
father_birth_ref = father.get_birth_ref() father_birth_ref = father.get_birth_ref()
if father_birth_ref and father_birth_ref.get_role() == gen.lib.EventRoleType.PRIMARY: if father_birth_ref and father_birth_ref.get_role().is_primary():
father_birth = db.get_event_from_handle( father_birth = db.get_event_from_handle(
father_birth_ref.ref) father_birth_ref.ref)
dobj = father_birth.get_date_object() dobj = father_birth.get_date_object()
@ -640,7 +638,7 @@ def probably_alive(person, db, current_date=None, limit=0):
return True return True
father_death_ref = father.get_death_ref() father_death_ref = father.get_death_ref()
if father_death_ref and father_death_ref.get_role() == gen.lib.EventRoleType.PRIMARY: if father_death_ref and father_death_ref.get_role().is_primary():
father_death = db.get_event_from_handle( father_death = db.get_event_from_handle(
father_death_ref.ref) father_death_ref.ref)
dobj = father_death.get_date_object() dobj = father_death.get_date_object()
@ -655,7 +653,7 @@ def probably_alive(person, db, current_date=None, limit=0):
if mother_handle: if mother_handle:
mother = db.get_person_from_handle(mother_handle) mother = db.get_person_from_handle(mother_handle)
mother_birth_ref = mother.get_birth_ref() mother_birth_ref = mother.get_birth_ref()
if mother_birth_ref and mother_birth_ref.get_role() == gen.lib.EventRoleType.PRIMARY: if mother_birth_ref and mother_birth_ref.get_role().is_primary():
mother_birth = db.get_event_from_handle(mother_birth_ref.ref) mother_birth = db.get_event_from_handle(mother_birth_ref.ref)
dobj = mother_birth.get_date_object() dobj = mother_birth.get_date_object()
if dobj.get_start_date() != gen.lib.Date.EMPTY: if dobj.get_start_date() != gen.lib.Date.EMPTY:
@ -663,7 +661,7 @@ def probably_alive(person, db, current_date=None, limit=0):
return True return True
mother_death_ref = mother.get_death_ref() mother_death_ref = mother.get_death_ref()
if mother_death_ref and mother_death_ref.get_role() == gen.lib.EventRoleType.PRIMARY: if mother_death_ref and mother_death_ref.get_role().is_primary():
mother_death = db.get_event_from_handle( mother_death = db.get_event_from_handle(
mother_death_ref.ref) mother_death_ref.ref)
dobj = mother_death.get_date_object() dobj = mother_death.get_date_object()
@ -1042,7 +1040,7 @@ def get_participant_from_event(db, event_handle):
person = db.get_person_from_handle(personhandle) person = db.get_person_from_handle(personhandle)
for event_ref in person.get_event_ref_list(): for event_ref in person.get_event_ref_list():
if event_handle == event_ref.ref and \ if event_handle == event_ref.ref and \
event_ref.get_role() == gen.lib.EventRoleType.PRIMARY: event_ref.get_role().is_primary():
if participant: if participant:
ellipses = True ellipses = True
else: else:
@ -1057,7 +1055,7 @@ def get_participant_from_event(db, event_handle):
family = db.get_family_from_handle(familyhandle) family = db.get_family_from_handle(familyhandle)
for event_ref in family.get_event_ref_list(): for event_ref in family.get_event_ref_list():
if event_handle == event_ref.ref and \ if event_handle == event_ref.ref and \
event_ref.get_role() == gen.lib.EventRoleType.FAMILY: event_ref.get_role().is_family():
if participant: if participant:
ellipses = True ellipses = True
else: else:

View File

@ -35,7 +35,7 @@ from TransUtils import sgettext as _
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
import gen.lib import gen.lib
from gen.lib import ChildRefType, Date, EventType, Name, EventRoleType from gen.lib import ChildRefType, Date, Name
from gen.plug.docgen import FontStyle, ParagraphStyle, FONT_SANS_SERIF from gen.plug.docgen import FontStyle, ParagraphStyle, FONT_SANS_SERIF
from BasicUtils import name_displayer from BasicUtils import name_displayer
from gen.plug import Gramplet from gen.plug import Gramplet
@ -69,9 +69,7 @@ def _find_death_date(db, person):
event_list = person.get_primary_event_ref_list() event_list = person.get_primary_event_ref_list()
for event_ref in event_list: for event_ref in event_list:
event = db.get_event_from_handle(event_ref.ref) event = db.get_event_from_handle(event_ref.ref)
if (event.get_type() == EventType.BURIAL or if event.get_type().is_death_fallback():
event.get_type() == EventType.CAUSE_DEATH or
event.get_type() == EventType.CREMATION):
return event.get_date_object() return event.get_date_object()
return None return None
@ -137,13 +135,13 @@ def _find_records(db, filter, callname):
divorce_date = None divorce_date = None
for event_ref in family.get_event_ref_list(): for event_ref in family.get_event_ref_list():
event = db.get_event_from_handle(event_ref.ref) event = db.get_event_from_handle(event_ref.ref)
if event.get_type() == gen.lib.EventType.MARRIAGE and \ if (event.get_type().is_marriage() and
(event_ref.get_role() == gen.lib.EventRoleType.FAMILY or (event_ref.get_role().is_family() or
event_ref.get_role() == gen.lib.EventRoleType.PRIMARY ): event_ref.get_role().is_primary())):
marriage_date = event.get_date_object() marriage_date = event.get_date_object()
elif event.get_type() == gen.lib.EventType.DIVORCE and \ elif (event.get_type().is_divorce() and
(event_ref.get_role() == gen.lib.EventRoleType.FAMILY or (event_ref.get_role().is_family() or
event_ref.get_role() == gen.lib.EventRoleType.PRIMARY ): event_ref.get_role().is_primary())):
divorce_date = event.get_date_object() divorce_date = event.get_date_object()
if _good_date(marriage_date): if _good_date(marriage_date):
@ -225,13 +223,13 @@ def _find_records(db, filter, callname):
divorce_date = None divorce_date = None
for event_ref in family.get_event_ref_list(): for event_ref in family.get_event_ref_list():
event = db.get_event_from_handle(event_ref.ref) event = db.get_event_from_handle(event_ref.ref)
if event.get_type() == gen.lib.EventType.MARRIAGE and \ if (event.get_type().is_marriage() and
(event_ref.get_role() == gen.lib.EventRoleType.FAMILY or (event_ref.get_role().is_family() or
event_ref.get_role() == gen.lib.EventRoleType.PRIMARY ): event_ref.get_role().is_primary())):
marriage_date = event.get_date_object() marriage_date = event.get_date_object()
if event and event.get_type() == gen.lib.EventType.DIVORCE and \ if (event and event.get_type().is_divorce() and
(event_ref.get_role() == gen.lib.EventRoleType.FAMILY or (event_ref.get_role().is_family() or
event_ref.get_role() == gen.lib.EventRoleType.PRIMARY ): event_ref.get_role().is_primary())):
divorce_date = event.get_date_object() divorce_date = event.get_date_object()
father_death_date = _find_death_date(db, father) father_death_date = _find_death_date(db, father)