0002204: Narrative Web report "restrict living" is different than Gramps 2.x

svn: r10786
This commit is contained in:
Brian Matherly 2008-06-05 03:45:14 +00:00
parent 367e3b73a7
commit 0b70388483
5 changed files with 67 additions and 59 deletions

View File

@ -331,7 +331,8 @@ class GedcomWriter(BasicUtils.UpdateCallback):
# If the restrict flag is set, apply the LivingProxyDb # If the restrict flag is set, apply the LivingProxyDb
if option_box.restrict: if option_box.restrict:
self.dbase = gen.proxy.LivingProxyDb( self.dbase = gen.proxy.LivingProxyDb(
self.dbase, gen.proxy.LivingProxyDb.MODE_RESTRICT) self.dbase,
gen.proxy.LivingProxyDb.MODE_INCLUDE_LAST_NAME_ONLY)
# If the filter returned by cfilter is not empty, apply the # If the filter returned by cfilter is not empty, apply the
# FilterProxyDb # FilterProxyDb

View File

@ -88,7 +88,7 @@ def export_data(database, filename, person, option_box, callback=None):
if restrict: if restrict:
database = gen.proxy.LivingProxyDb( database = gen.proxy.LivingProxyDb(
database, gen.proxy.LivingProxyDb.MODE_RESTRICT) database, gen.proxy.LivingProxyDb.MODE_INCLUDE_LAST_NAME_ONLY)
if not option_box.cfilter.is_empty(): if not option_box.cfilter.is_empty():
database = gen.proxy.FilterProxyDb(database, option_box.cfilter) database = gen.proxy.FilterProxyDb(database, option_box.cfilter)

View File

@ -1,7 +1,7 @@
# #
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2007 Brian G. Matherly # Copyright (C) 2007-2008 Brian G. Matherly
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
@ -50,8 +50,9 @@ class LivingProxyDb(ProxyDbBase):
A proxy to a Gramps database. This proxy will act like a Gramps database, A proxy to a Gramps database. This proxy will act like a Gramps database,
but all living people will be hidden from the user. but all living people will be hidden from the user.
""" """
MODE_EXCLUDE = 0 MODE_EXCLUDE_ALL = 0
MODE_RESTRICT = 1 MODE_INCLUDE_LAST_NAME_ONLY = 1
MODE_INCLUDE_FULL_NAME_ONLY = 2
def __init__(self, dbase, mode, current_year=None, years_after_death=0): def __init__(self, dbase, mode, current_year=None, years_after_death=0):
""" """
@ -60,9 +61,11 @@ class LivingProxyDb(ProxyDbBase):
@param dbase: The database to be a proxy for @param dbase: The database to be a proxy for
@type dbase: DbBase @type dbase: DbBase
@param mode: The method for handling living people. @param mode: The method for handling living people.
LivingProxyDb.MODE_EXCLUDE will remove living people altogether. LivingProxyDb.MODE_EXCLUDE_ALL will remove living people altogether.
LivingProxyDb.MODE_RESTRICT will remove all information and change LivingProxyDb.MODE_INCLUDE_LAST_NAME_ONLY will remove all information
their given name to "Living". and change their given name to "Living".
LivingProxyDb.MODE_INCLUDE_FULL_NAME_ONLY will remove all information
but leave the entire name intact.
@type mode: int @type mode: int
@param current_year: The current year to use for living determination. @param current_year: The current year to use for living determination.
If None is supplied, the current year will be found from the system. If None is supplied, the current year will be found from the system.
@ -87,10 +90,10 @@ class LivingProxyDb(ProxyDbBase):
""" """
person = self.db.get_person_from_handle(handle) person = self.db.get_person_from_handle(handle)
if person and self.__is_living(person): if person and self.__is_living(person):
if self.mode == self.MODE_EXCLUDE: if self.mode == self.MODE_EXCLUDE_ALL:
person = None person = None
elif self.mode == self.MODE_RESTRICT: else:
person = _restrict_person(person) person = self.__restrict_person(person)
return person return person
def get_source_from_handle(self, handle): def get_source_from_handle(self, handle):
@ -151,10 +154,10 @@ class LivingProxyDb(ProxyDbBase):
""" """
person = self.db.get_person_from_gramps_id(val) person = self.db.get_person_from_gramps_id(val)
if self.__is_living(person): if self.__is_living(person):
if self.mode == self.MODE_EXCLUDE: if self.mode == self.MODE_EXCLUDE_ALL:
return None return None
else: else:
return _restrict_person(person) return self.__restrict_person(person)
else: else:
return person return person
@ -215,12 +218,12 @@ class LivingProxyDb(ProxyDbBase):
the database. If sort_handles is True, the list is sorted by surnames the database. If sort_handles is True, the list is sorted by surnames
""" """
handles = [] handles = []
if self.mode == self.MODE_EXCLUDE: if self.mode == self.MODE_EXCLUDE_ALL:
for handle in self.db.get_person_handles(sort_handles): for handle in self.db.get_person_handles(sort_handles):
person = self.db.get_person_from_handle(handle) person = self.db.get_person_from_handle(handle)
if not self.__is_living(person): if not self.__is_living(person):
handles.append(handle) handles.append(handle)
elif self.mode == self.MODE_RESTRICT: else:
handles = self.db.get_person_handles(sort_handles) handles = self.db.get_person_handles(sort_handles)
return handles return handles
@ -398,7 +401,7 @@ class LivingProxyDb(ProxyDbBase):
father = self.db.get_person_from_handle(father_handle) father = self.db.get_person_from_handle(father_handle)
if self.__is_living(father): if self.__is_living(father):
parent_is_living = True parent_is_living = True
if self.mode == self.MODE_EXCLUDE: if self.mode == self.MODE_EXCLUDE_ALL:
family.set_father_handle(None) family.set_father_handle(None)
mother_handle = family.get_mother_handle() mother_handle = family.get_mother_handle()
@ -406,14 +409,14 @@ class LivingProxyDb(ProxyDbBase):
mother = self.db.get_person_from_handle(mother_handle) mother = self.db.get_person_from_handle(mother_handle)
if self.__is_living(mother): if self.__is_living(mother):
parent_is_living = True parent_is_living = True
if self.mode == self.MODE_EXCLUDE: if self.mode == self.MODE_EXCLUDE_ALL:
family.set_mother_handle(None) family.set_mother_handle(None)
if parent_is_living: if parent_is_living:
# Clear all events for families where a parent is living. # Clear all events for families where a parent is living.
family.set_event_ref_list([]) family.set_event_ref_list([])
if self.mode == self.MODE_EXCLUDE: if self.mode == self.MODE_EXCLUDE_ALL:
for child_ref in family.get_child_ref_list(): for child_ref in family.get_child_ref_list():
child_handle = child_ref.get_reference_handle() child_handle = child_ref.get_reference_handle()
child = self.db.get_person_from_handle(child_handle) child = self.db.get_person_from_handle(child_handle)
@ -422,33 +425,37 @@ class LivingProxyDb(ProxyDbBase):
return family return family
def _restrict_person(person): def __restrict_person(self, person):
""" """
Remove information from a person and replace the first name with "Living". Remove information from a person and replace the first name with
""" "Living".
new_person = Person() """
new_name = Name() new_person = Person()
old_name = person.get_primary_name() new_name = Name()
old_name = person.get_primary_name()
new_name.set_group_as(old_name.get_group_as()) new_name.set_group_as(old_name.get_group_as())
new_name.set_sort_as(old_name.get_sort_as()) new_name.set_sort_as(old_name.get_sort_as())
new_name.set_display_as(old_name.get_display_as()) new_name.set_display_as(old_name.get_display_as())
new_name.set_surname_prefix(old_name.get_surname_prefix()) new_name.set_surname_prefix(old_name.get_surname_prefix())
new_name.set_type(old_name.get_type()) new_name.set_type(old_name.get_type())
new_name.set_first_name(_(u'Living')) if self.mode == self.MODE_INCLUDE_LAST_NAME_ONLY:
new_name.set_patronymic(old_name.get_patronymic()) new_name.set_first_name(_(u'Living'))
new_name.set_surname(old_name.get_surname()) else: # self.mode == self.MODE_INCLUDE_FULL_NAME_ONLY
new_name.set_privacy(old_name.get_privacy()) new_name.set_first_name(old_name.get_first_name())
new_name.set_patronymic(old_name.get_patronymic())
new_name.set_surname(old_name.get_surname())
new_name.set_privacy(old_name.get_privacy())
new_person.set_primary_name(new_name) new_person.set_primary_name(new_name)
new_person.set_privacy(person.get_privacy()) new_person.set_privacy(person.get_privacy())
new_person.set_gender(person.get_gender()) new_person.set_gender(person.get_gender())
new_person.set_gramps_id(person.get_gramps_id()) new_person.set_gramps_id(person.get_gramps_id())
new_person.set_handle(person.get_handle()) new_person.set_handle(person.get_handle())
new_person.set_family_handle_list(person.get_family_handle_list()) new_person.set_family_handle_list(person.get_family_handle_list())
new_person.set_parent_family_handle_list( new_person.set_parent_family_handle_list(
person.get_parent_family_handle_list() ) person.get_parent_family_handle_list() )
return new_person return new_person

View File

@ -94,6 +94,7 @@ from gen.lib.eventroletype import EventRoleType
# constants # constants
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
_INCLUDE_LIVING_VALUE = 99 # Arbitrary number
_NARRATIVE = "narrative.css" _NARRATIVE = "narrative.css"
_NARRATIVEPRINT = "narrative-print.css" _NARRATIVEPRINT = "narrative-print.css"
_NAME_COL = 3 _NAME_COL = 3
@ -2486,14 +2487,9 @@ class NavWebReport(Report):
livinginfo = self.options['living'] livinginfo = self.options['living']
yearsafterdeath = self.options['yearsafterdeath'] yearsafterdeath = self.options['yearsafterdeath']
if livinginfo == LivingProxyDb.MODE_EXCLUDE: if livinginfo != _INCLUDE_LIVING_VALUE:
self.database = LivingProxyDb(self.database, self.database = LivingProxyDb(self.database,
LivingProxyDb.MODE_EXCLUDE, livinginfo,
None,
yearsafterdeath)
elif livinginfo == LivingProxyDb.MODE_RESTRICT:
self.database = LivingProxyDb(self.database,
LivingProxyDb.MODE_RESTRICT,
None, None,
yearsafterdeath) yearsafterdeath)
@ -2936,7 +2932,6 @@ class NavWebOptions(MenuReportOptions):
""" """
Defines options and provides handling interface. Defines options and provides handling interface.
""" """
__INCLUDE_LIVING_VALUE = 99 # Arbitrary number
def __init__(self, name, dbase): def __init__(self, name, dbase):
self.__db = dbase self.__db = dbase
@ -3101,10 +3096,15 @@ class NavWebOptions(MenuReportOptions):
menu.add_option(category_name, 'incpriv', incpriv) menu.add_option(category_name, 'incpriv', incpriv)
self.__living = EnumeratedListOption(_("Living People"), self.__living = EnumeratedListOption(_("Living People"),
self.__INCLUDE_LIVING_VALUE ) _INCLUDE_LIVING_VALUE )
self.__living.add_item(LivingProxyDb.MODE_EXCLUDE, _("Exclude")) self.__living.add_item(LivingProxyDb.MODE_EXCLUDE_ALL,
self.__living.add_item(LivingProxyDb.MODE_RESTRICT, _("Restrict")) _("Exclude"))
self.__living.add_item(self.__INCLUDE_LIVING_VALUE, _("Include")) self.__living.add_item(LivingProxyDb.MODE_INCLUDE_LAST_NAME_ONLY,
_("Include Last Name Only"))
self.__living.add_item(LivingProxyDb.MODE_INCLUDE_FULL_NAME_ONLY,
_("Include Full Name Only"))
self.__living.add_item(_INCLUDE_LIVING_VALUE,
_("Include"))
self.__living.set_help(_("How to handle living people")) self.__living.set_help(_("How to handle living people"))
menu.add_option(category_name, "living", self.__living) menu.add_option(category_name, "living", self.__living)
self.__living.connect('value-changed', self.__living_changed) self.__living.connect('value-changed', self.__living_changed)
@ -3198,7 +3198,7 @@ class NavWebOptions(MenuReportOptions):
""" """
Handle a change in the living option Handle a change in the living option
""" """
if self.__living.get_value() == self.__INCLUDE_LIVING_VALUE: if self.__living.get_value() == _INCLUDE_LIVING_VALUE:
self.__yearsafterdeath.set_available(False) self.__yearsafterdeath.set_available(False)
else: else:
self.__yearsafterdeath.set_available(True) self.__yearsafterdeath.set_available(True)

View File

@ -78,7 +78,7 @@ def writeData(database, filename, person, option_box, callback=None):
if restrict: if restrict:
database = gen.proxy.LivingProxyDb( database = gen.proxy.LivingProxyDb(
database, gen.proxy.LivingProxyDb.MODE_RESTRICT) database, gen.proxy.LivingProxyDb.MODE_INCLUDE_LAST_NAME_ONLY)
if not option_box.cfilter.is_empty(): if not option_box.cfilter.is_empty():
database = gen.proxy.FilterProxyDb(database, option_box.cfilter) database = gen.proxy.FilterProxyDb(database, option_box.cfilter)