2007-12-29 10:12:37 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
|
|
|
# Copyright (C) 2000-2007 Donald N. Allingham
|
2008-05-19 00:54:28 +05:30
|
|
|
# Copyright (C) 2007-2008 Brian G. Matherly
|
2009-01-06 10:26:09 +05:30
|
|
|
# Copyright (C) 2009 Douglas S. Blank
|
2007-12-29 10:12:37 +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-01-06 10:26:09 +05:30
|
|
|
Display a people who have a person's same surname or given name
|
2007-12-29 10:12:37 +05:30
|
|
|
"""
|
|
|
|
|
|
|
|
from Simple import SimpleAccess, SimpleDoc, SimpleTable
|
|
|
|
from gettext import gettext as _
|
2009-02-02 22:43:02 +05:30
|
|
|
from gettext import ngettext
|
2008-10-02 09:32:10 +05:30
|
|
|
from gen.plug import PluginManager
|
2009-01-06 10:26:09 +05:30
|
|
|
import gen.lib
|
|
|
|
from ReportBase import CATEGORY_QR_PERSON, CATEGORY_QR_MISC
|
2008-01-16 00:34:46 +05:30
|
|
|
from Filters.Rules import Rule
|
2008-02-19 01:37:09 +05:30
|
|
|
from Filters import GenericFilterFactory
|
2007-12-29 10:12:37 +05:30
|
|
|
|
2008-01-16 00:34:46 +05:30
|
|
|
class IncompleteSurname(Rule):
|
|
|
|
"""People with incomplete surnames"""
|
|
|
|
name = _('People with incomplete surnames')
|
|
|
|
description = _("Matches people with lastname missing")
|
|
|
|
category = _('General filters')
|
|
|
|
def apply(self,db,person):
|
|
|
|
for name in [person.get_primary_name()] + person.get_alternate_names():
|
2008-03-06 18:03:02 +05:30
|
|
|
if name.get_group_name() == "":
|
2008-01-16 00:34:46 +05:30
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2008-01-18 23:58:28 +05:30
|
|
|
class SameSurname(Rule):
|
|
|
|
"""People with same surname"""
|
|
|
|
labels = [_('Substring:')]
|
|
|
|
name = _('People matching the <name>')
|
|
|
|
description = _("Matches people with same lastname")
|
|
|
|
category = _('General filters')
|
|
|
|
def apply(self,db,person):
|
|
|
|
src = self.list[0].upper()
|
|
|
|
for name in [person.get_primary_name()] + person.get_alternate_names():
|
|
|
|
if name.surname and name.surname.upper() == src.upper():
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2009-01-06 10:26:09 +05:30
|
|
|
class SameGiven(Rule):
|
|
|
|
"""People with same given name"""
|
|
|
|
labels = [_('Substring:')]
|
|
|
|
name = _('People matching the <given>')
|
|
|
|
description = _("Matches people with same given name")
|
|
|
|
category = _('General filters')
|
|
|
|
def apply(self,db,person):
|
|
|
|
src = self.list[0].upper()
|
|
|
|
for name in [person.get_primary_name()] + person.get_alternate_names():
|
|
|
|
if name.first_name:
|
|
|
|
if " " in name.first_name.strip():
|
|
|
|
for name in name.first_name.upper().strip().split():
|
|
|
|
if name == src.upper():
|
|
|
|
return True
|
|
|
|
elif name.first_name.upper() == src.upper():
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
class IncompleteGiven(Rule):
|
|
|
|
"""People with incomplete given names"""
|
|
|
|
name = _('People with incomplete given names')
|
|
|
|
description = _("Matches people with firstname missing")
|
|
|
|
category = _('General filters')
|
|
|
|
def apply(self,db,person):
|
|
|
|
for name in [person.get_primary_name()] + person.get_alternate_names():
|
|
|
|
if name.get_first_name() == "":
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2007-12-29 10:12:37 +05:30
|
|
|
def run(database, document, person):
|
|
|
|
"""
|
|
|
|
Loops through the families that the person is a child in, and display
|
|
|
|
the information about the other children.
|
|
|
|
"""
|
|
|
|
# setup the simple access functions
|
|
|
|
sdb = SimpleAccess(database)
|
|
|
|
sdoc = SimpleDoc(document)
|
2008-04-18 06:39:32 +05:30
|
|
|
stab = SimpleTable(sdb)
|
2009-01-06 10:26:09 +05:30
|
|
|
if isinstance(person, gen.lib.Person):
|
2008-03-05 09:31:27 +05:30
|
|
|
surname = sdb.surname(person)
|
2008-03-06 18:03:02 +05:30
|
|
|
rsurname = person.get_primary_name().get_group_name()
|
2009-01-06 10:26:09 +05:30
|
|
|
else:
|
|
|
|
surname = person
|
|
|
|
rsurname = person
|
2007-12-29 10:12:37 +05:30
|
|
|
# display the title
|
2008-03-05 09:31:27 +05:30
|
|
|
sdoc.title(_("People with the surname '%s'") % surname)
|
2007-12-29 10:12:37 +05:30
|
|
|
sdoc.paragraph("")
|
|
|
|
stab.columns(_("Person"), _("Birth Date"), _("Name type"))
|
|
|
|
filter = GenericFilterFactory('Person')()
|
2008-03-05 09:31:27 +05:30
|
|
|
if rsurname != '':
|
|
|
|
rule = SameSurname([rsurname])
|
2008-01-16 00:34:46 +05:30
|
|
|
else:
|
|
|
|
rule = IncompleteSurname([])
|
2007-12-29 10:12:37 +05:30
|
|
|
filter.add_rule(rule)
|
|
|
|
people = filter.apply(database,
|
|
|
|
database.get_person_handles(sort_handles=False))
|
|
|
|
matches = 0
|
|
|
|
for person_handle in people:
|
|
|
|
person = database.get_person_from_handle(person_handle)
|
2008-01-16 07:55:40 +05:30
|
|
|
stab.row(person, sdb.birth_date_obj(person),
|
|
|
|
str(person.get_primary_name().get_type()))
|
2007-12-29 10:12:37 +05:30
|
|
|
matches += 1
|
2009-02-02 22:43:02 +05:30
|
|
|
sdoc.paragraph(ngettext("There is %d person with a matching name, or alternate name.\n"
|
|
|
|
,
|
|
|
|
"There are %d people with a matching name, or alternate name.\n"
|
|
|
|
, matches) % matches)
|
2008-04-18 06:39:32 +05:30
|
|
|
stab.write(sdoc)
|
2009-01-06 10:26:09 +05:30
|
|
|
|
|
|
|
def run_given(database, document, person):
|
|
|
|
"""
|
|
|
|
Loops through the families that the person is a child in, and display
|
|
|
|
the information about the other children.
|
|
|
|
"""
|
|
|
|
# setup the simple access functions
|
|
|
|
sdb = SimpleAccess(database)
|
|
|
|
sdoc = SimpleDoc(document)
|
|
|
|
stab = SimpleTable(sdb)
|
|
|
|
if isinstance(person, gen.lib.Person):
|
|
|
|
rgivenname = person.get_primary_name().get_first_name()
|
|
|
|
else:
|
|
|
|
rgivenname = person
|
|
|
|
if " " in rgivenname.strip():
|
|
|
|
rgivenname, second = rgivenname.strip().split(" ", 1)
|
|
|
|
# display the title
|
|
|
|
sdoc.title(_("People with the given name '%s'") % rgivenname)
|
|
|
|
sdoc.paragraph("")
|
|
|
|
stab.columns(_("Person"), _("Birth Date"), _("Name type"))
|
|
|
|
filter = GenericFilterFactory('Person')()
|
|
|
|
if rgivenname != '':
|
|
|
|
rule = SameGiven([rgivenname])
|
|
|
|
else:
|
|
|
|
rule = IncompleteGiven([])
|
|
|
|
filter.add_rule(rule)
|
|
|
|
people = filter.apply(database,
|
|
|
|
database.get_person_handles(sort_handles=False))
|
|
|
|
matches = 0
|
|
|
|
for person_handle in people:
|
|
|
|
person = database.get_person_from_handle(person_handle)
|
|
|
|
stab.row(person, sdb.birth_date_obj(person),
|
|
|
|
str(person.get_primary_name().get_type()))
|
|
|
|
matches += 1
|
2009-02-02 22:43:02 +05:30
|
|
|
sdoc.paragraph(ngettext("There is %d person with a matching name, or alternate name.\n"
|
|
|
|
,
|
|
|
|
"There are %d people with a matching name, or alternate name.\n"
|
|
|
|
, matches) % matches)
|
2009-01-06 10:26:09 +05:30
|
|
|
stab.write(sdoc)
|
|
|
|
|
2007-12-29 10:12:37 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2008-05-19 00:54:28 +05:30
|
|
|
pmgr = PluginManager.get_instance()
|
|
|
|
pmgr.register_quick_report(
|
2007-12-30 09:16:39 +05:30
|
|
|
name = 'samesurnames',
|
2007-12-29 10:12:37 +05:30
|
|
|
category = CATEGORY_QR_PERSON,
|
|
|
|
run_func = run,
|
|
|
|
translated_name = _("Same Surnames"),
|
|
|
|
status = _("Stable"),
|
|
|
|
description= _("Display people with the same surname as a person."),
|
|
|
|
author_name="Douglas S. Blank",
|
|
|
|
author_email="dblank@cs.brynmawr.edu"
|
|
|
|
)
|
2009-01-06 10:26:09 +05:30
|
|
|
|
|
|
|
pmgr.register_quick_report(
|
|
|
|
name = 'samegivens',
|
|
|
|
category = CATEGORY_QR_PERSON, # to run with a person object
|
|
|
|
run_func = run_given,
|
|
|
|
translated_name = _("Same Given Names"),
|
|
|
|
status = _("Stable"),
|
|
|
|
description= _("Display people with the same given name as a person."),
|
|
|
|
author_name="Douglas S. Blank",
|
|
|
|
author_email="dblank@cs.brynmawr.edu"
|
|
|
|
)
|
|
|
|
|
|
|
|
pmgr.register_quick_report(
|
|
|
|
name = 'samegivens_misc',
|
2009-01-10 21:55:31 +05:30
|
|
|
category = CATEGORY_QR_MISC, # to run with a given name string
|
2009-01-06 10:26:09 +05:30
|
|
|
run_func = run_given,
|
|
|
|
translated_name = _("Same Given Names"),
|
|
|
|
status = _("Stable"),
|
|
|
|
description= _("Display people with the same given name as a person."),
|
|
|
|
author_name="Douglas S. Blank",
|
|
|
|
author_email="dblank@cs.brynmawr.edu"
|
|
|
|
)
|