Moved fallback functions from Db to gen.utils
svn: r13876
This commit is contained in:
parent
c01fa3c174
commit
3a8b4d7e40
@ -166,30 +166,6 @@ def find_marriage(database, family):
|
||||
return event
|
||||
return None
|
||||
|
||||
def get_birth_or_fallback(database, person):
|
||||
birth_ref = person.get_birth_ref()
|
||||
if birth_ref: # regular birth found
|
||||
return database.get_event_from_handle(birth_ref.ref)
|
||||
# now search the event list for fallbacks
|
||||
for event_ref in person.get_primary_event_ref_list():
|
||||
event = database.get_event_from_handle(event_ref.ref)
|
||||
if (event.type.is_birth_fallback() and
|
||||
event_ref.role.is_primary()):
|
||||
return event
|
||||
return None
|
||||
|
||||
def get_death_or_fallback(database, person):
|
||||
death_ref = person.get_death_ref()
|
||||
if death_ref: # regular death found
|
||||
return database.get_event_from_handle(death_ref.ref)
|
||||
# now search the event list for fallbacks
|
||||
for event_ref in person.get_primary_event_ref_list():
|
||||
event = database.get_event_from_handle(event_ref.ref)
|
||||
if (event.type.is_death_fallback() and
|
||||
event_ref.role.is_primary()):
|
||||
return event
|
||||
return None
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Indexing function
|
||||
|
@ -40,8 +40,8 @@ import locale
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from gen.lib import Date
|
||||
from gen.utils import get_birth_or_fallback, get_death_or_fallback
|
||||
from BasicUtils import name_displayer as _nd
|
||||
from ReportBase import ReportUtils
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
@ -118,13 +118,13 @@ class Sort(object):
|
||||
first = self.database.get_person_from_handle(first_id)
|
||||
second = self.database.get_person_from_handle(second_id)
|
||||
|
||||
birth1 = ReportUtils.get_birth_or_fallback(self.database, first)
|
||||
birth1 = get_birth_or_fallback(self.database, first)
|
||||
if birth1:
|
||||
date1 = birth1.get_date_object()
|
||||
else:
|
||||
date1 = Date()
|
||||
|
||||
birth2 = ReportUtils.get_birth_or_fallback(self.database, second)
|
||||
birth2 = get_birth_or_fallback(self.database, second)
|
||||
if birth2:
|
||||
date2 = birth2.get_date_object()
|
||||
else:
|
||||
@ -143,7 +143,7 @@ class Sort(object):
|
||||
are equal, sorts by name"""
|
||||
first = self.database.get_person_from_handle(first_id)
|
||||
|
||||
birth1 = ReportUtils.get_birth_or_fallback(self.database, first)
|
||||
birth1 = get_birth_or_fallback(self.database, first)
|
||||
if birth1:
|
||||
date1 = birth1.get_date_object()
|
||||
else:
|
||||
|
@ -39,9 +39,9 @@ Mary Smith was born on 3/28/1923.
|
||||
#------------------------------------------------------------------------
|
||||
|
||||
from BasicUtils import name_displayer
|
||||
from ReportBase import ReportUtils
|
||||
import DateHandler
|
||||
import gen.lib
|
||||
from gen.utils import get_birth_or_fallback, get_death_or_fallback
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
@ -81,13 +81,13 @@ class SubstKeywords(object):
|
||||
self.m = ""
|
||||
self.M = ""
|
||||
|
||||
birth = ReportUtils.get_birth_or_fallback(database, person)
|
||||
birth = get_birth_or_fallback(database, person)
|
||||
if birth:
|
||||
self.b = DateHandler.get_date(birth)
|
||||
bplace_handle = birth.get_place_handle()
|
||||
if bplace_handle:
|
||||
self.B = database.get_place_from_handle(bplace_handle).get_title()
|
||||
death = ReportUtils.get_death_or_fallback(database, person)
|
||||
death = get_death_or_fallback(database, person)
|
||||
if death:
|
||||
self.d = DateHandler.get_date(death)
|
||||
dplace_handle = death.get_place_handle()
|
||||
|
@ -1520,46 +1520,6 @@ class GrampsDbBase(object):
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def get_birth_or_fallback(self, person):
|
||||
"""
|
||||
Get BIRTH event from a person, or fallback to an event around
|
||||
the time of birth.
|
||||
"""
|
||||
birth_ref = person.get_birth_ref()
|
||||
if birth_ref: # regular birth found
|
||||
event = self.get_event_from_handle(birth_ref.ref)
|
||||
if event:
|
||||
return event
|
||||
# now search the event list for fallbacks
|
||||
for event_ref in person.get_primary_event_ref_list():
|
||||
if event_ref:
|
||||
event = self.get_event_from_handle(event_ref.ref)
|
||||
if (event
|
||||
and event.type.is_birth_fallback()
|
||||
and event_ref.role.is_primary()):
|
||||
return event
|
||||
return None
|
||||
|
||||
def get_death_or_fallback(self, person):
|
||||
"""
|
||||
Get a DEATH event from a person, or fallback to an
|
||||
event around the time of death.
|
||||
"""
|
||||
death_ref = person.get_death_ref()
|
||||
if death_ref: # regular death found
|
||||
event = self.get_event_from_handle(death_ref.ref)
|
||||
if event:
|
||||
return event
|
||||
# now search the event list for fallbacks
|
||||
for event_ref in person.get_primary_event_ref_list():
|
||||
if event_ref:
|
||||
event = self.get_event_from_handle(event_ref.ref)
|
||||
if (event
|
||||
and event.type.is_death_fallback()
|
||||
and event_ref.role.is_primary()):
|
||||
return event
|
||||
return None
|
||||
|
||||
def add_child_to_family(self, family, child,
|
||||
mrel=gen.lib.ChildRefType(),
|
||||
frel=gen.lib.ChildRefType(),
|
||||
|
@ -10,6 +10,7 @@ pkgdata_PYTHON = \
|
||||
callback.py \
|
||||
callman.py \
|
||||
configmanager.py \
|
||||
fallback.py \
|
||||
progressmon.py \
|
||||
longop.py
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
Generic utilities useful for users of the gen package
|
||||
"""
|
||||
|
||||
from fallback import *
|
||||
from configmanager import ConfigManager
|
||||
from progressmon import ProgressMonitor
|
||||
from longop import LongOpStatus
|
||||
|
@ -36,8 +36,8 @@ import cgi
|
||||
import DateHandler
|
||||
from BasicUtils import name_displayer
|
||||
import Utils
|
||||
from ReportBase import ReportUtils
|
||||
import gen.lib
|
||||
from gen.utils import get_birth_or_fallback
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
@ -78,7 +78,7 @@ class ChildModel(gtk.ListStore):
|
||||
return self.family.get_child_ref_list()
|
||||
|
||||
def column_birth_day(self, data):
|
||||
birth = ReportUtils.get_birth_or_fallback(self.db, data)
|
||||
birth = get_birth_or_fallback(self.db, data)
|
||||
if birth:
|
||||
if birth.get_type() == gen.lib.EventType.BIRTH:
|
||||
return DateHandler.get_date(birth)
|
||||
|
@ -64,7 +64,6 @@ from glade import Glade
|
||||
from editprimary import EditPrimary
|
||||
from editchildref import EditChildRef
|
||||
from editperson import EditPerson
|
||||
from ReportBase import ReportUtils
|
||||
from displaytabs import (EmbeddedList, EventEmbedList, SourceEmbedList,
|
||||
FamilyAttrEmbedList, NoteTab, GalleryTab,
|
||||
FamilyLdsEmbedList, ChildModel)
|
||||
@ -72,8 +71,9 @@ from gui.widgets import (PrivacyButton, MonitoredEntry, MonitoredDataType)
|
||||
from gen.plug import CATEGORY_QR_FAMILY
|
||||
from QuestionDialog import (ErrorDialog, RunDatabaseRepair, WarningDialog,
|
||||
MessageHideDialog)
|
||||
|
||||
from gen.utils import get_birth_or_fallback, get_death_or_fallback
|
||||
from gui.selectors import SelectorFactory
|
||||
|
||||
SelectPerson = SelectorFactory('Person')
|
||||
|
||||
_RETURN = gdk.keyval_from_name("Return")
|
||||
@ -898,7 +898,7 @@ class EditFamily(EditPrimary):
|
||||
person = db.get_person_from_handle(handle)
|
||||
name = "%s [%s]" % (name_displayer.display(person),
|
||||
person.gramps_id)
|
||||
birth = ReportUtils.get_birth_or_fallback(db, person)
|
||||
birth = get_birth_or_fallback(db, person)
|
||||
self.callman.register_handles({'person': [handle]})
|
||||
if birth:
|
||||
#if event changes it view needs to update
|
||||
@ -906,7 +906,7 @@ class EditFamily(EditPrimary):
|
||||
if birth and birth.get_type() == gen.lib.EventType.BAPTISM:
|
||||
birth_label.set_label(_("Baptism:"))
|
||||
|
||||
death = ReportUtils.get_death_or_fallback(db, person)
|
||||
death = get_death_or_fallback(db, person)
|
||||
if death:
|
||||
#if event changes it view needs to update
|
||||
self.callman.register_handles({'event': [death.get_handle()]})
|
||||
|
@ -48,6 +48,7 @@ from BasicUtils import name_displayer
|
||||
from Utils import probably_alive
|
||||
from gui.utils import ProgressMeter
|
||||
import gen.lib
|
||||
from gen.utils import get_birth_or_fallback, get_death_or_fallback
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
@ -139,13 +140,13 @@ class TimeLine(Report):
|
||||
for p_id in self.plist:
|
||||
self.progress.step()
|
||||
p = self.database.get_person_from_handle(p_id)
|
||||
birth = ReportUtils.get_birth_or_fallback(self.database, p)
|
||||
birth = get_birth_or_fallback(self.database, p)
|
||||
if birth:
|
||||
b = birth.get_date_object().to_calendar(self.calendar).get_year()
|
||||
else:
|
||||
b = None
|
||||
|
||||
death = ReportUtils.get_death_or_fallback(self.database, p)
|
||||
death = get_death_or_fallback(self.database, p)
|
||||
if death:
|
||||
d = death.get_date_object().to_calendar(self.calendar).get_year()
|
||||
else:
|
||||
@ -242,13 +243,13 @@ class TimeLine(Report):
|
||||
|
||||
for p_id in self.plist:
|
||||
p = self.database.get_person_from_handle(p_id)
|
||||
birth = ReportUtils.get_birth_or_fallback(self.database, p)
|
||||
birth = get_birth_or_fallback(self.database, p)
|
||||
if birth:
|
||||
b = birth.get_date_object().to_calendar(self.calendar).get_year()
|
||||
else:
|
||||
b = None
|
||||
|
||||
death = ReportUtils.get_death_or_fallback(self.database, p)
|
||||
death = get_death_or_fallback(self.database, p)
|
||||
if death:
|
||||
d = death.get_date_object().to_calendar(self.calendar).get_year()
|
||||
else:
|
||||
|
@ -36,9 +36,9 @@ from gen.plug import Gramplet
|
||||
from TransUtils import sgettext as _
|
||||
from gettext import ngettext
|
||||
from BasicUtils import name_displayer
|
||||
from ReportBase import ReportUtils
|
||||
import DateHandler
|
||||
import gen
|
||||
from gen.utils import get_birth_or_fallback, get_death_or_fallback
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
@ -185,7 +185,7 @@ class PedigreeGramplet(Gramplet):
|
||||
self.set_box(generation, 0) # regardless, turn off line if on
|
||||
|
||||
def info_string(self, person):
|
||||
birth = ReportUtils.get_birth_or_fallback(self.dbstate.db, person)
|
||||
birth = get_birth_or_fallback(self.dbstate.db, person)
|
||||
if birth and birth.get_type() != gen.lib.EventType.BIRTH:
|
||||
sdate = DateHandler.get_date(birth)
|
||||
if sdate:
|
||||
@ -197,7 +197,7 @@ class PedigreeGramplet(Gramplet):
|
||||
else:
|
||||
bdate = ""
|
||||
|
||||
death = ReportUtils.get_death_or_fallback(self.dbstate.db, person)
|
||||
death = get_death_or_fallback(self.dbstate.db, person)
|
||||
if death and death.get_type() != gen.lib.EventType.DEATH:
|
||||
sdate = DateHandler.get_date(death)
|
||||
if sdate:
|
||||
|
@ -56,6 +56,7 @@ from ReportBase import Report, ReportUtils, MenuReportOptions
|
||||
from gen.plug.menu import NumberOption, ColorOption, BooleanOption, \
|
||||
EnumeratedListOption, PersonListOption, \
|
||||
SurnameColorOption
|
||||
from gen.utils import get_birth_or_fallback, get_death_or_fallback
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
@ -780,8 +781,8 @@ class FamilyLinesReport(Report):
|
||||
|
||||
# see if we have a birth/death or fallback dates we can use
|
||||
if self._incdates or self._incplaces:
|
||||
bth_event = ReportUtils.get_birth_or_fallback(self._db, person)
|
||||
dth_event = ReportUtils.get_death_or_fallback(self._db, person)
|
||||
bth_event = get_birth_or_fallback(self._db, person)
|
||||
dth_event = get_death_or_fallback(self._db, person)
|
||||
else:
|
||||
bth_event = None
|
||||
dth_event = None
|
||||
|
@ -43,6 +43,7 @@ from gen.plug.menu import (PersonOption, BooleanOption, NumberOption,
|
||||
EnumeratedListOption)
|
||||
from ReportBase import Report, ReportUtils, MenuReportOptions
|
||||
import DateHandler
|
||||
from gen.utils import get_birth_or_fallback, get_death_or_fallback
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
@ -169,13 +170,13 @@ class HourGlassReport(Report):
|
||||
p_id = person.get_gramps_id()
|
||||
name = name_displayer.display_formal(person)
|
||||
|
||||
birth_evt = ReportUtils.get_birth_or_fallback(self.__db, person)
|
||||
birth_evt = get_birth_or_fallback(self.__db, person)
|
||||
if birth_evt:
|
||||
birth = DateHandler.get_date(birth_evt)
|
||||
else:
|
||||
birth = ""
|
||||
|
||||
death_evt = ReportUtils.get_death_or_fallback(self.__db, person)
|
||||
death_evt = get_death_or_fallback(self.__db, person)
|
||||
if death_evt:
|
||||
death = DateHandler.get_date(death_evt)
|
||||
else:
|
||||
|
@ -53,6 +53,7 @@ import DateHandler
|
||||
import gen.lib
|
||||
import Utils
|
||||
import ThumbNails
|
||||
from gen.utils import get_birth_or_fallback, get_death_or_fallback
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
@ -403,13 +404,13 @@ class RelGraphReport(Report):
|
||||
|
||||
def get_date_strings(self, person):
|
||||
"returns tuple of birth/christening and death/burying date strings"
|
||||
birth_event = ReportUtils.get_birth_or_fallback(self.database, person)
|
||||
birth_event = get_birth_or_fallback(self.database, person)
|
||||
if birth_event:
|
||||
birth = self.get_event_string(birth_event)
|
||||
else:
|
||||
birth = ""
|
||||
|
||||
death_event = ReportUtils.get_death_or_fallback(self.database, person)
|
||||
death_event = get_death_or_fallback(self.database, person)
|
||||
if death_event:
|
||||
death = self.get_event_string(death_event)
|
||||
else:
|
||||
|
@ -40,7 +40,7 @@ from cgi import escape
|
||||
import gen.lib
|
||||
import DateHandler
|
||||
from BasicUtils import name_displayer
|
||||
from ReportBase import ReportUtils
|
||||
from gen.utils import get_birth_or_fallback, get_death_or_fallback
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
@ -111,7 +111,7 @@ class FormattingHelper(object):
|
||||
name = name_displayer.display(person)
|
||||
text = name
|
||||
if line_count >= 3:
|
||||
birth = ReportUtils.get_birth_or_fallback(self.dbstate.db, person)
|
||||
birth = get_birth_or_fallback(self.dbstate.db, person)
|
||||
if birth and use_markup and birth.get_type() != \
|
||||
gen.lib.EventType.BIRTH:
|
||||
bdate = "<i>%s</i>" % escape(DateHandler.get_date(birth))
|
||||
@ -126,7 +126,7 @@ class FormattingHelper(object):
|
||||
else:
|
||||
bdate = ""
|
||||
bplace = ""
|
||||
death = ReportUtils.get_death_or_fallback(self.dbstate.db, person)
|
||||
death = get_death_or_fallback(self.dbstate.db, person)
|
||||
if death and use_markup and death.get_type() != \
|
||||
gen.lib.EventType.DEATH:
|
||||
ddate = "<i>%s</i>" % escape(DateHandler.get_date(death))
|
||||
|
@ -46,6 +46,7 @@ from Errors import ReportError
|
||||
from ReportBase import Report, ReportUtils, MenuReportOptions
|
||||
import DateHandler
|
||||
import Sort
|
||||
from gen.utils import get_birth_or_fallback, get_death_or_fallback
|
||||
|
||||
_BORN = _('b.')
|
||||
_DIED = _('d.')
|
||||
@ -85,8 +86,8 @@ class DescendantReport(Report):
|
||||
self.by_birthdate = sort.by_birthdate
|
||||
|
||||
def dump_dates(self, person):
|
||||
birth = ReportUtils.get_birth_or_fallback(self.database, person)
|
||||
death = ReportUtils.get_death_or_fallback(self.database, person)
|
||||
birth = get_birth_or_fallback(self.database, person)
|
||||
death = get_death_or_fallback(self.database, person)
|
||||
|
||||
if birth or death:
|
||||
self.doc.write_text(' (')
|
||||
|
@ -44,6 +44,7 @@ from gen.plug.docgen import (IndexMark, FontStyle, ParagraphStyle,
|
||||
from gen.plug.menu import NumberOption, BooleanOption, PersonOption
|
||||
from ReportBase import Report, ReportUtils, MenuReportOptions
|
||||
import DateHandler
|
||||
from gen.utils import get_birth_or_fallback, get_death_or_fallback
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
@ -283,12 +284,12 @@ class KinshipReport(Report):
|
||||
name = name_displayer.display(person)
|
||||
mark = ReportUtils.get_person_mark(self.database, person)
|
||||
birth_date = ""
|
||||
birth = ReportUtils.get_birth_or_fallback(self.database, person)
|
||||
birth = get_birth_or_fallback(self.database, person)
|
||||
if birth:
|
||||
birth_date = DateHandler.get_date(birth)
|
||||
|
||||
death_date = ""
|
||||
death = ReportUtils.get_death_or_fallback(self.database, person)
|
||||
death = get_death_or_fallback(self.database, person)
|
||||
if death:
|
||||
death_date = DateHandler.get_date(death)
|
||||
dates = _(" (%(birth_date)s - %(death_date)s)") % {
|
||||
|
@ -61,7 +61,7 @@ import Errors
|
||||
import Bookmarks
|
||||
import const
|
||||
|
||||
from ReportBase import ReportUtils
|
||||
from gen.utils import get_birth_or_fallback, get_death_or_fallback
|
||||
|
||||
_GenderCode = {
|
||||
gen.lib.Person.MALE : u'\u2642',
|
||||
@ -582,7 +582,7 @@ class RelationshipView(NavigationView):
|
||||
2, 3, 0, 1, yoptions=0)
|
||||
|
||||
# Birth event.
|
||||
birth = ReportUtils.get_birth_or_fallback(self.dbstate.db, person)
|
||||
birth = get_birth_or_fallback(self.dbstate.db, person)
|
||||
if birth:
|
||||
birth_title = birth.get_type()
|
||||
else:
|
||||
@ -593,7 +593,7 @@ class RelationshipView(NavigationView):
|
||||
subtbl.attach(widgets.BasicLabel(self.format_event(birth)),
|
||||
2, 3, 1, 2, yoptions=0)
|
||||
|
||||
death = ReportUtils.get_death_or_fallback(self.dbstate.db, person)
|
||||
death = get_death_or_fallback(self.dbstate.db, person)
|
||||
if death:
|
||||
death_title = death.get_type()
|
||||
else:
|
||||
@ -1121,7 +1121,7 @@ class RelationshipView(NavigationView):
|
||||
if not person:
|
||||
return None
|
||||
|
||||
birth = ReportUtils.get_birth_or_fallback(self.dbstate.db, person)
|
||||
birth = get_birth_or_fallback(self.dbstate.db, person)
|
||||
if birth and birth.get_type() != gen.lib.EventType.BIRTH:
|
||||
sdate = DateHandler.get_date(birth)
|
||||
if sdate:
|
||||
@ -1133,7 +1133,7 @@ class RelationshipView(NavigationView):
|
||||
else:
|
||||
bdate = ""
|
||||
|
||||
death = ReportUtils.get_death_or_fallback(self.dbstate.db, person)
|
||||
death = get_death_or_fallback(self.dbstate.db, person)
|
||||
if death and death.get_type() != gen.lib.EventType.DEATH:
|
||||
sdate = DateHandler.get_date(death)
|
||||
if sdate:
|
||||
|
Loading…
Reference in New Issue
Block a user