Some cleanup work, and changed get_marriage_event() to use the extended eventtype.py

svn: r13904
This commit is contained in:
Rob G. Healey
2009-12-24 07:55:26 +00:00
parent 864a4692a9
commit c96e7a579a

View File

@ -176,18 +176,15 @@ class WebCalReport(Report):
# styled notes # styled notes
htmlnotetext = self.styled_note(note.get_styledtext(), htmlnotetext = self.styled_note(note.get_styledtext(),
note.get_format()) note.get_format())
text = htmlnotetext or Html('p', note_text) text = htmlnotetext or Html("p", note_text)
# return text of the note to its callers # return text of the note to its callers
return text return text
################################################# #################################################
# # Will produce styled notes for WebCal by using:
# Will produce styled notes for NarrativeWeb by using:
# src/plugins/lib/libhtmlbackend.py # src/plugins/lib/libhtmlbackend.py
#
################################################# #################################################
def styled_note(self, styledtext, format): def styled_note(self, styledtext, format):
""" """
styledtext : assumed a StyledText object to write styledtext : assumed a StyledText object to write
@ -210,7 +207,7 @@ class WebCalReport(Report):
#FIXME: following split should be regex to match \n\s*\n instead? #FIXME: following split should be regex to match \n\s*\n instead?
htmllist += Html('pre', indent=None, inline = True) htmllist += Html('pre', indent=None, inline = True)
for line in markuptext.split('\n\n'): for line in markuptext.split('\n\n'):
htmllist += Html('p') htmllist += Html("p")
for realline in line.split('\n'): for realline in line.split('\n'):
htmllist += realline htmllist += realline
htmllist += Html('br') htmllist += Html('br')
@ -219,12 +216,12 @@ class WebCalReport(Report):
#flowed #flowed
#FIXME: following split should be regex to match \n\s*\n instead? #FIXME: following split should be regex to match \n\s*\n instead?
for line in markuptext.split('\n\n'): for line in markuptext.split('\n\n'):
htmllist += Html('p') htmllist += Html("p")
htmllist += line htmllist += line
return htmllist return htmllist
def copy_file(self, from_fname, to_fname, to_dir=''): def copy_file(self, from_fname, to_fname, to_dir = ''):
""" """
Copy a file from a source to a (report) destination. Copy a file from a source to a (report) destination.
If to_dir is not present and if the target is not an archive, If to_dir is not present and if the target is not an archive,
@ -281,8 +278,7 @@ class WebCalReport(Report):
if month > 0: if month > 0:
try: try:
event_date = Date() event_date = Date(year, month, day)
event_date.set_yr_mon_day(year, month, day)
except ValueError: except ValueError:
event_date = Date.EMPTY event_date = Date.EMPTY
else: else:
@ -303,7 +299,7 @@ class WebCalReport(Report):
# --------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------
def __get_holidays(self, year): def __get_holidays(self, year):
self.progress.set_pass(_('Calculating Holidays for year %d' % year), 365) self.progress.set_pass(_('Calculating Holidays for year %04d' % year), 365)
""" Get the holidays for the specified country and year """ """ Get the holidays for the specified country and year """
holiday_table = libholiday.HolidayTable() holiday_table = libholiday.HolidayTable()
@ -337,14 +333,12 @@ class WebCalReport(Report):
# set imgs to empty # set imgs to empty
imgs = [] imgs = []
# Mainz stylesheet graphics
# will only be used if Mainz is slected as the stylesheet
Mainz_images = ["Web_Mainz_Bkgd.png", "Web_Mainz_Header.png",
"Web_Mainz_Mid.png", "Web_Mainz_MidLight.png"]
if self.css == "Web_Mainz.css": if self.css == "Web_Mainz.css":
# Copy Mainz Style Images
imgs += Mainz_images # Mainz stylesheet graphics
# will only be used if Mainz is slected as the stylesheet
imgs += ["Web_Mainz_Bkgd.png", "Web_Mainz_Header.png",
"Web_Mainz_Mid.png", "Web_Mainz_MidLight.png"]
# Copy GRAMPS favicon # Copy GRAMPS favicon
imgs += ['favicon.ico'] imgs += ['favicon.ico']
@ -423,7 +417,6 @@ class WebCalReport(Report):
meta = Html("meta", attr = _META1) + ( meta = Html("meta", attr = _META1) + (
Html("meta", attr = _META2, indent=False) Html("meta", attr = _META2, indent=False)
) )
head += meta
# links for GRAMPS favicon and stylesheets # links for GRAMPS favicon and stylesheets
links = Html("link", rel='shortcut icon', href=fname1, links = Html("link", rel='shortcut icon', href=fname1,
@ -431,7 +424,6 @@ class WebCalReport(Report):
Html("link",rel="stylesheet", href=fname2, type="text/css", media= "screen", Html("link",rel="stylesheet", href=fname2, type="text/css", media= "screen",
indent = False) indent = False)
) )
head += links
# add printer stylesheet to webcalendar() and one_day() only # add printer stylesheet to webcalendar() and one_day() only
if add_print: if add_print:
@ -439,6 +431,9 @@ class WebCalReport(Report):
links += Html("link",rel="stylesheet", href=fname,type="text/css", media="print", links += Html("link",rel="stylesheet", href=fname,type="text/css", media="print",
indent = False) indent = False)
# add meta tags and links to head section
head += (meta, links)
# replace standard body element with custom one # replace standard body element with custom one
body.attr = 'id="%s"' % body_id body.attr = 'id="%s"' % body_id
@ -462,7 +457,7 @@ class WebCalReport(Report):
if msg is not None: if msg is not None:
header += Html("p", msg, id="CreatorInfo") header += Html("p", msg, id="CreatorInfo")
# return to its caller; either webcalendar(), year_glance(), or one_day() # return to its callers; either webcalendar(), year_glance(), or one_day()
return page, body return page, body
# --------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------
@ -672,7 +667,7 @@ class WebCalReport(Report):
dayclass = get_class_for_daycol(day_col) dayclass = get_class_for_daycol(day_col)
dayname = get_name_for_daycol(day_col) dayname = get_name_for_daycol(day_col)
trow += Html("th", class_ =dayclass, inline = True) + ( trow += Html("th", class_ =dayclass, inline = True) + (
Html('abbr', dayname[0], title=dayname) Html('abbr', dayname[0], title = dayname)
) )
# begin table body # begin table body
@ -711,7 +706,6 @@ class WebCalReport(Report):
specday = __get_previous_month_day(year, month, day_col) if week_row == 0 \ specday = __get_previous_month_day(year, month, day_col) if week_row == 0 \
else __get_next_month_day(year, month, day_col) else __get_next_month_day(year, month, day_col)
specclass = "previous " if week_row == 0 else "Next " specclass = "previous " if week_row == 0 else "Next "
specclass += dayclass specclass += dayclass
@ -755,8 +749,7 @@ class WebCalReport(Report):
# create hyperlink to one_day() # create hyperlink to one_day()
fname_date = full_month_name + '/' + fname_date fname_date = full_month_name + '/' + fname_date
hyper = Html("a", datediv, href=fname_date, inline = True) tcell += Html("a", datediv, href = fname_date, inline = True)
tcell += hyper
# only year_glance() needs this to create the one_day() pages # only year_glance() needs this to create the one_day() pages
self.one_day(event_date, fname_date, day_list) self.one_day(event_date, fname_date, day_list)
@ -934,7 +927,7 @@ class WebCalReport(Report):
body += Html("div", class_ = "content") + ( body += Html("div", class_ = "content") + (
# message line # message line
Html('p', msg, id='description') Html("p", msg, id='description')
) )
for month in range(1, 13): for month in range(1, 13):
@ -978,15 +971,12 @@ class WebCalReport(Report):
month = event_date.get_month() month = event_date.get_month()
# Name the file, and crate it (see code in calendar_build) # Name the file, and crate it (see code in calendar_build)
# chose 'od' as I will be opening and closing more than one file
# at one time
od = self.create_file(fname_date, str(year)) od = self.create_file(fname_date, str(year))
# page title # page title
title = _('One Day Within A Year') title = _('One Day Within A Year')
# create page header # create page header
# body has already been added to oneday already once
oneday, body = self.write_header(nr_up, 'OneDay', title) oneday, body = self.write_header(nr_up, 'OneDay', title)
# create Year Navigation menu # create Year Navigation menu
@ -999,8 +989,7 @@ class WebCalReport(Report):
body += self.month_navigation(nr_up, year, currentsection, True) body += self.month_navigation(nr_up, year, currentsection, True)
# set date display as in user prevferences # set date display as in user prevferences
pg_date = _dd.display(event_date) body += Html("h3", _dd.display(event_date), inline = True)
body += Html("h3", pg_date, inline = True)
# list the events # list the events
ordered = Html("ol") ordered = Html("ol")
@ -1023,7 +1012,7 @@ class WebCalReport(Report):
def build_url_fname_html(self, fname, subdir=None, prefix=None): def build_url_fname_html(self, fname, subdir=None, prefix=None):
return self.build_url_fname(fname, subdir, prefix) + self.ext return self.build_url_fname(fname, subdir, prefix) + self.ext
def build_url_fname(self, fname, subdir, prefix=None): def build_url_fname(self, fname, subdir, prefix = None):
""" """
Create part of the URL given the filename and optionally the subdirectory. Create part of the URL given the filename and optionally the subdirectory.
If the subdirectory is given, then two extra levels of subdirectory are inserted If the subdirectory is given, then two extra levels of subdirectory are inserted
@ -1097,25 +1086,27 @@ class WebCalReport(Report):
This method runs through the data, and collects the relevant dates This method runs through the data, and collects the relevant dates
and text. and text.
""" """
people = self.database.iter_person_handles() db = self.database
self.progress.set_pass(_('Applying Filter...'), self.database.get_number_of_people())
people = self.filter.apply(self.database, people, self.progress) people = db.iter_person_handles()
self.progress.set_pass(_('Applying Filter...'), db.get_number_of_people())
people = self.filter.apply(db, people, self.progress)
self.progress.set_pass(_("Reading database..."), len(people)) self.progress.set_pass(_("Reading database..."), len(people))
for person in imap(self.database.get_person_from_handle, people): for person in imap(db.get_person_from_handle, people):
self.progress.step() self.progress.step()
family_list = person.get_family_handle_list() family_list = person.get_family_handle_list()
birth_ref = person.get_birth_ref() birth_ref = person.get_birth_ref()
birth_date = None birth_date = Date.EMPTY
if birth_ref: if birth_ref:
birth_event = self.database.get_event_from_handle(birth_ref.ref) birth_event = db.get_event_from_handle(birth_ref.ref)
birth_date = birth_event.get_date_object() birth_date = birth_event.get_date_object()
# determine birthday information??? # determine birthday information???
if (self.birthday and birth_date is not None and birth_date.is_valid()): if (self.birthday and birth_date is not Date.EMPTY):
year = birth_date.get_year() year = birth_date.get_year() or this_year
month = birth_date.get_month() or 1 month = birth_date.get_month() or 1
day = birth_date.get_day() or 1 day = birth_date.get_day() or 1
@ -1134,17 +1125,16 @@ class WebCalReport(Report):
fhandle = family_list[0] fhandle = family_list[0]
else: else:
fhandle = family_list[-1] fhandle = family_list[-1]
fam = self.database.get_family_from_handle(fhandle) fam = db.get_family_from_handle(fhandle)
father_handle = fam.get_father_handle() father_handle = fam.get_father_handle()
mother_handle = fam.get_mother_handle() mother_handle = fam.get_mother_handle()
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 = db.get_person_from_handle(father_handle)
if father is not None: if father is not None:
father_name = father.primary_name father_surname = _get_regular_surname(person.gender, father.primary_name)
father_surname = _get_regular_surname(person.gender, father_name)
short_name = self.get_name(person, father_surname) short_name = self.get_name(person, father_surname)
alive = probably_alive(person, self.database, prob_alive_date) alive = probably_alive(person, db, prob_alive_date)
if (self.alive and alive) or not self.alive: if (self.alive and alive) or not self.alive:
# add link to NarrativeWeb # add link to NarrativeWeb
@ -1159,7 +1149,7 @@ class WebCalReport(Report):
# add anniversary if requested # add anniversary if requested
if self.anniv: if self.anniv:
for fhandle in family_list: for fhandle in family_list:
fam = self.database.get_family_from_handle(fhandle) fam = db.get_family_from_handle(fhandle)
father_handle = fam.get_father_handle() father_handle = fam.get_father_handle()
mother_handle = fam.get_mother_handle() mother_handle = fam.get_mother_handle()
if father_handle == person.handle: if father_handle == person.handle:
@ -1167,37 +1157,39 @@ class WebCalReport(Report):
else: else:
continue # with next person if this was the marriage event continue # with next person if this was the marriage event
if spouse_handle: if spouse_handle:
spouse = self.database.get_person_from_handle(spouse_handle) spouse = db.get_person_from_handle(spouse_handle)
if spouse: if spouse:
spouse_name = self.get_name(spouse) spouse_name = self.get_name(spouse)
short_name = self.get_name(person) short_name = self.get_name(person)
# will return a marriage event or False if not married any longer # will return a marriage event or False if not married any longer
marriage_event = get_marriage_event(self.database, fam) marriage_event = get_marriage_event(db, fam)
if marriage_event: if marriage_event:
event_obj = marriage_event.get_date_object() event_date = marriage_event.get_date_object()
year = event_obj.get_year() if event_date is not Date.EMPTY:
month = event_obj.get_month() year = event_date.get_year()
day = event_obj.get_day() month = event_date.get_month()
day = event_date.get_day()
# date to figure if someone is still alive # date to figure if someone is still alive
prob_alive_date = Date(this_year, month, day) prob_alive_date = Date(this_year, month, day)
if event_obj.is_valid():
if self.link_to_narweb: if self.link_to_narweb:
spouse_name = Html("a", spouse_name, spouse_name = Html("a", spouse_name,
href=self.build_url_fname_html(spouse_handle, 'ppl', href = self.build_url_fname_html(spouse_handle, 'ppl',
prefix=self.narweb_prefix)) prefix = self.narweb_prefix))
short_name = Html("a", short_name, short_name = Html("a", short_name,
href=self.build_url_fname_html(person.handle, 'ppl', href = self.build_url_fname_html(person.handle, 'ppl',
prefix=self.narweb_prefix)) prefix = self.narweb_prefix))
text = _('%(spouse)s and %(person)s') % {
'spouse' : spouse_name,
'person' : short_name}
alive1 = probably_alive(person, self.database, prob_alive_date) alive1 = probably_alive(person, db, prob_alive_date)
alive2 = probably_alive(spouse, self.database, prob_alive_date) alive2 = probably_alive(spouse, db, 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):
text = _('%(spouse)s and %(person)s') % {
'spouse' : spouse_name,
'person' : short_name}
self.add_day_item(text, year, month, day, 'Anniversary') self.add_day_item(text, year, month, day, 'Anniversary')
# --------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------
@ -1210,36 +1202,30 @@ class WebCalReport(Report):
root of the directory tree (i.e. to self.html_dir). root of the directory tree (i.e. to self.html_dir).
""" """
# begin calendar footer # begin calendar footer
footer = Html("div", id = 'footer') with Html("div", id = "footer") as footer:
# Display date as user set in preferences # Display date as user set in preferences
msg = _('Generated by <a href="http://gramps-project.org">' msg = _('Generated by <a href="http://gramps-project.org">'
'Gramps</a> on %(date)s') % {'date' : _dd.display(date.Today())} 'Gramps</a> on %(date)s') % {'date' : _dd.display(date.Today())}
p = Html('p', msg, id = 'createdate') footer += Html("p", msg, id = 'createdate')
# add Generated by? to footer copy_nr = self.copy
footer += p text = ''
if copy_nr == 0:
copy_nr = self.copy if self.author:
text = '' text = "&copy; %s %s" % (self.today.get_year(), self.author)
if copy_nr == 0: elif 0 < copy_nr < len(_CC):
if self.author: subdirs = ['..'] * nr_up
# Note. We use '/' here because it is a URL, not a OS dependent pathname
fname = '/'.join(subdirs + ['images'] + ['somerights20.gif'])
text = _CC[copy_nr] % {'gif_fname' : fname}
else:
text = "&copy; %s %s" % (self.today.get_year(), self.author) text = "&copy; %s %s" % (self.today.get_year(), self.author)
elif 0 < copy_nr < len(_CC):
subdirs = ['..'] * nr_up
# Note. We use '/' here because it is a URL, not a OS dependent pathname
fname = '/'.join(subdirs + ['images'] + ['somerights20.gif'])
text = _CC[copy_nr] % {'gif_fname' : fname}
else:
text = "&copy; %s %s" % (self.today.get_year(), self.author)
p = Html('p', text, id = 'copyright') footer += Html("p", text, id = 'copyright')
# add copyright to footer # return footer to its callers
footer += p
# return footer to its caller
return footer return footer
# --------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------
@ -1646,19 +1632,19 @@ def get_short_month_name(month):
def get_marriage_event(db, family): def get_marriage_event(db, family):
""" """
are_married will either be the marriage event or None marriage_event will either be the marriage event or False
""" """
marriage_event = False marriage_event = False
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 [EventType.MARRIAGE, if event.type.is_marriage:
EventType.MARR_ALT]:
marriage_event = event marriage_event = event
elif event.type in [EventType.DIVORCE, elif event.type.is_divorce:
EventType.ANNULMENT, continue
EventType.DIV_FILING]:
marriage_event = False # return the marriage event or False to it caller
return marriage_event return marriage_event
def get_first_day_of_month(year, month): def get_first_day_of_month(year, month):
@ -1718,16 +1704,22 @@ def get_day_list(event_date, holiday_list, bday_anniv_list):
bday_anniv_list = [(t, e, d) for t, e, d in bday_anniv_list bday_anniv_list = [(t, e, d) for t, e, d in bday_anniv_list
if (event_date.get_year() - d.get_year()) >= 0] if (event_date.get_year() - d.get_year()) >= 0]
# a holiday
# zero will force holidays to be first in list
nyears = 0
for text, event, date in holiday_list:
day_list.append((nyears, date, text, event))
# birthday and anniversary list # birthday and anniversary list
for text, event, date in bday_anniv_list: for text, event, date in bday_anniv_list:
# number of years married, ex: 10 # number of years married, ex: 10
# zero will force holidays to be first in list
nyears = (event_date.get_year() - date.get_year()) nyears = (event_date.get_year() - date.get_year())
# number of years for birthday, ex: 10 years # number of years for birthday, ex: 10 years
age_str = event_date - date age_str = event_date - date
age_str.format(precision=1) age_str.format(precision = 1)
# a birthday # a birthday
if event == 'Birthday': if event == 'Birthday':
@ -1752,12 +1744,6 @@ def get_day_list(event_date, holiday_list, bday_anniv_list):
day_list.append((nyears, date, txt_str, event)) day_list.append((nyears, date, txt_str, event))
# a holiday
nyears = 0
for text, event, date in holiday_list:
day_list.append((nyears, date, text, event))
# sort them based on number of years # sort them based on number of years
# holidays will always be on top of event list # holidays will always be on top of event list
day_list.sort() day_list.sort()