2008-01-03 19:48:18 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
|
|
|
# Copyright (C) 2000-2007 Donald N. Allingham
|
|
|
|
# Copyright (C) 2007-2008 Brian G. Matherly
|
2009-01-04 23:14:33 +05:30
|
|
|
# Copyright (C) 2009 Douglas S. Blank
|
2008-01-03 19:48:18 +05:30
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
2009-02-16 12:26:49 +05:30
|
|
|
#
|
|
|
|
# $Id$
|
|
|
|
#
|
|
|
|
#
|
2008-01-03 19:48:18 +05:30
|
|
|
"""
|
|
|
|
Display references for any object
|
|
|
|
"""
|
|
|
|
|
|
|
|
from Simple import SimpleAccess, SimpleDoc, SimpleTable
|
|
|
|
from gettext import gettext as _
|
|
|
|
import DateHandler
|
|
|
|
import gen.lib
|
2009-10-08 06:42:51 +05:30
|
|
|
import config
|
2008-01-03 19:48:18 +05:30
|
|
|
|
|
|
|
def run(database, document, date):
|
|
|
|
"""
|
|
|
|
Display people probably alive and their ages on a particular date.
|
|
|
|
"""
|
|
|
|
# setup the simple access functions
|
|
|
|
sdb = SimpleAccess(database)
|
|
|
|
sdoc = SimpleDoc(document)
|
2008-04-18 06:39:32 +05:30
|
|
|
stab = SimpleTable(sdb)
|
2008-01-03 19:48:18 +05:30
|
|
|
if not date.get_valid():
|
|
|
|
sdoc.paragraph("Date is not a valid date.")
|
|
|
|
return
|
|
|
|
# display the title
|
2008-03-02 11:42:05 +05:30
|
|
|
if date.get_day_valid():
|
|
|
|
sdoc.title(_("People probably alive and their ages the %s") %
|
|
|
|
DateHandler.displayer.display(date))
|
|
|
|
else:
|
|
|
|
sdoc.title(_("People probably alive and their ages on %s") %
|
2008-01-03 19:48:18 +05:30
|
|
|
DateHandler.displayer.display(date))
|
|
|
|
stab.columns(_("Person"), _("Age")) # Actual Date makes column unicode
|
2008-04-20 09:38:18 +05:30
|
|
|
matches = 0
|
2008-01-03 19:48:18 +05:30
|
|
|
for person in sdb.all_people():
|
|
|
|
birth_date = None
|
|
|
|
birth_str = ""
|
|
|
|
birth_sort = 0
|
|
|
|
birth_ref = gen.lib.Person.get_birth_ref(person)
|
|
|
|
birth_date = get_event_date_from_ref(database, birth_ref)
|
|
|
|
death_ref = gen.lib.Person.get_death_ref(person)
|
|
|
|
death_date = get_event_date_from_ref(database, death_ref)
|
|
|
|
if birth_date:
|
|
|
|
if (birth_date.get_valid() and birth_date < date and
|
|
|
|
birth_date.get_year() != 0 and
|
2008-06-16 20:31:46 +05:30
|
|
|
((death_date is None) or (death_date > date))):
|
2009-01-04 23:14:33 +05:30
|
|
|
diff_span = (date - birth_date)
|
2008-06-16 20:31:46 +05:30
|
|
|
if ((death_date is not None) or
|
|
|
|
(death_date is None and
|
2010-01-02 02:58:05 +05:30
|
|
|
int(diff_span)/365.0 <= config.get('behavior.max-age-prob-alive'))):
|
2009-01-04 23:14:33 +05:30
|
|
|
birth_str = str(diff_span)
|
|
|
|
birth_sort = int(diff_span)
|
2008-01-03 19:48:18 +05:30
|
|
|
if birth_str != "":
|
|
|
|
stab.row(person, birth_str)
|
2009-01-04 23:14:33 +05:30
|
|
|
stab.row_sort_val(1, diff_span)
|
2008-04-20 09:38:18 +05:30
|
|
|
matches += 1
|
2009-10-16 08:50:07 +05:30
|
|
|
|
2009-02-09 21:57:09 +05:30
|
|
|
sdoc.paragraph(_("\n%d matches.\n") % matches)
|
2008-04-18 06:39:32 +05:30
|
|
|
stab.write(sdoc)
|
2008-01-03 19:48:18 +05:30
|
|
|
sdoc.paragraph("")
|
|
|
|
|
|
|
|
def get_event_date_from_ref(database, ref):
|
|
|
|
date = None
|
|
|
|
if ref:
|
|
|
|
handle = ref.get_reference_handle()
|
|
|
|
if handle:
|
|
|
|
event = database.get_event_from_handle(handle)
|
|
|
|
if event:
|
|
|
|
date = event.get_date_object()
|
|
|
|
return date
|