Webcal: add death event
Fixes #5025 add some cleanup use html_escape instead of _escape
This commit is contained in:
parent
b5e9795ccf
commit
98a38cde57
@ -50,6 +50,7 @@ from gramps.gen.const import GRAMPS_LOCALE as glocale
|
|||||||
_ = glocale.translation.sgettext
|
_ = 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 +64,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
|
||||||
@ -93,18 +95,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('&', '&') # must be the first
|
|
||||||
string = string.replace('<', '<')
|
|
||||||
string = string.replace('>', '>')
|
|
||||||
return string
|
|
||||||
|
|
||||||
# pylint: disable=unused-variable
|
|
||||||
# pylint: disable=unused-argument
|
|
||||||
|
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# WebCalReport
|
# WebCalReport
|
||||||
@ -157,6 +147,7 @@ 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 = []
|
||||||
|
|
||||||
@ -290,7 +281,7 @@ 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
|
||||||
@ -302,7 +293,7 @@ class WebCalReport(Report):
|
|||||||
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 +312,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
|
||||||
@ -729,42 +720,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> ")
|
my_title += Html("</a> ")
|
||||||
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") + (
|
||||||
@ -1006,7 +997,7 @@ class WebCalReport(Report):
|
|||||||
note = self.database.get_note_from_gramps_id(note)
|
note = self.database.get_note_from_gramps_id(note)
|
||||||
note = self.get_note_format(note)
|
note = self.get_note_format(note)
|
||||||
|
|
||||||
# table foot section
|
# table foot section
|
||||||
cal_foot = Html("tfoot")
|
cal_foot = Html("tfoot")
|
||||||
monthly_calendar += cal_foot
|
monthly_calendar += cal_foot
|
||||||
|
|
||||||
@ -1145,7 +1136,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 +1151,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> </em>')
|
my_title = Html('<em> </em>')
|
||||||
@ -1169,7 +1160,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> </b>')
|
my_title += Html('<b> </b>')
|
||||||
@ -1360,6 +1351,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:
|
||||||
@ -1764,14 +1785,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,6 +1860,18 @@ 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)
|
||||||
@ -2040,6 +2065,12 @@ def get_day_list(event_date, holiday_list, bday_anniv_list, rlocale=glocale):
|
|||||||
'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":
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user