Merge pull request #802 from SNoiraud:webcal

This commit is contained in:
Nick Hall
2019-05-12 16:13:15 +01:00

View File

@@ -32,7 +32,8 @@ Web Calendar generator.
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# python modules # python modules
#------------------------------------------------------------------------ #------------------------------------------------------------------------
import os, shutil import os
import shutil
import datetime import datetime
import time import time
import calendar # Python module import calendar # Python module
@@ -41,15 +42,14 @@ import calendar # Python module
# Set up logging # Set up logging
#------------------------------------------------------------------------ #------------------------------------------------------------------------
import logging import logging
_LOG = logging.getLogger(".WebPage")
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# Gramps module # Gramps module
#------------------------------------------------------------------------ #------------------------------------------------------------------------
from gramps.gen.const import GRAMPS_LOCALE as glocale from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.sgettext
from gramps.gen.lib import Date, Name, NameType, Person from gramps.gen.lib import Date, Name, NameType, Person
from gramps.gen.lib.date import Today from gramps.gen.lib.date import Today
from gramps.plugins.webreport.common import html_escape
from gramps.gen.const import PROGRAM_NAME, URL_HOMEPAGE from gramps.gen.const import PROGRAM_NAME, URL_HOMEPAGE
from gramps.version import VERSION from gramps.version import VERSION
from gramps.gen.constfunc import win from gramps.gen.constfunc import win
@@ -63,6 +63,7 @@ from gramps.gen.plug.menu import (BooleanOption, NumberOption, StringOption,
PersonOption, DestinationOption, NoteOption) PersonOption, DestinationOption, NoteOption)
from gramps.gen.utils.config import get_researcher from gramps.gen.utils.config import get_researcher
from gramps.gen.utils.alive import probably_alive from gramps.gen.utils.alive import probably_alive
from gramps.gen.utils.db import get_death_or_fallback
from gramps.gen.datehandler import displayer as _dd from gramps.gen.datehandler import displayer as _dd
from gramps.gen.display.name import displayer as _nd from gramps.gen.display.name import displayer as _nd
@@ -80,7 +81,11 @@ from gramps.plugins.lib.libhtmlbackend import HtmlBackend
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# constants # constants
#------------------------------------------------------------------------ #------------------------------------------------------------------------
_ = glocale.translation.sgettext
_LOG = logging.getLogger(".WebPage")
# full clear line for proper styling # full clear line for proper styling
FULLCLEAR = Html("div", class_="fullclear", inline=True) FULLCLEAR = Html("div", class_="fullclear", inline=True)
# Web page filename extensions # Web page filename extensions
@@ -93,18 +98,6 @@ _CALENDARPRINT = 'calendar-print.css'
PLUGMAN = GuiPluginManager.get_instance() PLUGMAN = GuiPluginManager.get_instance()
CSS = PLUGMAN.process_plugin_data('WEBSTUFF') CSS = PLUGMAN.process_plugin_data('WEBSTUFF')
def _escape(string):
""" replace character in text that html shows correctly
special characters: & < and >
"""
string = string.replace('&', '&amp;') # must be the first
string = string.replace('<', '&lt;')
string = string.replace('>', '&gt;')
return string
# pylint: disable=unused-variable
# pylint: disable=unused-argument
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
# WebCalReport # WebCalReport
@@ -147,6 +140,7 @@ class WebCalReport(Report):
self.multiyear = mgobn('multiyear') self.multiyear = mgobn('multiyear')
self.start_year = mgobn('start_year') self.start_year = mgobn('start_year')
self.end_year = mgobn('end_year') self.end_year = mgobn('end_year')
self.after_year = mgobn('after_year')
if not self.multiyear: if not self.multiyear:
self.end_year = self.start_year self.end_year = self.start_year
if self.end_year < self.start_year: if self.end_year < self.start_year:
@@ -157,12 +151,14 @@ class WebCalReport(Report):
self.alive = mgobn('alive') self.alive = mgobn('alive')
self.birthday = mgobn('birthdays') self.birthday = mgobn('birthdays')
self.anniv = mgobn('anniversaries') self.anniv = mgobn('anniversaries')
self.death_anniv = mgobn('death_anniv')
self.home_link = mgobn('home_link') self.home_link = mgobn('home_link')
self.event_list = [] self.event_list = []
self.month_notes = [mgobn('note_' + month) self.month_notes = [mgobn('note_' + month)
for month in ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', for month in ['jan', 'feb', 'mar', 'apr', 'may',
'aug', 'sep', 'oct', 'nov', 'dec']] 'jun', 'jul', 'aug', 'sep', 'oct',
'nov', 'dec']]
self.encoding = mgobn('encoding') self.encoding = mgobn('encoding')
self.fullyear = True self.fullyear = True
@@ -290,19 +286,22 @@ class WebCalReport(Report):
text -- line to be added text -- line to be added
year, month, day -- date to add the text to year, month, day -- date to add the text to
event -- one of 'BirthDay', 'Anniversary', or 'Holiday' event -- one of 'BirthDay', 'Anniversary', 'Death' or 'Holiday'
age_at_death -- The age in text. ie : 68 years, 6 months age_at_death -- The age in text. ie : 68 years, 6 months
dead_event_date -- The date of the event used to calculate dead_event_date -- The date of the event used to calculate
the age_at_death the age_at_death
""" """
if year <= self.after_year:
return
# This may happen for certain "about" dates. # This may happen for certain "about" dates.
# Use first day of the month # Use first day of the month
if day == 0: if day == 0:
day = 1 day = 1
# determine which dictionary to use??? # determine which dictionary to use???
if event in ['Birthday', 'Anniversary']: if event in ['Birthday', 'Anniversary', 'Death']:
month_dict = self.calendar.get(month, {}) month_dict = self.calendar.get(month, {})
else: else:
month_dict = self.holidays.get(month, {}) month_dict = self.holidays.get(month, {})
@@ -321,7 +320,7 @@ class WebCalReport(Report):
month_dict[day] = day_list month_dict[day] = day_list
# determine which dictionary to add it to??? # determine which dictionary to add it to???
if event in ['Birthday', 'Anniversary']: if event in ['Birthday', 'Anniversary', 'Death']:
self.calendar[month] = month_dict self.calendar[month] = month_dict
else: else:
self.holidays[month] = month_dict self.holidays[month] = month_dict
@@ -380,7 +379,7 @@ class WebCalReport(Report):
imgs += [CSS["favicon2"]["filename"]] imgs += [CSS["favicon2"]["filename"]]
for from_path in imgs: for from_path in imgs:
fdir, fname = os.path.split(from_path) dummy_fdir, fname = os.path.split(from_path)
self.copy_file(from_path, fname, "images") self.copy_file(from_path, fname, "images")
def create_file(self, fname, subdir): def create_file(self, fname, subdir):
@@ -458,8 +457,7 @@ class WebCalReport(Report):
links = Html("link", rel='shortcut icon', links = Html("link", rel='shortcut icon',
href=fname1, type="image/x-icon") + ( href=fname1, type="image/x-icon") + (
Html("link", href=fname2, type="text/css", Html("link", href=fname2, type="text/css",
media="screen", rel="stylesheet", indent=False) media="screen", rel="stylesheet", indent=False))
)
# add horizontal menu if css == Blue or Visually because # add horizontal menu if css == Blue or Visually because
# there is no menus? # there is no menus?
@@ -488,13 +486,13 @@ class WebCalReport(Report):
# Created for ? # Created for ?
msg = None msg = None
if self.author and self.email: if self.author and self.email:
bemail = '<a href="mailto:' + self.email + '?subject='
eemail = '">' + self.author + '</a>'
msg = self._('the "WebCal" will be the potential-email Subject|' msg = self._('the "WebCal" will be the potential-email Subject|'
'Created for %(html_email_author_start)s' 'Created for %(html_email_author_start)s'
'WebCal%(html_email_author_end)s') % { 'WebCal%(html_email_author_end)s') % {
'html_email_author_start' : 'html_email_author_start' : bemail,
'<a href="mailto:' + self.email + '?subject=', 'html_email_author_end' : eemail}
'html_email_author_end' :
'">' + self.author + '</a>'}
elif self.author: elif self.author:
msg = self._('Created for %(author)s') % { msg = self._('Created for %(author)s') % {
'author' : self.author} 'author' : self.author}
@@ -546,8 +544,10 @@ class WebCalReport(Report):
# Figure out if we need <li class="CurrentSection"> # Figure out if we need <li class="CurrentSection">
# or just plain <li> # or just plain <li>
check_cs = str(cal_year) == currentsection and\ if str(cal_year) == currentsection:
'class = "CurrentSection"' or False check_cs = 'class = "CurrentSection"'
else:
check_cs = False
if check_cs: if check_cs:
unordered.extend( unordered.extend(
Html("li", hyper, attr=check_cs, inline=True) Html("li", hyper, attr=check_cs, inline=True)
@@ -614,8 +614,10 @@ class WebCalReport(Report):
# Figure out if we need <li class="CurrentSection"> or # Figure out if we need <li class="CurrentSection"> or
# just plain <li> # just plain <li>
check_cs = url_fname == currentsection and \ if url_fname == currentsection:
'class = "CurrentSection"' or False check_cs = 'class = "CurrentSection"'
else:
check_cs = False
if url == self.home_link: if url == self.home_link:
mytitle = self._("NarrativeWeb Home") mytitle = self._("NarrativeWeb Home")
@@ -729,42 +731,42 @@ class WebCalReport(Report):
full_month_name = date_displayer.long_months[month-1] full_month_name = date_displayer.long_months[month-1]
url = full_month_name.lower() + self.ext url = full_month_name.lower() + self.ext
prevm = Date(int(year), int(month-1), 0) prevm = Date(int(year), int(month-1), 0)
my_title = Html("a", _escape("<"), href=url, my_title = Html("a", html_escape("<"), href=url,
title=date_displayer.display(prevm)) title=date_displayer.display(prevm))
elif self.multiyear and year > self.start_year: elif self.multiyear and year > self.start_year:
full_month_name = date_displayer.long_months[12] full_month_name = date_displayer.long_months[12]
url = full_month_name.lower() + self.ext url = full_month_name.lower() + self.ext
dest = os.path.join("../", str(year-1), url) dest = os.path.join("../", str(year-1), url)
prevm = Date(int(year-1), 12, 0) prevm = Date(int(year-1), 12, 0)
my_title = Html("a", _escape("<"), href=dest, my_title = Html("a", html_escape("<"), href=dest,
title=date_displayer.display(prevm)) title=date_displayer.display(prevm))
else: else:
full_month_name = date_displayer.long_months[12] full_month_name = date_displayer.long_months[12]
url = full_month_name.lower() + self.ext url = full_month_name.lower() + self.ext
dest = os.path.join("../", str(self.end_year), url) dest = os.path.join("../", str(self.end_year), url)
prevy = Date(self.end_year, 12, 0) prevy = Date(self.end_year, 12, 0)
my_title = Html("a", _escape("<"), href=dest, my_title = Html("a", html_escape("<"), href=dest,
title=date_displayer.display(prevy)) title=date_displayer.display(prevy))
my_title += Html("</a>&nbsp;") my_title += Html("</a>&nbsp;")
if month < 12: if month < 12:
full_month_name = date_displayer.long_months[month+1] full_month_name = date_displayer.long_months[month+1]
url = full_month_name.lower() + self.ext url = full_month_name.lower() + self.ext
nextd = Date(int(year), int(month+1), 0) nextd = Date(int(year), int(month+1), 0)
my_title += Html("a", _escape(">"), href=url, my_title += Html("a", html_escape(">"), href=url,
title=date_displayer.display(nextd)) title=date_displayer.display(nextd))
elif self.multiyear and year < self.end_year: elif self.multiyear and year < self.end_year:
full_month_name = date_displayer.long_months[1] full_month_name = date_displayer.long_months[1]
url = full_month_name.lower() + self.ext url = full_month_name.lower() + self.ext
dest = os.path.join("../", str(year+1), url) dest = os.path.join("../", str(year+1), url)
nextd = Date(int(year+1), 1, 0) nextd = Date(int(year+1), 1, 0)
my_title += Html("a", _escape(">"), href=dest, my_title += Html("a", html_escape(">"), href=dest,
title=date_displayer.display(nextd)) title=date_displayer.display(nextd))
else: else:
full_month_name = date_displayer.long_months[1] full_month_name = date_displayer.long_months[1]
url = full_month_name.lower() + self.ext url = full_month_name.lower() + self.ext
dest = os.path.join("../", str(self.start_year), url) dest = os.path.join("../", str(self.start_year), url)
nexty = Date(self.start_year, 1, 0) nexty = Date(self.start_year, 1, 0)
my_title += Html("a", _escape(">"), href=dest, my_title += Html("a", html_escape(">"), href=dest,
title=date_displayer.display(nexty)) title=date_displayer.display(nexty))
my_title += Html("</a>") my_title += Html("</a>")
trow = Html("tr") + ( trow = Html("tr") + (
@@ -792,8 +794,8 @@ class WebCalReport(Report):
table += tbody table += tbody
# get first of the month and month information # get first of the month and month information
current_date, current_ord, monthinfo = get_first_day_of_month(year, (dummy_current_date,
month) current_ord, monthinfo) = get_first_day_of_month(year, month)
# begin calendar table rows, starting week0 # begin calendar table rows, starting week0
nweeks = len(monthinfo) nweeks = len(monthinfo)
@@ -841,9 +843,13 @@ class WebCalReport(Report):
# Something this month # Something this month
if thisday.month == month: if thisday.month == month:
holiday_list = self.holidays.get(month, holiday_list = self.holidays.get(month,
{}).get(thisday.day, []) {}).get(
thisday.day,
[])
bday_anniv_list = self.calendar.get(month, bday_anniv_list = self.calendar.get(month,
{}).get(thisday.day, []) {}).get(
thisday.day,
[])
# date is an instance because of subtracting # date is an instance because of subtracting
# abilities in date.py # abilities in date.py
@@ -892,15 +898,13 @@ class WebCalReport(Report):
# without id tag # without id tag
tcell = Html("td", class_=hilightday, tcell = Html("td", class_=hilightday,
inline=True) + ( inline=True) + (
# adds date division # adds date division
Html("div", day, class_="date", Html("div", day,
inline=True) class_="date",
) inline=True))
# WebCal # WebCal
else: else:
# add date to table cell # add date to table cell
tcell += datediv tcell += datediv
@@ -908,30 +912,27 @@ class WebCalReport(Report):
unordered = Html("ul") unordered = Html("ul")
tcell += unordered tcell += unordered
for (nyears, date, text, for (dummy_nyears, dummy_date, text,
event, notused, notused) in day_list: event, dummy_notused,
dummy_notused) in day_list:
unordered += Html("li", text, unordered += Html("li", text,
inline=False inline=False
if event == 'Anniversary' else True) if (event ==
'Anniversary')
else True)
# no events for this day # no events for this day
else: else:
# create empty day with date # create empty day with date
tcell = Html("td", class_=dayclass, tcell = Html("td", class_=dayclass,
inline=True) + ( inline=True) + (
# adds date division # adds date division
Html("div", day, class_="date", inline=True) Html("div", day, class_="date",
) inline=True))
# nothing for this month # nothing for this month
else: else:
tcell = Html("td", class_=dayclass) + ( tcell = Html("td", class_=dayclass) + (
# adds date division # adds date division
Html("div", day, class_="date", inline=True) Html("div", day, class_="date", inline=True))
)
# attach table cell to table row # attach table cell to table row
# close the day column # close the day column
@@ -949,7 +950,7 @@ class WebCalReport(Report):
class_="week%02d" % (weeks + 1)) as six_weeks: class_="week%02d" % (weeks + 1)) as six_weeks:
tbody += six_weeks tbody += six_weeks
for emptydays in range(7): for dummy_emptydays in range(7):
six_weeks += Html("td", class_="emptyDays", six_weeks += Html("td", class_="emptyDays",
inline=True) inline=True)
@@ -1022,7 +1023,7 @@ class WebCalReport(Report):
# send calendar page to web output # send calendar page to web output
# and close the file # and close the file
self.XHTMLWriter(webcal, open_file) self.xhtmlwriter(webcal, open_file)
step() step()
@@ -1058,7 +1059,8 @@ class WebCalReport(Report):
# generate progress pass for "Year At A Glance" # generate progress pass for "Year At A Glance"
with self._user.progress(_("Web Calendar Report"), with self._user.progress(_("Web Calendar Report"),
_('Creating Year At A Glance calendar'), 12) as step: _('Creating Year At A Glance calendar'),
12) as step:
open_file = self.create_file('fullyearlinked', str(year)) open_file = self.create_file('fullyearlinked', str(year))
@@ -1079,9 +1081,10 @@ class WebCalReport(Report):
body += self.month_navigation(nr_up, year, "fullyearlinked", True) body += self.month_navigation(nr_up, year, "fullyearlinked", True)
msg = (self._('This calendar is meant to give you access ' msg = (self._('This calendar is meant to give you access '
'to all your data at a glance compressed into one page. ' 'to all your data at a glance compressed into one '
'Clicking on a date will take you to a page that shows all' 'page. Clicking on a date will take you to a page '
' the events for that date, if there are any.\n')) 'that shows all the events for that date, if there '
'are any.\n'))
# page description # page description
content = Html("div", class_="content", id="YearGlance") content = Html("div", class_="content", id="YearGlance")
@@ -1106,7 +1109,7 @@ class WebCalReport(Report):
# send calendar page to web output # send calendar page to web output
# and close the file # and close the file
self.XHTMLWriter(yearglance, open_file) self.xhtmlwriter(yearglance, open_file)
def one_day(self, event_date, fname_date, day_list): def one_day(self, event_date, fname_date, day_list):
""" """
@@ -1145,7 +1148,7 @@ class WebCalReport(Report):
currentsection = _dd.long_months[month] currentsection = _dd.long_months[month]
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 preferences
content = Html("div", class_="content", id="OneDay") content = Html("div", class_="content", id="OneDay")
body += content body += content
evt = fname_date[:8] evt = fname_date[:8]
@@ -1160,7 +1163,7 @@ class WebCalReport(Report):
url = event[1] + self.ext url = event[1] + self.ext
prevd = Date(int(event[1][:4]), int(event[1][4:6]), prevd = Date(int(event[1][:4]), int(event[1][4:6]),
int(event[1][6:])) int(event[1][6:]))
my_title = Html("a", _escape("<"), href=url, my_title = Html("a", html_escape("<"), href=url,
title=self.rlocale.get_date(prevd)) title=self.rlocale.get_date(prevd))
else: else:
my_title = Html('<em>&nbsp;&nbsp;</em>') my_title = Html('<em>&nbsp;&nbsp;</em>')
@@ -1169,7 +1172,7 @@ class WebCalReport(Report):
url = event[2] + self.ext url = event[2] + self.ext
nextd = Date(int(event[2][:4]), int(event[2][4:6]), nextd = Date(int(event[2][:4]), int(event[2][4:6]),
int(event[2][6:])) int(event[2][6:]))
my_title += Html("a", _escape(">"), href=url, my_title += Html("a", html_escape(">"), href=url,
title=self.rlocale.get_date(nextd)) title=self.rlocale.get_date(nextd))
else: else:
my_title += Html('<b>&nbsp;&nbsp;</b>') my_title += Html('<b>&nbsp;&nbsp;</b>')
@@ -1183,8 +1186,8 @@ class WebCalReport(Report):
# list the events # list the events
ordered = Html("ol") ordered = Html("ol")
content += ordered content += ordered
for (nyears, date, text, event, age_at_death, for (dummy_nyears, dummy_date, text, event, dummy_age_at_death,
dead_event_date) in day_list: dummy_dead_event_date) in day_list:
ordered += Html("li", text, ordered += Html("li", text,
inline=False if event == 'Anniversary' else True) inline=False if event == 'Anniversary' else True)
@@ -1195,7 +1198,7 @@ class WebCalReport(Report):
# send calendar page to web output # send calendar page to web output
# and close the file # and close the file
self.XHTMLWriter(oneday, one_day_file) self.xhtmlwriter(oneday, one_day_file)
def build_url_fname_html(self, fname, subdir=None, prefix=None): def build_url_fname_html(self, fname, subdir=None, prefix=None):
""" """
@@ -1360,6 +1363,36 @@ class WebCalReport(Report):
self.add_day_item(text, year, month, day, self.add_day_item(text, year, month, day,
'Birthday', 'Birthday',
age_at_death, person_death) age_at_death, person_death)
death_event = get_death_or_fallback(db, person)
if death_event:
death_date = death_event.get_date_object()
else:
death_date = None
#primary_name = person.primary_name
#name = Name(primary_name)
if self.death_anniv and death_date:
year = death_date.get_year() or this_year
month = death_date.get_month()
day = death_date.get_day()
short_name = self.get_name(person)
prob_alive_date = Date(this_year, month, day)
alive = probably_alive(person, db, prob_alive_date)
if (self.alive and alive) or not self.alive:
# add link to NarrativeWeb
if self.link_to_narweb:
prfx = self.narweb_prefix
navpfx = self.build_url_fname_html(person.handle,
"ppl",
prefix=prfx)
text = str(Html("a", short_name, href=navpfx))
else:
text = short_name
self.add_day_item(text, year, month, day, 'Death',
age_at_death, death_date)
#print('Death date for %s %s/%s/%s' % (short_name, day,
# month, year),
# age_at_death)
# add anniversary if requested # add anniversary if requested
if self.anniv: if self.anniv:
@@ -1417,14 +1450,16 @@ class WebCalReport(Report):
dlocale=self.rlocale) dlocale=self.rlocale)
if self.link_to_narweb: if self.link_to_narweb:
spouse_name = str(Html("a", spouse_name, prefx = self.narweb_prefix
href=self.build_url_fname_html( reference = self.build_url_fname_html(
spouse_handle, 'ppl', spouse_handle, 'ppl',
prefix=self.narweb_prefix))) prefix=prefx)
spouse_name = str(Html("a", spouse_name,
href=reference))
href1 = self.build_url_fname_html(
person.handle, 'ppl', prefix=prefx)
short_name = str(Html("a", short_name, short_name = str(Html("a", short_name,
href=self.build_url_fname_html( href=href1))
person.handle, 'ppl',
prefix=self.narweb_prefix)))
alive1 = probably_alive(person, db, alive1 = probably_alive(person, db,
prob_alive_date) prob_alive_date)
@@ -1435,8 +1470,9 @@ class WebCalReport(Report):
if ((self.alive and alive1 if ((self.alive and alive1
and alive2) or not self.alive): and alive2) or not self.alive):
mg = self._('%(spouse)s and %(person)s') spse = self._('%(spouse)s and'
text = mg % {'spouse' : spouse_name, ' %(person)s')
text = spse % {'spouse' : spouse_name,
'person' : short_name} 'person' : short_name}
self.add_day_item(text, year, month, self.add_day_item(text, year, month,
@@ -1455,12 +1491,13 @@ class WebCalReport(Report):
with Html("div", id="footer", role="Footer-End") as footer: with Html("div", id="footer", role="Footer-End") as footer:
# Display date as user set in preferences # Display date as user set in preferences
date = self.rlocale.date_displayer.display(Today())
bhtml = '<a href="' + URL_HOMEPAGE + '">'
msg = self._('Generated by %(gramps_home_html_start)s' msg = self._('Generated by %(gramps_home_html_start)s'
'Gramps%(html_end)s on %(date)s') % { 'Gramps%(html_end)s on %(date)s') % {
'gramps_home_html_start' : 'gramps_home_html_start' : bhtml,
'<a href="' + URL_HOMEPAGE + '">',
'html_end' : '</a>', 'html_end' : '</a>',
'date' : self.rlocale.date_displayer.display(Today())} 'date' : date}
footer += Html("p", msg, id='createdate') footer += Html("p", msg, id='createdate')
copy_nr = self.copy copy_nr = self.copy
@@ -1482,7 +1519,7 @@ class WebCalReport(Report):
# return footer to its callers # return footer to its callers
return footer return footer
def XHTMLWriter(self, page, open_file): def xhtmlwriter(self, page, open_file):
""" """
This function is simply to make the web page look pretty and readable This function is simply to make the web page look pretty and readable
It is not for the browser, but for us, humans It is not for the browser, but for us, humans
@@ -1580,7 +1617,7 @@ class WebCalReport(Report):
# send calendar page to web output # send calendar page to web output
# and close the file # and close the file
self.XHTMLWriter(index, output_file) self.xhtmlwriter(index, output_file)
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# WebCalOptions; Creates the Menu # WebCalOptions; Creates the Menu
@@ -1600,6 +1637,7 @@ class WebCalOptions(MenuReportOptions):
self.__multiyear = None self.__multiyear = None
self.__start_year = None self.__start_year = None
self.__end_year = None self.__end_year = None
self.__after_year = None
def add_menu_options(self, menu): def add_menu_options(self, menu):
""" """
@@ -1608,8 +1646,8 @@ class WebCalOptions(MenuReportOptions):
self.__add_report_options(menu) self.__add_report_options(menu)
self.__add_report2_options(menu) self.__add_report2_options(menu)
self.__add_content_options(menu) self.__add_content_options(menu)
self.__add_notes_options(menu)
self.__add_advanced_options(menu) self.__add_advanced_options(menu)
self.__add_notes_options(menu)
def __add_report_options(self, menu): def __add_report_options(self, menu):
""" """
@@ -1619,9 +1657,9 @@ class WebCalOptions(MenuReportOptions):
dbname = self.__db.get_dbname() dbname = self.__db.get_dbname()
default_dir = dbname + "_WEBCAL" default_dir = dbname + "_WEBCAL"
target = DestinationOption(_("Destination"), target = DestinationOption(
os.path.join(config.get('paths.website-directory'), _("Destination"),
default_dir)) os.path.join(config.get('paths.website-directory'), default_dir))
target.set_help(_("The destination directory for the web files")) target.set_help(_("The destination directory for the web files"))
target.set_directory_entry(True) target.set_directory_entry(True)
menu.add_option(category_name, "target", target) menu.add_option(category_name, "target", target)
@@ -1681,7 +1719,7 @@ class WebCalOptions(MenuReportOptions):
break break
name_format = EnumeratedListOption(_("Name format"), name_format = EnumeratedListOption(_("Name format"),
fmt_list[default][0]) fmt_list[default][0])
for num, name, fmt_str, act in fmt_list: for num, name, dummy_fmt_str, dummy_act in fmt_list:
name_format.add_item(num, name) name_format.add_item(num, name)
name_format.set_help(_("Select the format to display names")) name_format.set_help(_("Select the format to display names"))
menu.add_option(category_name, "name_format", name_format) menu.add_option(category_name, "name_format", name_format)
@@ -1729,8 +1767,10 @@ class WebCalOptions(MenuReportOptions):
holiday_table = libholiday.HolidayTable() holiday_table = libholiday.HolidayTable()
countries = holiday_table.get_countries() countries = holiday_table.get_countries()
countries.sort() countries.sort()
if (len(countries) == 0 or #if (len(countries) == 0 or
(len(countries) > 0 and countries[0] != '')): # (len(countries) > 0 and countries[0] != '')):
if (not countries or
(countries and countries[0] != '')):
countries.insert(0, '') countries.insert(0, '')
count = 0 count = 0
for cntry in countries: for cntry in countries:
@@ -1764,14 +1804,6 @@ class WebCalOptions(MenuReportOptions):
"the main page of the web site")) "the main page of the web site"))
menu.add_option(category_name, "home_link", home_link) menu.add_option(category_name, "home_link", home_link)
birthdays = BooleanOption(_("Include birthdays"), True)
birthdays.set_help(_("Include birthdays in the calendar"))
menu.add_option(category_name, "birthdays", birthdays)
anniversaries = BooleanOption(_("Include anniversaries"), True)
anniversaries.set_help(_("Include anniversaries in the calendar"))
menu.add_option(category_name, "anniversaries", anniversaries)
def __add_notes_options(self, menu): def __add_notes_options(self, menu):
""" """
Options on the "Months Notes" tabs. Options on the "Months Notes" tabs.
@@ -1847,11 +1879,34 @@ class WebCalOptions(MenuReportOptions):
makeoneday.set_help(_('Whether to create one day pages or not')) makeoneday.set_help(_('Whether to create one day pages or not'))
menu.add_option(category_name, 'makeoneday', makeoneday) menu.add_option(category_name, 'makeoneday', makeoneday)
birthdays = BooleanOption(_("Include birthdays"), True)
birthdays.set_help(_("Include birthdays in the calendar"))
menu.add_option(category_name, "birthdays", birthdays)
anniversaries = BooleanOption(_("Include anniversaries"), True)
anniversaries.set_help(_("Include anniversaries in the calendar"))
menu.add_option(category_name, "anniversaries", anniversaries)
anniversaries = BooleanOption(_('Include death dates'), False)
anniversaries.set_help(_('Include death anniversaries in the calendar'))
menu.add_option(category_name, 'death_anniv', anniversaries)
self.__links = BooleanOption(_('Link to Narrated Web Report'), False) self.__links = BooleanOption(_('Link to Narrated Web Report'), False)
self.__links.set_help(_('Whether to link data to web report or not')) self.__links.set_help(_('Whether to link data to web report or not'))
menu.add_option(category_name, 'link_to_narweb', self.__links) menu.add_option(category_name, 'link_to_narweb', self.__links)
self.__links.connect('value-changed', self.__links_changed) self.__links.connect('value-changed', self.__links_changed)
today = Today()
default_before = config.get('behavior.max-age-prob-alive')
self.__after_year = NumberOption(_('Show data only after year'),
(today.get_year() - default_before),
0, today.get_year())
self.__after_year.set_help(_("Show data only after this year."
" Default is current year - "
" 'maximum age probably alive' which is "
"defined in the dates preference tab."))
menu.add_option(category_name, 'after_year', self.__after_year)
dbname = self.__db.get_dbname() dbname = self.__db.get_dbname()
default_prefix = '../../' + dbname + "_NAVWEB/" default_prefix = '../../' + dbname + "_NAVWEB/"
self.__prefix = StringOption(_('Link prefix'), default_prefix) self.__prefix = StringOption(_('Link prefix'), default_prefix)
@@ -1912,6 +1967,7 @@ def _regular_surname(sex, name):
""" """
Returns a name string built from the components of the Name instance. Returns a name string built from the components of the Name instance.
""" """
dummy_gender = sex
surname = name.get_surname() surname = name.get_surname()
suffix = name.get_suffix() suffix = name.get_suffix()
if suffix: if suffix:
@@ -2034,12 +2090,19 @@ def get_day_list(event_date, holiday_list, bday_anniv_list, rlocale=glocale):
date_y = date.get_year() date_y = date.get_year()
trans_date = trans_text("Born %(birth_date)s.") trans_date = trans_text("Born %(birth_date)s.")
old_date = trans_text('%s old') old_date = trans_text('%s old')
tranlated_date = rlocale.get_date(dead_event_date) translated_date = rlocale.get_date(dead_event_date)
age += old_date % str(age_str) if date_y != 0 else \ age += old_date % (str(age_str) if (date_y != 0)
trans_date % { else trans_date % {
'birth_date' : translated_date} 'birth_date' : translated_date})
txt_str = (text + age + '</em>') txt_str = (text + age + '</em>')
# a death
if event == 'Death':
txt_str = (text + ', <em>'
+ (_('%s since death') % str(age_str) if nyears
else _('death'))
+ '</em>')
# an anniversary # an anniversary
elif event == "Anniversary": elif event == "Anniversary":