More refactoring work on both of these web reports. Fixed and changed get_marital_status to get_marriage_event() as that is what it does anyway. Changes are being given and helped by Gerald Britton.

svn: r12103
This commit is contained in:
Rob G. Healey 2009-02-24 02:52:06 +00:00
parent b8080c5fc6
commit bc081c401c
3 changed files with 88 additions and 106 deletions

View File

@ -19,7 +19,7 @@
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# #
# $Id:WriteGeneWeb.py 9912 2008-01-22 09:17:46Z acraphae $ # $Id$
"Export to GeneWeb." "Export to GeneWeb."

View File

@ -2374,6 +2374,23 @@ class IndividualPage(BasePage):
of.write('   (%s)' % str(rel)) of.write('   (%s)' % str(rel))
of.write('</td>\n') of.write('</td>\n')
def get_sorted_half_step_siblings(self, db, child_handle):
"""
will return the sort information for half and step siblings if birthorder
"""
sort_other_child = []
temp_sibling = db.get_person_from_handle(child_handle)
birth_ref = temp_sibling.get_birth_ref()
birth_date = None
if birth_ref:
birth_event = db.get_event_from_handle(birth_ref.ref)
birth_date = birth_event.get_date_object()
if birth_date is not None and birth_date.is_valid():
ssort_other_child.append((birth_date, child_handle))
return sort_other_child
def display_ind_parents(self, of): def display_ind_parents(self, of):
parent_list = self.person.get_parent_family_handle_list() parent_list = self.person.get_parent_family_handle_list()
@ -2437,7 +2454,7 @@ class IndividualPage(BasePage):
# Also try to identify half-siblings # Also try to identify half-siblings
half_siblings = set() half_siblings = set()
sort_half_sibs = [] self.sort_half_sibs = []
birthorder = self.report.options['birthorder'] birthorder = self.report.options['birthorder']
# if we have a known father... # if we have a known father...
@ -2457,17 +2474,10 @@ class IndividualPage(BasePage):
# we have a new step/half sibling # we have a new step/half sibling
half_siblings.add(half_child_handle) half_siblings.add(half_child_handle)
# if sort siblings or not? # if sort siblings?
if birthorder: if birthorder:
half_sib = db.get_person_from_handle(half_child_handle) sort_half_sibs = \
birth_ref = half_sib.get_birth_ref() self.get_sort_half_step_sibs(db, half_child_handle)
birth_date = None
if birth_ref:
birth_event = db.get_event_from_handle(birth_ref.ref)
birth_date = birth_event.get_date_object()
if birth_date != None and birth_date.is_valid():
sort_half_sibs.append((birth_date, half_child_handle))
# do the same thing with the mother (see "father" just above): # do the same thing with the mother (see "father" just above):
if mother_handle and showallsiblings: if mother_handle and showallsiblings:
@ -2483,25 +2493,17 @@ class IndividualPage(BasePage):
# sort siblings or not? # sort siblings or not?
if birthorder: if birthorder:
half_sib = db.get_person_from_handle(half_child_handle) sort_half_sibs = \
birth_ref = half_sib.get_birth_ref() self.get_sort_half_step_sibs(db, half_child_handle)
birth_date = None
if birth_ref:
birth_event = db.get_event_from_handle(birth_ref.ref)
birth_date = birth_event.get_date_object()
if birth_date != None and birth_date.is_valid():
sort_half_sibs.append((birth_date, half_child_handle))
# now that we have all of the half-siblings, print them out # now that we have all of the half-siblings, print them out
if len(half_siblings) > 0 or len(sort_half_sibs) > 0: if len(half_siblings) or len(sort_half_sibs):
of.write('\t\t\t<tr>\n') of.write('\t\t\t<tr>\n')
of.write('\t\t\t\t<td class="ColumnAttribute">%s</td>\n' % _("Half Siblings")) of.write('\t\t\t\t<td class="ColumnAttribute">%s</td>\n' % _("Half Siblings"))
of.write('\t\t\t\t<td class="ColumnValue">\n') of.write('\t\t\t\t<td class="ColumnValue">\n')
of.write('\t\t\t\t\t<ol>\n') of.write('\t\t\t\t\t<ol>\n')
if birthorder: if birthorder:
sort_half_sibs.sort() sort_half_sibs.sort()
for date, handle in sort_half_sibs: for date, handle in sort_half_sibs:
self.display_child_link(of, handle) self.display_child_link(of, handle)
else: else:
@ -2513,7 +2515,7 @@ class IndividualPage(BasePage):
# get step-siblings # get step-siblings
step_siblings = set() step_siblings = set()
step_kids = [] sort_step_sibs = []
if showallsiblings: if showallsiblings:
# to find the step-siblings, we need to identify # to find the step-siblings, we need to identify
@ -2579,27 +2581,21 @@ class IndividualPage(BasePage):
# we have a new step sibling # we have a new step sibling
step_siblings.add(step_child_handle) step_siblings.add(step_child_handle)
# sort siblings or not? # if sort siblings?
if birthorder: if birthorder:
step_sib = db.get_person_from_handle(step_child_handle) sort_step_sibs = \
birth_ref = step_sib.get_birth_ref() self.get_sort_half_step_sibs(db, step_child_handle)
birth_date = None
if birth_ref:
birth_event = db.get_event_from_handle(birth_ref.ref)
birth_date = birth_event.get_date_object()
if birth_date != None and birth_date.is_valid():
step_kids.append((birth_date, step_child_handle))
# now that we have all of the step-siblings, print them out # now that we have all of the step-siblings, print them out
if len(step_siblings) > 0 or len(step_kids) > 0: if len(step_siblings) or len(sort_step_sibs):
of.write('\t\t\t<tr>\n') of.write('\t\t\t<tr>\n')
of.write('\t\t\t\t<td class="ColumnAttribute">%s</td>\n' % _("Step Siblings")) of.write('\t\t\t\t<td class="ColumnAttribute">%s</td>\n' % _("Step Siblings"))
of.write('\t\t\t\t<td class="ColumnValue">\n') of.write('\t\t\t\t<td class="ColumnValue">\n')
of.write('\t\t\t\t\t<ol>\n') of.write('\t\t\t\t\t<ol>\n')
if birthorder: if birthorder:
for date, handle in step_kids: sort_step_sibs.sort()
for date, handle in sort_step_sibs:
self.display_child_link(of, handle) self.display_child_link(of, handle)
else: else:
for child_handle in step_siblings: for child_handle in step_siblings:

View File

@ -27,11 +27,6 @@
Web Calendar generator. Web Calendar generator.
Refactoring. This is an ongoing job until this plugin is in a better shape. Refactoring. This is an ongoing job until this plugin is in a better shape.
TODO list:
- progress bar, rethink its usage
- in year navigation, use month in link, or 'fullyear'
- daylight saving not just for USA and Europe
- move the close_file() from one_day() to caller
""" """
#------------------------------------------------------------------------ #------------------------------------------------------------------------
@ -39,12 +34,8 @@ TODO list:
# python modules # python modules
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
import os import os, codecs, shutil
import time import time, datetime, calendar
import datetime
import calendar
import codecs
import shutil
from gettext import gettext as _ from gettext import gettext as _
from gettext import ngettext from gettext import ngettext
@ -91,7 +82,7 @@ _WEBMID = "Web_Mainz_Mid.png"
_WEBMIDLIGHT = "Web_Mainz_MidLight.png" _WEBMIDLIGHT = "Web_Mainz_MidLight.png"
# This information defines the list of styles in the Web calendar # This information defines the list of styles in the Web calendar
# options dialog as well as the location of the corresponding SCREEN # options dialog as well as the location of the corresponding
# stylesheets. # stylesheets.
_CSS_FILES = [ _CSS_FILES = [
# First is used as default selection. # First is used as default selection.
@ -185,48 +176,49 @@ class WebCalReport(Report):
def __init__(self, database, options): def __init__(self, database, options):
Report.__init__(self, database, options) Report.__init__(self, database, options)
menu = options.menu menu = options.menu
mgobn = menu.get_option_by_name
self.database = database self.database = database
self.options = options self.options = options
self.html_dir = menu.get_option_by_name('target').get_value() self.html_dir = mgobn('target').get_value()
self.title_text = menu.get_option_by_name('title').get_value() self.title_text = mgobn('title').get_value()
filter_option = menu.get_option_by_name('filter') filter_option = mgobn('filter')
self.filter = filter_option.get_filter() self.filter = filter_option.get_filter()
self.ext = menu.get_option_by_name('ext').get_value() self.ext = mgobn('ext').get_value()
self.copy = menu.get_option_by_name('cright').get_value() self.copy = mgobn('cright').get_value()
self.encoding = menu.get_option_by_name('encoding').get_value() self.encoding = mgobn('encoding').get_value()
self.css = menu.get_option_by_name('css').get_value() self.css = mgobn('css').get_value()
self.country = menu.get_option_by_name('country').get_value() self.country = mgobn('country').get_value()
self.start_dow = menu.get_option_by_name('start_dow').get_value() self.start_dow = mgobn('start_dow').get_value()
self.multiyear = menu.get_option_by_name('multiyear').get_value() self.multiyear = mgobn('multiyear').get_value()
self.start_year = menu.get_option_by_name('start_year').get_value() self.start_year = mgobn('start_year').get_value()
self.end_year = menu.get_option_by_name('end_year').get_value() self.end_year = mgobn('end_year').get_value()
self.fullyear = menu.get_option_by_name('fullyear').get_value() self.fullyear = mgobn('fullyear').get_value()
self.maiden_name = menu.get_option_by_name('maiden_name').get_value() self.maiden_name = mgobn('maiden_name').get_value()
self.alive = menu.get_option_by_name('alive').get_value() self.alive = mgobn('alive').get_value()
self.birthday = menu.get_option_by_name('birthdays').get_value() self.birthday = mgobn('birthdays').get_value()
self.anniv = menu.get_option_by_name('anniversaries').get_value() self.anniv = mgobn('anniversaries').get_value()
self.home_link = menu.get_option_by_name('home_link').get_value().strip() self.home_link = mgobn('home_link').get_value().strip()
self.month_notes = [menu.get_option_by_name('note_jan').get_value(), self.month_notes = [mgobn('note_jan').get_value(),
menu.get_option_by_name('note_feb').get_value(), mgobn('note_feb').get_value(),
menu.get_option_by_name('note_mar').get_value(), mgobn('note_mar').get_value(),
menu.get_option_by_name('note_apr').get_value(), mgobn('note_apr').get_value(),
menu.get_option_by_name('note_may').get_value(), mgobn('note_may').get_value(),
menu.get_option_by_name('note_jun').get_value(), mgobn('note_jun').get_value(),
menu.get_option_by_name('note_jul').get_value(), mgobn('note_jul').get_value(),
menu.get_option_by_name('note_aug').get_value(), mgobn('note_aug').get_value(),
menu.get_option_by_name('note_sep').get_value(), mgobn('note_sep').get_value(),
menu.get_option_by_name('note_oct').get_value(), mgobn('note_oct').get_value(),
menu.get_option_by_name('note_nov').get_value(), mgobn('note_nov').get_value(),
menu.get_option_by_name('note_dec').get_value()] mgobn('note_dec').get_value()]
# identify researcher name and e-mail address # identify researcher name and e-mail address
# as Narrated WebSite already does # as Narrated WebSite already does
@ -1044,7 +1036,7 @@ class WebCalReport(Report):
if mother_handle == person_handle: if mother_handle == person_handle:
if father_handle: if father_handle:
father = self.database.get_person_from_handle(father_handle) father = self.database.get_person_from_handle(father_handle)
if father != None: if father is not None:
father_name = father.primary_name father_name = father.primary_name
father_surname = _get_regular_surname(sex, father_name) father_surname = _get_regular_surname(sex, father_name)
short_name = _get_short_name(person, father_surname) short_name = _get_short_name(person, father_surname)
@ -1069,26 +1061,24 @@ class WebCalReport(Report):
spouse_name = _get_short_name(spouse) spouse_name = _get_short_name(spouse)
short_name = _get_short_name(person) short_name = _get_short_name(person)
are_married = get_marital_status(self.database, fam) are_married = get_marriage_event(self.database, fam)
if are_married is not None: if are_married is not None:
for event_ref in fam.get_event_ref_list(): event_obj = are_married.get_date_object()
event = self.database.get_event_from_handle(event_ref.ref) year = event_obj.get_year()
event_obj = event.get_date_object() month = event_obj.get_month()
year = event_obj.get_year() day = event_obj.get_day()
month = event_obj.get_month()
day = event_obj.get_day()
prob_alive_date = gen.lib.Date(this_year, month, day) prob_alive_date = gen.lib.Date(this_year, month, day)
if event_obj.is_valid(): if event_obj.is_valid():
text = _('%(spouse)s and %(person)s') % { text = _('%(spouse)s and %(person)s') % {
'spouse' : spouse_name, 'spouse' : spouse_name,
'person' : short_name} 'person' : short_name}
alive1 = probably_alive(person, self.database, prob_alive_date) alive1 = probably_alive(person, self.database, prob_alive_date)
alive2 = probably_alive(spouse, self.database, prob_alive_date) alive2 = probably_alive(spouse, self.database, prob_alive_date)
if ((self.alive and alive1 and alive2) or not self.alive): if ((self.alive and alive1 and alive2) or not self.alive):
self.add_day_item(text, year, month, day, 'Anniversary') self.add_day_item(text, year, month, day, 'Anniversary')
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
@ -1469,7 +1459,7 @@ def get_day_list(event_date, holiday_list, bday_anniv_list):
if event == 'Birthday': if event == 'Birthday':
txt_str = _(text + ', <em>' txt_str = _(text + ', <em>'
+ ('birth' if nyears == 0 else '%s old' % str(age_str)) + ('%s old' % str(age_str) if nyears else 'birth')
+ '</em>') + '</em>')
# an anniversary # an anniversary
@ -1495,25 +1485,21 @@ def get_day_list(event_date, holiday_list, bday_anniv_list):
return day_list return day_list
def get_marital_status(db, family): def get_marriage_event(db, family):
""" """
Returns the marital status of two people, a couple are_married will either be the marriage event or None
are_married will either be the marriage event
or None if not married anymore
""" """
are_married = None
for event_ref in family.get_event_ref_list(): for event_ref in family.get_event_ref_list():
event = db.get_event_from_handle(event_ref.ref) event = db.get_event_from_handle(event_ref.ref)
if event.type in [gen.lib.EventType.MARRIAGE, if event.type in [gen.lib.EventType.MARRIAGE,
gen.lib.EventType.MARR_ALT]: gen.lib.EventType.MARR_ALT]:
are_married = event return event
elif event.type in [gen.lib.EventType.DIVORCE, elif event.type in [gen.lib.EventType.DIVORCE,
gen.lib.EventType.ANNULMENT, gen.lib.EventType.ANNULMENT,
gen.lib.EventType.DIV_FILING]: gen.lib.EventType.DIV_FILING]:
are_married = None return None
return are_married return None
def get_first_day_of_month(year, month): def get_first_day_of_month(year, month):
""" """