2007-08-27 01:45:15 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
2008-06-05 09:15:14 +05:30
|
|
|
#
|
|
|
|
# Copyright (C) 2007-2008 Brian G. Matherly
|
2007-08-27 01:45:15 +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
|
|
|
|
#
|
|
|
|
|
|
|
|
# $Id$
|
|
|
|
|
|
|
|
"""
|
|
|
|
Proxy class for the GRAMPS databases. Filter out all living people.
|
|
|
|
"""
|
|
|
|
|
2008-04-21 05:05:39 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Python libraries
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
|
2007-08-27 01:45:15 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS libraries
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2007-10-03 22:44:26 +05:30
|
|
|
from proxybase import ProxyDbBase
|
2008-02-19 01:37:09 +05:30
|
|
|
from gen.lib import Date, Person, Name
|
2007-08-27 01:45:15 +05:30
|
|
|
from Utils import probably_alive
|
2009-07-29 08:58:05 +05:30
|
|
|
import Config
|
2007-08-27 01:45:15 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# LivingProxyDb
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class LivingProxyDb(ProxyDbBase):
|
|
|
|
"""
|
|
|
|
A proxy to a Gramps database. This proxy will act like a Gramps database,
|
|
|
|
but all living people will be hidden from the user.
|
|
|
|
"""
|
2008-06-05 09:15:14 +05:30
|
|
|
MODE_EXCLUDE_ALL = 0
|
|
|
|
MODE_INCLUDE_LAST_NAME_ONLY = 1
|
|
|
|
MODE_INCLUDE_FULL_NAME_ONLY = 2
|
2007-08-27 01:45:15 +05:30
|
|
|
|
2008-04-21 05:05:39 +05:30
|
|
|
def __init__(self, dbase, mode, current_year=None, years_after_death=0):
|
2007-08-27 01:45:15 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Create a new LivingProxyDb instance.
|
2007-08-27 01:45:15 +05:30
|
|
|
|
2008-04-21 05:05:39 +05:30
|
|
|
@param dbase: The database to be a proxy for
|
|
|
|
@type dbase: DbBase
|
2007-08-27 01:45:15 +05:30
|
|
|
@param mode: The method for handling living people.
|
2008-06-05 09:15:14 +05:30
|
|
|
LivingProxyDb.MODE_EXCLUDE_ALL will remove living people altogether.
|
|
|
|
LivingProxyDb.MODE_INCLUDE_LAST_NAME_ONLY will remove all information
|
2009-07-29 08:58:05 +05:30
|
|
|
and change their given name to "[Living]" or what has been set in
|
|
|
|
Preferences -> Text.
|
2008-06-05 09:15:14 +05:30
|
|
|
LivingProxyDb.MODE_INCLUDE_FULL_NAME_ONLY will remove all information
|
|
|
|
but leave the entire name intact.
|
2007-08-27 01:45:15 +05:30
|
|
|
@type mode: int
|
|
|
|
@param current_year: The current year to use for living determination.
|
|
|
|
If None is supplied, the current year will be found from the system.
|
|
|
|
@type current_year: int or None
|
|
|
|
@param years_after_death: The number of years after a person's death to
|
|
|
|
still consider them living.
|
|
|
|
@type years_after_death: int
|
|
|
|
"""
|
2008-04-21 05:05:39 +05:30
|
|
|
ProxyDbBase.__init__(self, dbase)
|
2007-08-27 01:45:15 +05:30
|
|
|
self.mode = mode
|
2008-06-16 20:31:46 +05:30
|
|
|
if current_year is not None:
|
2007-11-21 20:41:14 +05:30
|
|
|
self.current_date = Date()
|
|
|
|
self.current_date.set_year(current_year)
|
|
|
|
else:
|
|
|
|
self.current_date = None
|
2007-08-27 01:45:15 +05:30
|
|
|
self.years_after_death = years_after_death
|
|
|
|
|
|
|
|
def get_person_from_handle(self, handle):
|
|
|
|
"""
|
|
|
|
Finds a Person in the database from the passed gramps ID.
|
|
|
|
If no such Person exists, None is returned.
|
|
|
|
"""
|
|
|
|
person = self.db.get_person_from_handle(handle)
|
|
|
|
if person and self.__is_living(person):
|
2008-06-05 09:15:14 +05:30
|
|
|
if self.mode == self.MODE_EXCLUDE_ALL:
|
2007-08-27 01:45:15 +05:30
|
|
|
person = None
|
2008-06-05 09:15:14 +05:30
|
|
|
else:
|
|
|
|
person = self.__restrict_person(person)
|
2007-08-27 01:45:15 +05:30
|
|
|
return person
|
|
|
|
|
|
|
|
def get_source_from_handle(self, handle):
|
|
|
|
"""
|
|
|
|
Finds a Source in the database from the passed gramps ID.
|
|
|
|
If no such Source exists, None is returned.
|
|
|
|
"""
|
|
|
|
return self.db.get_source_from_handle(handle)
|
|
|
|
|
|
|
|
def get_object_from_handle(self, handle):
|
|
|
|
"""
|
|
|
|
Finds an Object in the database from the passed gramps ID.
|
|
|
|
If no such Object exists, None is returned.
|
|
|
|
"""
|
|
|
|
return self.db.get_object_from_handle(handle)
|
|
|
|
|
|
|
|
def get_place_from_handle(self, handle):
|
|
|
|
"""
|
|
|
|
Finds a Place in the database from the passed gramps ID.
|
|
|
|
If no such Place exists, None is returned.
|
|
|
|
"""
|
|
|
|
return self.db.get_place_from_handle(handle)
|
|
|
|
|
|
|
|
def get_event_from_handle(self, handle):
|
|
|
|
"""
|
|
|
|
Finds a Event in the database from the passed gramps ID.
|
|
|
|
If no such Event exists, None is returned.
|
|
|
|
"""
|
|
|
|
return self.db.get_event_from_handle(handle)
|
|
|
|
|
|
|
|
def get_family_from_handle(self, handle):
|
|
|
|
"""
|
2007-08-27 02:02:50 +05:30
|
|
|
Finds a Family in the database from the passed handle.
|
2007-08-27 01:45:15 +05:30
|
|
|
If no such Family exists, None is returned.
|
|
|
|
"""
|
|
|
|
family = self.db.get_family_from_handle(handle)
|
2007-08-27 02:02:50 +05:30
|
|
|
family = self.__remove_living_from_family(family)
|
2007-08-27 01:45:15 +05:30
|
|
|
return family
|
|
|
|
|
|
|
|
def get_repository_from_handle(self, handle):
|
|
|
|
"""
|
|
|
|
Finds a Repository in the database from the passed gramps' ID.
|
|
|
|
If no such Repository exists, None is returned.
|
|
|
|
"""
|
|
|
|
return self.db.get_repository_from_handle(handle)
|
|
|
|
|
|
|
|
def get_note_from_handle(self, handle):
|
|
|
|
"""
|
|
|
|
Finds a Note in the database from the passed gramps' ID.
|
|
|
|
If no such Note exists, None is returned.
|
|
|
|
"""
|
|
|
|
return self.db.get_note_from_handle(handle)
|
|
|
|
|
|
|
|
def get_person_from_gramps_id(self, val):
|
|
|
|
"""
|
|
|
|
Finds a Person in the database from the passed GRAMPS ID.
|
|
|
|
If no such Person exists, None is returned.
|
|
|
|
"""
|
|
|
|
person = self.db.get_person_from_gramps_id(val)
|
2009-05-19 14:13:51 +05:30
|
|
|
if person and self.__is_living(person):
|
2008-06-05 09:15:14 +05:30
|
|
|
if self.mode == self.MODE_EXCLUDE_ALL:
|
2007-08-27 01:45:15 +05:30
|
|
|
return None
|
|
|
|
else:
|
2008-06-05 09:15:14 +05:30
|
|
|
return self.__restrict_person(person)
|
2007-08-27 01:45:15 +05:30
|
|
|
else:
|
|
|
|
return person
|
|
|
|
|
|
|
|
def get_family_from_gramps_id(self, val):
|
|
|
|
"""
|
|
|
|
Finds a Family in the database from the passed GRAMPS ID.
|
|
|
|
If no such Family exists, None is returned.
|
|
|
|
"""
|
|
|
|
family = self.db.get_family_from_gramps_id(val)
|
2007-08-27 02:02:50 +05:30
|
|
|
family = self.__remove_living_from_family(family)
|
2007-08-27 01:45:15 +05:30
|
|
|
return family
|
|
|
|
|
|
|
|
def get_event_from_gramps_id(self, val):
|
|
|
|
"""
|
|
|
|
Finds an Event in the database from the passed GRAMPS ID.
|
|
|
|
If no such Event exists, None is returned.
|
|
|
|
"""
|
|
|
|
return self.db.get_event_from_gramps_id(val)
|
|
|
|
|
|
|
|
def get_place_from_gramps_id(self, val):
|
|
|
|
"""
|
|
|
|
Finds a Place in the database from the passed gramps' ID.
|
|
|
|
If no such Place exists, None is returned.
|
|
|
|
"""
|
|
|
|
return self.db.get_place_from_gramps_id(val)
|
|
|
|
|
|
|
|
def get_source_from_gramps_id(self, val):
|
|
|
|
"""
|
|
|
|
Finds a Source in the database from the passed gramps' ID.
|
|
|
|
If no such Source exists, None is returned.
|
|
|
|
"""
|
|
|
|
return self.db.get_source_from_gramps_id(val)
|
|
|
|
|
|
|
|
def get_object_from_gramps_id(self, val):
|
|
|
|
"""
|
|
|
|
Finds a MediaObject in the database from the passed gramps' ID.
|
|
|
|
If no such MediaObject exists, None is returned.
|
|
|
|
"""
|
|
|
|
return self.db.get_object_from_gramps_id(val)
|
|
|
|
|
|
|
|
def get_repository_from_gramps_id(self, val):
|
|
|
|
"""
|
|
|
|
Finds a Repository in the database from the passed gramps' ID.
|
|
|
|
If no such Repository exists, None is returned.
|
|
|
|
"""
|
|
|
|
return self.db.get_repository_from_gramps_id(val)
|
|
|
|
|
|
|
|
def get_note_from_gramps_id(self, val):
|
|
|
|
"""
|
|
|
|
Finds a Note in the database from the passed gramps' ID.
|
|
|
|
If no such Note exists, None is returned.
|
|
|
|
"""
|
|
|
|
return self.db.get_note_from_gramps_id(val)
|
|
|
|
|
2009-07-11 00:54:43 +05:30
|
|
|
def person_predicate(self, handle):
|
2009-07-04 01:53:41 +05:30
|
|
|
if self.mode == self.MODE_EXCLUDE_ALL:
|
2009-07-11 00:54:43 +05:30
|
|
|
person = self.db.get_person_from_handle(handle)
|
|
|
|
if self.__is_living(person):
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
2007-08-27 01:45:15 +05:30
|
|
|
def get_default_person(self):
|
|
|
|
"""returns the default Person of the database"""
|
|
|
|
person_handle = self.db.get_default_handle()
|
|
|
|
return self.get_person_from_handle(person_handle)
|
|
|
|
|
|
|
|
def get_default_handle(self):
|
|
|
|
"""returns the default Person of the database"""
|
|
|
|
person_handle = self.db.get_default_handle()
|
|
|
|
if self.get_person_from_handle(person_handle):
|
|
|
|
return person_handle
|
|
|
|
return None
|
|
|
|
|
|
|
|
def has_person_handle(self, handle):
|
|
|
|
"""
|
|
|
|
returns True if the handle exists in the current Person database.
|
|
|
|
"""
|
|
|
|
if self.get_person_from_handle(handle):
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def has_event_handle(self, handle):
|
|
|
|
"""
|
|
|
|
returns True if the handle exists in the current Event database.
|
|
|
|
"""
|
|
|
|
return self.db.has_event_handle(handle)
|
|
|
|
|
|
|
|
def has_source_handle(self, handle):
|
|
|
|
"""
|
|
|
|
returns True if the handle exists in the current Source database.
|
|
|
|
"""
|
|
|
|
return self.db.has_source_handle(handle)
|
|
|
|
|
|
|
|
def has_place_handle(self, handle):
|
|
|
|
"""
|
|
|
|
returns True if the handle exists in the current Place database.
|
|
|
|
"""
|
|
|
|
return self.db.has_place_handle(handle)
|
|
|
|
|
|
|
|
def has_family_handle(self, handle):
|
|
|
|
"""
|
|
|
|
returns True if the handle exists in the current Family database.
|
|
|
|
"""
|
|
|
|
return self.db.has_family_handle(handle)
|
|
|
|
|
|
|
|
def has_object_handle(self, handle):
|
|
|
|
"""
|
|
|
|
returns True if the handle exists in the current MediaObjectdatabase.
|
|
|
|
"""
|
|
|
|
return self.db.has_object_handle(handle)
|
|
|
|
|
|
|
|
def has_repository_handle(self, handle):
|
|
|
|
"""
|
|
|
|
returns True if the handle exists in the current Repository database.
|
|
|
|
"""
|
|
|
|
return self.db.has_repository_handle(handle)
|
|
|
|
|
|
|
|
def has_note_handle(self, handle):
|
|
|
|
"""
|
|
|
|
returns True if the handle exists in the current Note database.
|
|
|
|
"""
|
|
|
|
return self.db.has_note_handle(handle)
|
|
|
|
|
|
|
|
def find_backlink_handles(self, handle, include_classes=None):
|
|
|
|
"""
|
|
|
|
Find all objects that hold a reference to the object handle.
|
2009-08-10 04:13:43 +05:30
|
|
|
Returns an iterator over a list of (class_name, handle) tuples.
|
2007-08-27 01:45:15 +05:30
|
|
|
|
|
|
|
@param handle: handle of the object to search for.
|
|
|
|
@type handle: database handle
|
|
|
|
@param include_classes: list of class names to include in the results.
|
|
|
|
Default: None means include all classes.
|
|
|
|
@type include_classes: list of class names
|
|
|
|
|
2009-08-10 04:13:43 +05:30
|
|
|
This default implementation does a sequential scan through all
|
2007-08-27 01:45:15 +05:30
|
|
|
the primary object databases and is very slow. Backends can
|
|
|
|
override this method to provide much faster implementations that
|
|
|
|
make use of additional capabilities of the backend.
|
|
|
|
|
|
|
|
Note that this is a generator function, it returns a iterator for
|
|
|
|
use in loops. If you want a list of the results use:
|
|
|
|
|
2009-07-04 01:53:41 +05:30
|
|
|
> result_list = list(find_backlink_handles(handle))
|
2007-08-27 01:45:15 +05:30
|
|
|
"""
|
|
|
|
handle_itr = self.db.find_backlink_handles(handle, include_classes)
|
|
|
|
for (class_name, handle) in handle_itr:
|
|
|
|
if class_name == 'Person':
|
|
|
|
if not self.get_person_from_handle(handle):
|
|
|
|
continue
|
2008-02-24 19:25:55 +05:30
|
|
|
yield (class_name, handle)
|
2007-08-27 01:45:15 +05:30
|
|
|
return
|
|
|
|
|
2008-04-21 05:05:39 +05:30
|
|
|
def __is_living(self, person):
|
|
|
|
"""
|
|
|
|
Check if a person is considered living.
|
|
|
|
Returns True if the person is considered living.
|
|
|
|
Returns False if the person is not considered living.
|
|
|
|
"""
|
2007-08-27 01:45:15 +05:30
|
|
|
return probably_alive( person,
|
|
|
|
self.db,
|
2007-11-21 20:19:50 +05:30
|
|
|
self.current_date,
|
2007-08-27 01:45:15 +05:30
|
|
|
self.years_after_death )
|
|
|
|
|
2008-04-21 05:05:39 +05:30
|
|
|
def __remove_living_from_family(self, family):
|
|
|
|
"""
|
|
|
|
Remove information from a family that pertains to living people.
|
|
|
|
Returns a family instance with information about living people removed.
|
|
|
|
Returns None if family is None.
|
|
|
|
"""
|
|
|
|
if family is None:
|
|
|
|
return None
|
|
|
|
|
2007-08-27 02:02:50 +05:30
|
|
|
parent_is_living = False
|
2007-08-27 01:45:15 +05:30
|
|
|
|
|
|
|
father_handle = family.get_father_handle()
|
|
|
|
if father_handle:
|
|
|
|
father = self.db.get_person_from_handle(father_handle)
|
|
|
|
if self.__is_living(father):
|
2007-08-27 02:02:50 +05:30
|
|
|
parent_is_living = True
|
2008-06-05 09:15:14 +05:30
|
|
|
if self.mode == self.MODE_EXCLUDE_ALL:
|
2007-08-27 02:02:50 +05:30
|
|
|
family.set_father_handle(None)
|
2007-08-27 01:45:15 +05:30
|
|
|
|
|
|
|
mother_handle = family.get_mother_handle()
|
|
|
|
if mother_handle:
|
|
|
|
mother = self.db.get_person_from_handle(mother_handle)
|
|
|
|
if self.__is_living(mother):
|
2007-08-27 02:02:50 +05:30
|
|
|
parent_is_living = True
|
2008-06-05 09:15:14 +05:30
|
|
|
if self.mode == self.MODE_EXCLUDE_ALL:
|
2007-08-27 02:02:50 +05:30
|
|
|
family.set_mother_handle(None)
|
|
|
|
|
|
|
|
if parent_is_living:
|
|
|
|
# Clear all events for families where a parent is living.
|
|
|
|
family.set_event_ref_list([])
|
2007-08-27 01:45:15 +05:30
|
|
|
|
2008-06-05 09:15:14 +05:30
|
|
|
if self.mode == self.MODE_EXCLUDE_ALL:
|
2007-08-27 02:02:50 +05:30
|
|
|
for child_ref in family.get_child_ref_list():
|
|
|
|
child_handle = child_ref.get_reference_handle()
|
|
|
|
child = self.db.get_person_from_handle(child_handle)
|
|
|
|
if self.__is_living(child):
|
|
|
|
family.remove_child_ref(child_ref)
|
2007-08-27 01:45:15 +05:30
|
|
|
|
|
|
|
return family
|
|
|
|
|
2008-06-05 09:15:14 +05:30
|
|
|
def __restrict_person(self, person):
|
|
|
|
"""
|
|
|
|
Remove information from a person and replace the first name with
|
2009-07-29 08:58:05 +05:30
|
|
|
"[Living]" or what has been set in Preferences -> Text.
|
2008-06-05 09:15:14 +05:30
|
|
|
"""
|
|
|
|
new_person = Person()
|
|
|
|
new_name = Name()
|
|
|
|
old_name = person.get_primary_name()
|
|
|
|
|
|
|
|
new_name.set_group_as(old_name.get_group_as())
|
|
|
|
new_name.set_sort_as(old_name.get_sort_as())
|
|
|
|
new_name.set_display_as(old_name.get_display_as())
|
|
|
|
new_name.set_surname_prefix(old_name.get_surname_prefix())
|
|
|
|
new_name.set_type(old_name.get_type())
|
|
|
|
if self.mode == self.MODE_INCLUDE_LAST_NAME_ONLY:
|
2009-07-29 08:58:05 +05:30
|
|
|
new_name.set_first_name(Config.get(Config.PRIVATE_GIVEN_TEXT))
|
2008-06-05 09:15:14 +05:30
|
|
|
else: # self.mode == self.MODE_INCLUDE_FULL_NAME_ONLY
|
|
|
|
new_name.set_first_name(old_name.get_first_name())
|
2009-01-16 06:22:49 +05:30
|
|
|
new_name.set_suffix(old_name.get_suffix())
|
|
|
|
new_name.set_title(old_name.get_title())
|
2008-06-05 09:15:14 +05:30
|
|
|
new_name.set_patronymic(old_name.get_patronymic())
|
|
|
|
new_name.set_surname(old_name.get_surname())
|
|
|
|
new_name.set_privacy(old_name.get_privacy())
|
2007-08-27 01:45:15 +05:30
|
|
|
|
2008-06-05 09:15:14 +05:30
|
|
|
new_person.set_primary_name(new_name)
|
|
|
|
new_person.set_privacy(person.get_privacy())
|
|
|
|
new_person.set_gender(person.get_gender())
|
|
|
|
new_person.set_gramps_id(person.get_gramps_id())
|
|
|
|
new_person.set_handle(person.get_handle())
|
|
|
|
new_person.set_family_handle_list(person.get_family_handle_list())
|
|
|
|
new_person.set_parent_family_handle_list(
|
2007-08-27 01:45:15 +05:30
|
|
|
person.get_parent_family_handle_list() )
|
2008-06-05 09:15:14 +05:30
|
|
|
|
|
|
|
return new_person
|
2007-08-27 01:45:15 +05:30
|
|
|
|
|
|
|
|