WebCal.py and NarrativeWeb.py; were sent by mistake. Watch as they are coming... Reverted back to r11481 and r11711 respectively.
svn: r11740
This commit is contained in:
@@ -42,6 +42,7 @@ dst start/stop from Calendar.py, etc.
|
|||||||
2008 Kees Bakker
|
2008 Kees Bakker
|
||||||
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:
|
TODO list:
|
||||||
|
- change filename for one_day pages to yyyy/mm/dd.html (just numbers)
|
||||||
- progress bar, rethink its usage
|
- progress bar, rethink its usage
|
||||||
- in year navigation, use month in link, or 'fullyear'
|
- in year navigation, use month in link, or 'fullyear'
|
||||||
- untangle calendar_build, it's too complex the way it is
|
- untangle calendar_build, it's too complex the way it is
|
||||||
@@ -226,6 +227,7 @@ class WebCalReport(Report):
|
|||||||
self.end_year = menu.get_option_by_name('end_year').get_value()
|
self.end_year = menu.get_option_by_name('end_year').get_value()
|
||||||
|
|
||||||
self.fullyear = menu.get_option_by_name('fullyear').get_value()
|
self.fullyear = menu.get_option_by_name('fullyear').get_value()
|
||||||
|
self.blankyear = menu.get_option_by_name('blankyear').get_value()
|
||||||
|
|
||||||
self.maiden_name = menu.get_option_by_name('maiden_name').get_value()
|
self.maiden_name = menu.get_option_by_name('maiden_name').get_value()
|
||||||
|
|
||||||
@@ -262,6 +264,7 @@ class WebCalReport(Report):
|
|||||||
self.today = datetime.date(today[0], today[1], today[2])
|
self.today = datetime.date(today[0], today[1], today[2])
|
||||||
|
|
||||||
self.warn_dir = True # Only give warning once.
|
self.warn_dir = True # Only give warning once.
|
||||||
|
self.imgs = []
|
||||||
|
|
||||||
# self.calendar is a dict; key is the month number
|
# self.calendar is a dict; key is the month number
|
||||||
# Each entry in the dict is also a dict; key is the day number.
|
# Each entry in the dict is also a dict; key is the day number.
|
||||||
@@ -310,7 +313,7 @@ class WebCalReport(Report):
|
|||||||
|
|
||||||
if month > 0:
|
if month > 0:
|
||||||
try:
|
try:
|
||||||
my_date = _make_date(year, month, day)
|
my_date = datetime.date(year, month, day)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
my_date = '...'
|
my_date = '...'
|
||||||
else:
|
else:
|
||||||
@@ -394,11 +397,7 @@ class WebCalReport(Report):
|
|||||||
"""
|
"""
|
||||||
Copies all the necessary files
|
Copies all the necessary files
|
||||||
"""
|
"""
|
||||||
|
# Copy the normal stylesheet
|
||||||
# initialize imgs to fill
|
|
||||||
imgs = []
|
|
||||||
|
|
||||||
# Copy the screen stylesheet
|
|
||||||
if self.css != "":
|
if self.css != "":
|
||||||
fname = os.path.join(const.DATA_DIR, self.css)
|
fname = os.path.join(const.DATA_DIR, self.css)
|
||||||
self.copy_file(fname, self.css, "styles")
|
self.copy_file(fname, self.css, "styles")
|
||||||
@@ -407,22 +406,16 @@ class WebCalReport(Report):
|
|||||||
fname = os.path.join(const.DATA_DIR, "Web_Print-Default.css")
|
fname = os.path.join(const.DATA_DIR, "Web_Print-Default.css")
|
||||||
self.copy_file(fname, "Web_Print-Default.css", "styles")
|
self.copy_file(fname, "Web_Print-Default.css", "styles")
|
||||||
|
|
||||||
if self.css == "Web_Mainz.css":
|
|
||||||
# Copy Mainz Style Images
|
|
||||||
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"]
|
fname = os.path.join(const.IMAGE_DIR, "favicon.ico")
|
||||||
|
self.copy_file(fname, "favicon.ico", "images")
|
||||||
|
|
||||||
# copy copyright image
|
# copy copyright image
|
||||||
if 0 < self.copy < len(_CC):
|
if 0 < self.copy < len(_CC):
|
||||||
imgs += ["somerights20.gif"]
|
fname = os.path.join(const.IMAGE_DIR, 'somerights20.gif')
|
||||||
|
self.copy_file(fname, 'somerights20.gif', 'images')
|
||||||
|
|
||||||
for f in imgs:
|
for f in self.imgs:
|
||||||
from_path = os.path.join(const.IMAGE_DIR, f)
|
from_path = os.path.join(const.IMAGE_DIR, f)
|
||||||
self.copy_file(from_path, f, "images")
|
self.copy_file(from_path, f, "images")
|
||||||
|
|
||||||
@@ -448,6 +441,9 @@ class WebCalReport(Report):
|
|||||||
# Add a link for year_glance() if requested
|
# Add a link for year_glance() if requested
|
||||||
navs.append(('fullyear', _('Year Glance'), self.fullyear))
|
navs.append(('fullyear', _('Year Glance'), self.fullyear))
|
||||||
|
|
||||||
|
# add a link to blank_year() if requested
|
||||||
|
navs.append(('blankyear', _('Blank Calendar'), self.blankyear))
|
||||||
|
|
||||||
of.write('<div id="subnavigation">\n')
|
of.write('<div id="subnavigation">\n')
|
||||||
of.write('\t<ul>\n')
|
of.write('\t<ul>\n')
|
||||||
|
|
||||||
@@ -473,7 +469,7 @@ class WebCalReport(Report):
|
|||||||
url = url_fname
|
url = url_fname
|
||||||
if not url.startswith('http:'):
|
if not url.startswith('http:'):
|
||||||
url = '/'.join(subdirs + [url_fname])
|
url = '/'.join(subdirs + [url_fname])
|
||||||
if not url.endswith(self.ext):
|
if not _has_webpage_extension(url):
|
||||||
url += self.ext
|
url += self.ext
|
||||||
|
|
||||||
cs = cs and ' id="CurrentSection"' or ''
|
cs = cs and ' id="CurrentSection"' or ''
|
||||||
@@ -572,7 +568,7 @@ class WebCalReport(Report):
|
|||||||
def calendar_build(self, of, cal, year, month):
|
def calendar_build(self, of, cal, year, month):
|
||||||
"""
|
"""
|
||||||
This does the work of building the calendar
|
This does the work of building the calendar
|
||||||
'cal' - one of "yg", "wc"
|
'cal' - one of "yg", "by", "wc"
|
||||||
'month' - month number 1, 2, .., 12
|
'month' - month number 1, 2, .., 12
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@@ -656,11 +652,11 @@ class WebCalReport(Report):
|
|||||||
nweeks = len(monthinfo)
|
nweeks = len(monthinfo)
|
||||||
for week_row in range(0, nweeks):
|
for week_row in range(0, nweeks):
|
||||||
week = monthinfo[week_row]
|
week = monthinfo[week_row]
|
||||||
# if you look this up in wikipedia, the first week is called week0
|
of.write('\t\t<tr class="week%d">\n' % (week_row+1))
|
||||||
of.write('\t\t<tr class="week%d">\n' % week_row)
|
|
||||||
|
|
||||||
for day_col in range(0, 7):
|
for day_col in range(0, 7):
|
||||||
dayclass = get_class_for_daycol(day_col)
|
dayclass = get_class_for_daycol(day_col)
|
||||||
|
hilightday = 'highlight ' + dayclass
|
||||||
|
|
||||||
day = week[day_col]
|
day = week[day_col]
|
||||||
if day == 0: # a day in the previous or next month
|
if day == 0: # a day in the previous or next month
|
||||||
@@ -671,57 +667,62 @@ class WebCalReport(Report):
|
|||||||
specday = firstweek_nextmonth[day_col]
|
specday = firstweek_nextmonth[day_col]
|
||||||
specclass = "next " + dayclass
|
specclass = "next " + dayclass
|
||||||
|
|
||||||
|
#if specclass[0] == 'p': # previous day of last month
|
||||||
|
# of.write('\t\t\t<td id="prevday%d" ' % specday)
|
||||||
|
#else: # next day of next month
|
||||||
|
# of.write('\t\t\t<td id="nextday%d" ' % specday)
|
||||||
of.write('\t\t\t<td class="%s">\n' % specclass)
|
of.write('\t\t\t<td class="%s">\n' % specclass)
|
||||||
of.write('\t\t\t\t<div class="date">%d</div>\n' % specday)
|
of.write('\t\t\t\t<div class="date">%d</div>\n' % specday)
|
||||||
of.write('\t\t\t</td>\n')
|
of.write('\t\t\t</td>\n')
|
||||||
|
|
||||||
else: # normal day number in current month
|
else: # normal day number in current month
|
||||||
thisday = datetime.date.fromordinal(current_ord)
|
if cal == "by": # blank_year() doesn't need any highlighting or hyperlinks
|
||||||
of.write('\t\t\t<td id="%s%02d" ' % (shrt_month, day))
|
of.write('\t\t\t<td id="%s%02d" class="%s">\n' % (shrt_month, day, dayclass))
|
||||||
if thisday.month == month: # Something this month
|
of.write('\t\t\t\t<div class="date">%d</div>\n' % day)
|
||||||
holiday_list = self.holidays.get(month, {}).get(thisday.day, [])
|
of.write('\t\t\t</td>\n')
|
||||||
bday_anniv_list = self.calendar.get(month, {}).get(thisday.day, [])
|
else:
|
||||||
if (holiday_list > []) or (bday_anniv_list > []):
|
thisday = datetime.date.fromordinal(current_ord)
|
||||||
|
of.write('\t\t\t<td id="%s%02d" ' % (shrt_month, day))
|
||||||
|
if thisday.month == month: # Something this month
|
||||||
|
holiday_list = self.holidays.get(month, {}).get(thisday.day, [])
|
||||||
|
bday_anniv_list = self.calendar.get(month, {}).get(thisday.day, [])
|
||||||
|
if (holiday_list > []) or (bday_anniv_list > []):
|
||||||
|
evt_date = time.strptime('%d/%d/%d' % (year, month, day), '%Y/%m/%d')
|
||||||
|
|
||||||
hilightday = 'highlight ' + dayclass
|
# Year at a Glance
|
||||||
|
if cal == "yg":
|
||||||
|
did_some = self.one_day(of, year, evt_date, cal, holiday_list, bday_anniv_list)
|
||||||
|
if did_some:
|
||||||
|
# Notice the code in one_day(): cal_fname = '%s%d%s' % (shrt_month, day, self.ext)
|
||||||
|
# TODO. Create file for one_day()
|
||||||
|
# The HREF is relative to the year path.
|
||||||
|
fname = '%s%d%s' % (shrt_month, day, self.ext)
|
||||||
|
fname = '/'.join([lng_month, fname])
|
||||||
|
of.write('class="%s">\n' % hilightday)
|
||||||
|
of.write('\t\t\t\t<a id="%s%d" href="%s" title="%s%d">\n'
|
||||||
|
% (shrt_month, day, fname, shrt_month, day))
|
||||||
|
of.write('\t\t\t\t\t<div class="date">%d</div>\n' % day)
|
||||||
|
of.write('\t\t\t\t</a>\n')
|
||||||
|
else:
|
||||||
|
of.write('class="%s">\n' % dayclass)
|
||||||
|
of.write('\t\t\t\t<div class="date">%d</div>\n' % day)
|
||||||
|
|
||||||
# specify day class for this day
|
# WebCal
|
||||||
of.write('class="%s">\n' % hilightday)
|
elif cal == 'wc':
|
||||||
|
of.write('class="%s">\n' % hilightday)
|
||||||
|
of.write('\t\t\t\t<div class="date">%d</div>\n' % day)
|
||||||
|
self.one_day(of, year, evt_date, cal, holiday_list, bday_anniv_list)
|
||||||
|
|
||||||
# Year at a Glance
|
# no holiday/ bday/ anniversary this day
|
||||||
if cal == "yg":
|
else:
|
||||||
# create yyyymmdd date string for "One Day" calendar pages filename
|
of.write('class="%s">\n' % dayclass)
|
||||||
two_digit_month = '%02d' % month
|
|
||||||
two_digit_day = '%02d' % day
|
|
||||||
fname_date = str(year) + str(two_digit_month) + str(two_digit_day)
|
|
||||||
|
|
||||||
# create web link to corresponding "One Day" page...
|
|
||||||
# The HREF is relative to the year path.
|
|
||||||
fname = '%s%s' % (fname_date, self.ext)
|
|
||||||
fname = '/'.join([lng_month, fname_date])
|
|
||||||
of.write('\t\t\t\t<a id="%s" href="%s" title="%s%d">\n'
|
|
||||||
% (fname_date, fname, shrt_month, day))
|
|
||||||
of.write('\t\t\t\t\t<div class="date">%d</div>\n' % day)
|
|
||||||
of.write('\t\t\t\t</a>\n')
|
|
||||||
one_day_cal = "OneDay"
|
|
||||||
|
|
||||||
# WebCal
|
|
||||||
else:
|
|
||||||
one_day_cal = "WebCal"
|
|
||||||
of.write('\t\t\t\t<div class="date">%d</div>\n' % day)
|
of.write('\t\t\t\t<div class="date">%d</div>\n' % day)
|
||||||
|
|
||||||
self.one_day(of, thisday, one_day_cal, holiday_list, bday_anniv_list)
|
# no holiday/ bday/ anniversary this month
|
||||||
|
|
||||||
# no holiday/ bday/ anniversary this day
|
|
||||||
else:
|
else:
|
||||||
of.write('class="%s">\n' % dayclass)
|
of.write('class="%s">\n' % dayclass)
|
||||||
of.write('\t\t\t\t<div class="date">%d</div>\n' % day)
|
of.write('\t\t\t\t<div class="date">%d</div>\n' % day)
|
||||||
|
|
||||||
# no holiday/ bday/ anniversary this month
|
|
||||||
else:
|
|
||||||
of.write('class="%s">\n' % dayclass)
|
|
||||||
of.write('\t\t\t\t<div class="date">%d</div>\n' % day)
|
|
||||||
|
|
||||||
# close the day/ column
|
# close the day/ column
|
||||||
of.write('\t\t\t</td>\n')
|
of.write('\t\t\t</td>\n')
|
||||||
|
|
||||||
@@ -731,7 +732,7 @@ class WebCalReport(Report):
|
|||||||
# close the week/ row
|
# close the week/ row
|
||||||
of.write('\t\t</tr>\n')
|
of.write('\t\t</tr>\n')
|
||||||
|
|
||||||
if cal == "yg":
|
if cal in ("yg", "by"):
|
||||||
# Fill up till we have 6 rows, so that the months align properly
|
# Fill up till we have 6 rows, so that the months align properly
|
||||||
for i in range(nweeks, 6):
|
for i in range(nweeks, 6):
|
||||||
of.write('\t\t<tr class="week%d">\n' % (i+1))
|
of.write('\t\t<tr class="week%d">\n' % (i+1))
|
||||||
@@ -824,7 +825,7 @@ class WebCalReport(Report):
|
|||||||
|
|
||||||
fname = os.path.join(self.html_dir, subdir, fname)
|
fname = os.path.join(self.html_dir, subdir, fname)
|
||||||
|
|
||||||
if not fname.endswith(self.ext):
|
if not _has_webpage_extension(fname):
|
||||||
fname += self.ext
|
fname += self.ext
|
||||||
|
|
||||||
destdir = os.path.dirname(fname)
|
destdir = os.path.dirname(fname)
|
||||||
@@ -838,64 +839,156 @@ class WebCalReport(Report):
|
|||||||
def close_file(self, of):
|
def close_file(self, of):
|
||||||
of.close()
|
of.close()
|
||||||
|
|
||||||
def one_day(self, of, event_date, one_day_cal, holiday_list, bday_anniv_list):
|
def one_day(self, of, year, event_date, cal, holiday_list, bday_anniv_list):
|
||||||
"""
|
"""
|
||||||
This method creates the One Day page for "Year At A Glance"
|
This method creates the One Day page for "Year At A Glance"
|
||||||
|
|
||||||
'holiday_list' - list of holidays to display on this day
|
'holiday_list' - list of holidays to display on this day
|
||||||
'bday_anniv_list' - list of birthdays and anniversaries to display on this day
|
'bday_anniv_list' - list of birthdays and anniversaries to display on this day
|
||||||
|
|
||||||
|
one or both of these dictionaries will possibly hav something in it
|
||||||
|
|
||||||
'day_list' - a combination of both dictionaries to be able to create one day
|
'day_list' - a combination of both dictionaries to be able to create one day
|
||||||
nyears, date, text, event --- are necessary for figuring the age or years married
|
date, text, event --- are necessary for figuring the age or years married
|
||||||
for each year being created...
|
for each year being created...
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# initialize day_list
|
|
||||||
day_list = []
|
day_list = []
|
||||||
|
|
||||||
# call day_list to fill
|
# holiday on this day
|
||||||
day_list = fill_day_list(event_date, holiday_list, bday_anniv_list)
|
if holiday_list > []:
|
||||||
|
for p in holiday_list:
|
||||||
|
for line in p.splitlines():
|
||||||
|
day_list.append((event_date, line, _('Holiday')))
|
||||||
|
|
||||||
# This is one_day in the year-at-a-glance calendar
|
# birthday/ anniversary on this day
|
||||||
if one_day_cal == "OneDay":
|
if bday_anniv_list > []:
|
||||||
|
for date, text, event in bday_anniv_list:
|
||||||
|
|
||||||
# break up event_date to get year, month, day for this day
|
# '...' signifies an incomplete date for an event. See add_day_item()
|
||||||
year, month, day = event_date.year, event_date.month, event_date.day
|
txt_str = None
|
||||||
|
if date != '...':
|
||||||
|
years = year - date.year
|
||||||
|
|
||||||
# create fname date string for "One Day" calendar pages filename
|
# a birthday
|
||||||
# using yyyymmdd for filename
|
if event == 'birthday':
|
||||||
two_digit_month = '%02d' % month
|
if years == 1:
|
||||||
two_digit_day = '%02d' % day
|
txt_str = _('%(short_name)s, <em>%(age)d</em> year old') % {
|
||||||
fname_date = str(year) + str(two_digit_month) + str(two_digit_day)
|
'short_name' : text,
|
||||||
|
'age' : years}
|
||||||
|
elif 2 <= years <= 105:
|
||||||
|
txt_str = _('%(short_name)s, <em>%(age)d</em> years old') % {
|
||||||
|
'short_name' : text,
|
||||||
|
'age' : years}
|
||||||
|
|
||||||
# define names for long and short month
|
# TODO. Think about this limit a bit more.
|
||||||
lng_month = _get_long_month_name(month)
|
# if age is greater than 105,
|
||||||
|
# STOP! Do Nothing!!!
|
||||||
|
else:
|
||||||
|
txt_str = None
|
||||||
|
|
||||||
# Name the file, and create it (see code in calendar_build)
|
# an anniversary
|
||||||
fpath = os.path.join(str(year), lng_month)
|
elif event == 'anniversary':
|
||||||
of = self.create_file(fname_date, fpath)
|
|
||||||
|
|
||||||
nr_up = 2 # number of directory levels up to get to root
|
# if married years is less than 76 years
|
||||||
|
if 1 <= years < 75:
|
||||||
|
txt_str = _('%(couple)s, <em>%(nyears)d</em> year anniversary') % {
|
||||||
|
'couple' : text,
|
||||||
|
'nyears' : years}
|
||||||
|
txt_str = '<span class="yearsmarried">%s</span>' % txt_str
|
||||||
|
|
||||||
# set date display as in user prevferences
|
# TODO. Think about this limit a bit more.
|
||||||
my_date = gen.lib.Date()
|
# if married years is greater than 75 years,
|
||||||
my_date.set_yr_mon_day(year, month, day)
|
# STOP! Do Nothing!!!
|
||||||
my_date = _dd.display(my_date)
|
else:
|
||||||
|
txt_str = None
|
||||||
|
|
||||||
self.calendar_common(of, nr_up, year, lng_month, _('One Day Within A Year'), my_date)
|
# incomplete date
|
||||||
|
else:
|
||||||
|
txt_str = None
|
||||||
|
|
||||||
of.write('\t<h3 id="OneDay">%s</h3>\n' % my_date)
|
if txt_str is not None:
|
||||||
|
day_list.append((date, txt_str, event))
|
||||||
|
|
||||||
# for both "WebCal" and "One Day"
|
# something for this day
|
||||||
of.write('\t\t\t\t\t<ul>\n')
|
if day_list > []:
|
||||||
for nyears, date, text, event in day_list:
|
|
||||||
of.write('\t\t\t\t\t\t<li>%s</li>\n' % text)
|
|
||||||
of.write('\t\t\t\t\t</ul>\n')
|
|
||||||
|
|
||||||
# if calendar is one_day(), write footer, and close the file
|
if cal == 'yg':
|
||||||
if one_day_cal == "OneDay":
|
|
||||||
self.write_footer(of, nr_up)
|
# This is a one_day in the year-at-a-glance calendar
|
||||||
self.close_file(of)
|
|
||||||
|
# slice up event_date to get year, month, and day
|
||||||
|
year, month, day = event_date[0], event_date[1], event_date[2]
|
||||||
|
|
||||||
|
# define names for long and short month
|
||||||
|
lng_month = _get_long_month_name(month)
|
||||||
|
shrt_month = _get_short_month_name(month)
|
||||||
|
|
||||||
|
# Name the file, and create it (see code in calendar_build)
|
||||||
|
cal_fname = '%s%d%s' % (shrt_month, day, self.ext)
|
||||||
|
fpath = os.path.join(str(year), lng_month)
|
||||||
|
of = self.create_file(cal_fname, fpath)
|
||||||
|
|
||||||
|
# set date display as in user prevferences
|
||||||
|
my_date = gen.lib.Date()
|
||||||
|
my_date.set_yr_mon_day(year, month, day)
|
||||||
|
my_date = _dd.display(my_date)
|
||||||
|
|
||||||
|
self.calendar_common(of, 2, year, lng_month, _('One Day Within A Year'), my_date)
|
||||||
|
|
||||||
|
of.write('\t<h3 id="OneDay">%s</h3>\n' % my_date)
|
||||||
|
|
||||||
|
of.write('\t<ul>\n')
|
||||||
|
for date, text, event in day_list:
|
||||||
|
of.write('\t\t<li>%s</li>\n' % text)
|
||||||
|
of.write('\t</ul>\n')
|
||||||
|
|
||||||
|
# Only close the file for "Year At A Glance"
|
||||||
|
if cal == 'yg':
|
||||||
|
self.write_footer(of, 2)
|
||||||
|
self.close_file(of)
|
||||||
|
|
||||||
|
# Let caller know we did output something.
|
||||||
|
return day_list > []
|
||||||
|
|
||||||
|
def blank_year(self, year):
|
||||||
|
"""
|
||||||
|
This method will create the Printable Full Year One Page Calendar...
|
||||||
|
"""
|
||||||
|
|
||||||
|
nr_up = 1 # Number of directory levels up to get to root
|
||||||
|
|
||||||
|
# Name the file, and create it
|
||||||
|
cal_fname = 'blankyear'
|
||||||
|
of = self.create_file(cal_fname, str(year))
|
||||||
|
|
||||||
|
# Page Title
|
||||||
|
if not self.multiyear:
|
||||||
|
title = ' '.join([str(year), _(' Blank Calendar')])
|
||||||
|
else:
|
||||||
|
title = _('Blank Calendar')
|
||||||
|
|
||||||
|
self.calendar_common(of, nr_up, year, 'blankyear', title, 'fullyear')
|
||||||
|
|
||||||
|
# generate progress pass for "Blank Year"
|
||||||
|
self.progress.set_pass(_('Creating Blank Year calendars'), self.end_month - self.start_month)
|
||||||
|
|
||||||
|
for month in range(self.start_month, self.end_month + 1):
|
||||||
|
|
||||||
|
# build the calendar
|
||||||
|
self.calendar_build(of, "by", year, month)
|
||||||
|
|
||||||
|
of.write('<tfoot>\n')
|
||||||
|
of.write('\t<tr><td colspan="7"></td></tr>\n')
|
||||||
|
of.write('</tfoot>\n')
|
||||||
|
of.write('</table>\n\n')
|
||||||
|
|
||||||
|
# increase progress bar
|
||||||
|
self.progress.step()
|
||||||
|
|
||||||
|
# Write footer and close file
|
||||||
|
self.write_footer(of, nr_up)
|
||||||
|
self.close_file(of)
|
||||||
|
|
||||||
def year_glance(self, year):
|
def year_glance(self, year):
|
||||||
"""
|
"""
|
||||||
@@ -923,6 +1016,9 @@ class WebCalReport(Report):
|
|||||||
of.write('</p>\n')
|
of.write('</p>\n')
|
||||||
of.write('</div>\n\n')
|
of.write('</div>\n\n')
|
||||||
|
|
||||||
|
# generate progress pass for "Year At A Glance"
|
||||||
|
self.progress.set_pass(_('Creating Year At A Glance calendars'), self.end_month - self.start_month)
|
||||||
|
|
||||||
for month in range(self.start_month, self.end_month + 1):
|
for month in range(self.start_month, self.end_month + 1):
|
||||||
|
|
||||||
# build the calendar
|
# build the calendar
|
||||||
@@ -938,7 +1034,7 @@ class WebCalReport(Report):
|
|||||||
of.write('\t</tfoot>\n')
|
of.write('\t</tfoot>\n')
|
||||||
of.write('</table>\n\n')
|
of.write('</table>\n\n')
|
||||||
|
|
||||||
# increment progress bar
|
# increase progress bar
|
||||||
self.progress.step()
|
self.progress.step()
|
||||||
|
|
||||||
# write footer section, and close file
|
# write footer section, and close file
|
||||||
@@ -954,12 +1050,20 @@ class WebCalReport(Report):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# open progress meter bar
|
# open progress meter bar
|
||||||
self.progress = Utils.ProgressMeter(_("Web Calendar Report"), '')
|
self.progress = Utils.ProgressMeter(_("Generate XHTML Calendars"), '')
|
||||||
|
|
||||||
# get data from database for birthdays/ anniversaries
|
# get data from database for birthdays/ anniversaries
|
||||||
# TODO. Verify that we collect correct info based on start_year
|
# TODO. Verify that we collect correct info based on start_year
|
||||||
self.collect_data(self.start_year)
|
self.collect_data(self.start_year)
|
||||||
|
|
||||||
|
if self.css == "Web_Mainz.css":
|
||||||
|
# Copy Mainz Style Images
|
||||||
|
self.imgs += ["Web_Mainz_Bkgd.png",
|
||||||
|
"Web_Mainz_Header.png",
|
||||||
|
"Web_Mainz_Mid.png",
|
||||||
|
"Web_Mainz_MidLight.png",
|
||||||
|
]
|
||||||
|
|
||||||
# Copy all files for the calendars being created
|
# Copy all files for the calendars being created
|
||||||
self.copy_calendar_files()
|
self.copy_calendar_files()
|
||||||
|
|
||||||
@@ -992,6 +1096,10 @@ class WebCalReport(Report):
|
|||||||
# create "WebCal" calendar pages
|
# create "WebCal" calendar pages
|
||||||
self.normal_cal(cal_year)
|
self.normal_cal(cal_year)
|
||||||
|
|
||||||
|
# create "Blank Year" calendar page
|
||||||
|
if self.blankyear:
|
||||||
|
self.blank_year(cal_year)
|
||||||
|
|
||||||
# create "Year At A Glance" and "One Day" calendar pages
|
# create "Year At A Glance" and "One Day" calendar pages
|
||||||
if self.fullyear:
|
if self.fullyear:
|
||||||
self.year_glance(cal_year)
|
self.year_glance(cal_year)
|
||||||
@@ -1019,6 +1127,10 @@ class WebCalReport(Report):
|
|||||||
# create "WebCal" calendar pages
|
# create "WebCal" calendar pages
|
||||||
self.normal_cal(cal_year)
|
self.normal_cal(cal_year)
|
||||||
|
|
||||||
|
# create "Blank Year" calendar page
|
||||||
|
if self.blankyear:
|
||||||
|
self.blank_year(cal_year)
|
||||||
|
|
||||||
# create "Year At A Glance"
|
# create "Year At A Glance"
|
||||||
if self.fullyear:
|
if self.fullyear:
|
||||||
self.year_glance(cal_year)
|
self.year_glance(cal_year)
|
||||||
@@ -1031,9 +1143,6 @@ class WebCalReport(Report):
|
|||||||
This method provides information and header/ footer to the calendar month
|
This method provides information and header/ footer to the calendar month
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# define progress bar pass
|
|
||||||
self.progress.set_pass(_('Creating Calendars ...'), 12)
|
|
||||||
|
|
||||||
# do some error correcting if needed
|
# do some error correcting if needed
|
||||||
if self.multiyear:
|
if self.multiyear:
|
||||||
if self.end_year < self.start_year:
|
if self.end_year < self.start_year:
|
||||||
@@ -1042,6 +1151,9 @@ class WebCalReport(Report):
|
|||||||
|
|
||||||
nr_up = 1 # Number of directory levels up to get to self.html_dir / root
|
nr_up = 1 # Number of directory levels up to get to self.html_dir / root
|
||||||
|
|
||||||
|
# generate progress pass for "WebCal"
|
||||||
|
self.progress.set_pass(_('Creating WebCal calendars'), self.end_month - self.start_month)
|
||||||
|
|
||||||
for month in range(self.start_month, self.end_month + 1):
|
for month in range(self.start_month, self.end_month + 1):
|
||||||
|
|
||||||
# Name the file, and create it
|
# Name the file, and create it
|
||||||
@@ -1095,16 +1207,18 @@ class WebCalReport(Report):
|
|||||||
if birth_ref:
|
if birth_ref:
|
||||||
birth_event = self.database.get_event_from_handle(birth_ref.ref)
|
birth_event = self.database.get_event_from_handle(birth_ref.ref)
|
||||||
birth_date = birth_event.get_date_object()
|
birth_date = birth_event.get_date_object()
|
||||||
|
death_ref = person.get_death_ref()
|
||||||
|
death_date = None
|
||||||
|
if death_ref:
|
||||||
|
death_event = self.database.get_event_from_handle(death_ref.ref)
|
||||||
|
death_date = death_event.get_date_object()
|
||||||
|
|
||||||
# determine birthday information???
|
# if person is dead, STOP! Nothing further to do
|
||||||
if self.birthday and birth_date is not None:
|
if death_date == None:
|
||||||
|
living = probably_alive(person, self.database, _make_date(this_year, 1, 1), 0)
|
||||||
# determine if birthdadate is a valid date???
|
|
||||||
complete_date = False
|
|
||||||
if birth_date.is_valid():
|
|
||||||
complete_date = True
|
|
||||||
if complete_date:
|
|
||||||
|
|
||||||
|
# add birthday if requested
|
||||||
|
if self.birthday and birth_date != None and ((self.alive and living) or not self.alive):
|
||||||
year = birth_date.get_year()
|
year = birth_date.get_year()
|
||||||
month = birth_date.get_month()
|
month = birth_date.get_month()
|
||||||
day = birth_date.get_day()
|
day = birth_date.get_day()
|
||||||
@@ -1129,50 +1243,48 @@ class WebCalReport(Report):
|
|||||||
father_name = father.get_primary_name()
|
father_name = father.get_primary_name()
|
||||||
father_lastname = _get_regular_surname(sex, father_name)
|
father_lastname = _get_regular_surname(sex, father_name)
|
||||||
short_name = _get_short_name(person, father_lastname)
|
short_name = _get_short_name(person, father_lastname)
|
||||||
alive = probably_alive(person, self.database, _make_date(this_year, month, day))
|
# Huh? Why translate this?
|
||||||
text = _('%(short_name)s') % {'short_name' : short_name}
|
text = _('%(short_name)s') % {'short_name' : short_name}
|
||||||
if ((self.alive and alive) or not self.alive):
|
self.add_day_item(text, year, month, day, 'birthday')
|
||||||
self.add_day_item(text, year, month, day, 'Birthday')
|
|
||||||
|
|
||||||
# add anniversary if requested
|
# add anniversary if requested
|
||||||
if self.anniv:
|
if self.anniv and ((self.alive and living) or not self.alive):
|
||||||
for fhandle in family_list:
|
for fhandle in family_list:
|
||||||
fam = self.database.get_family_from_handle(fhandle)
|
fam = self.database.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.get_handle():
|
if father_handle == person.get_handle():
|
||||||
spouse_handle = mother_handle
|
spouse_handle = mother_handle
|
||||||
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 = self.database.get_person_from_handle(spouse_handle)
|
||||||
if spouse:
|
if spouse:
|
||||||
spouse_name = _get_short_name(spouse)
|
death_ref = spouse.get_death_ref()
|
||||||
short_name = _get_short_name(person)
|
death_date = None
|
||||||
|
if death_ref:
|
||||||
|
death_event = self.database.get_event_from_handle(death_ref.ref)
|
||||||
|
death_date = death_event.get_date_object()
|
||||||
|
|
||||||
are_married = get_marrital_status(fam, self.database)
|
# if spouse is dead, STOP! Nothing more to do!
|
||||||
if are_married is not None:
|
if death_date == None:
|
||||||
for event_ref in fam.get_event_ref_list():
|
spouse_name = _get_short_name(spouse)
|
||||||
event = self.database.get_event_from_handle(event_ref.ref)
|
short_name = _get_short_name(person)
|
||||||
event_obj = event.get_date_object()
|
if self.alive:
|
||||||
year = event_obj.get_year()
|
if not probably_alive(spouse, self.database, _make_date(this_year, 1, 1), 0):
|
||||||
month = event_obj.get_month()
|
continue
|
||||||
day = event_obj.get_day()
|
are_married = _get_marrital_status(fam, self.database)
|
||||||
|
if are_married is not None:
|
||||||
# determine if anniversary date is a valid date???
|
for event_ref in fam.get_event_ref_list():
|
||||||
complete_date = False
|
event = self.database.get_event_from_handle(event_ref.ref)
|
||||||
if event_obj.get_valid():
|
event_obj = event.get_date_object()
|
||||||
complete_date = True
|
year = event_obj.get_year()
|
||||||
if complete_date:
|
month = event_obj.get_month()
|
||||||
|
day = event_obj.get_day()
|
||||||
text = _('%(spouse)s and %(person)s') % {
|
text = _('%(spouse)s and %(person)s') % {
|
||||||
'spouse' : spouse_name,
|
'spouse' : spouse_name,
|
||||||
'person' : short_name}
|
'person' : short_name}
|
||||||
|
self.add_day_item(text, year, month, day, 'anniversary')
|
||||||
alive1 = probably_alive(person, self.database, _make_date(this_year, month, day))
|
|
||||||
alive2 = probably_alive(spouse, self.database, _make_date(this_year, month, day))
|
|
||||||
if ((self.alive and alive1 and alive2) or not self.alive):
|
|
||||||
self.add_day_item(text, year, month, day, 'Anniversary')
|
|
||||||
|
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@@ -1287,6 +1399,10 @@ class WebCalOptions(MenuReportOptions):
|
|||||||
fullyear.set_help(_('Whether to create A one-page mini calendar with dates highlighted'))
|
fullyear.set_help(_('Whether to create A one-page mini calendar with dates highlighted'))
|
||||||
menu.add_option(category_name, 'fullyear', fullyear)
|
menu.add_option(category_name, 'fullyear', fullyear)
|
||||||
|
|
||||||
|
blankyear = BooleanOption(_('Create "Printable Blank" Calendar(s)'), False)
|
||||||
|
blankyear.set_help(_('Whether to create A Full Year Printable calendar'))
|
||||||
|
menu.add_option(category_name, 'blankyear', blankyear)
|
||||||
|
|
||||||
country = EnumeratedListOption(_('Country for holidays'), 0 )
|
country = EnumeratedListOption(_('Country for holidays'), 0 )
|
||||||
for index, item in enumerate(_COUNTRIES):
|
for index, item in enumerate(_COUNTRIES):
|
||||||
country.add_item(index, item)
|
country.add_item(index, item)
|
||||||
@@ -1782,6 +1898,12 @@ def _get_marrital_status(family, db):
|
|||||||
are_married = None
|
are_married = None
|
||||||
return are_married
|
return are_married
|
||||||
|
|
||||||
|
def _has_webpage_extension(fname):
|
||||||
|
for ext in ('.html', '.htm' '.shtml', '.cgi', '.php', '.php3'):
|
||||||
|
if fname.endswith(ext):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
# Simple utility list to convert Gramps day-of-week numbering to calendar.firstweekday numbering
|
# Simple utility list to convert Gramps day-of-week numbering to calendar.firstweekday numbering
|
||||||
_dow_gramps2iso = [ -1, calendar.SUNDAY, calendar.MONDAY, calendar.TUESDAY, calendar.WEDNESDAY, calendar.THURSDAY, calendar.FRIDAY, calendar.SATURDAY ]
|
_dow_gramps2iso = [ -1, calendar.SUNDAY, calendar.MONDAY, calendar.TUESDAY, calendar.WEDNESDAY, calendar.THURSDAY, calendar.FRIDAY, calendar.SATURDAY ]
|
||||||
|
|
||||||
@@ -1801,91 +1923,6 @@ def _get_long_month_name(month):
|
|||||||
def _get_short_month_name(month):
|
def _get_short_month_name(month):
|
||||||
return _shrt_month[month]
|
return _shrt_month[month]
|
||||||
|
|
||||||
def fill_day_list(event_date, holiday_list, bday_anniv_list):
|
|
||||||
"""
|
|
||||||
Will fill day_list and return it to its caller one_day()
|
|
||||||
|
|
||||||
holiday_list, or bday_anniv_list -- will always have something in it...
|
|
||||||
|
|
||||||
event_date -- date for this day_list
|
|
||||||
|
|
||||||
'day_list' - a combination of both dictionaries to be able to create one day
|
|
||||||
nyears, date, text, event --- are necessary for figuring the age or years married
|
|
||||||
for each year being created...
|
|
||||||
"""
|
|
||||||
|
|
||||||
# initialize day_list
|
|
||||||
day_list = []
|
|
||||||
|
|
||||||
# holiday on this day
|
|
||||||
if holiday_list > []:
|
|
||||||
|
|
||||||
# will force holidays to be first in the list
|
|
||||||
nyears = 0
|
|
||||||
|
|
||||||
for p in holiday_list:
|
|
||||||
for line in p.splitlines():
|
|
||||||
day_list.append((nyears, event_date, line, _('Holiday')))
|
|
||||||
|
|
||||||
# birthday/ anniversary on this day
|
|
||||||
if bday_anniv_list > []:
|
|
||||||
for date, text, event in bday_anniv_list:
|
|
||||||
|
|
||||||
# '...' signifies an incomplete date for an event. See add_day_item()
|
|
||||||
txt_str = None
|
|
||||||
if date != '...':
|
|
||||||
years = event_date.year - date.get_year()
|
|
||||||
|
|
||||||
# a birthday
|
|
||||||
if event == 'Birthday':
|
|
||||||
|
|
||||||
if years is 1:
|
|
||||||
txt_str = _('%(person)s, <em>%(age)d</em> year old') % {
|
|
||||||
'person' : text,
|
|
||||||
'age' : years}
|
|
||||||
elif years > 1:
|
|
||||||
txt_str = _('%(person)s, <em>%(age)d</em> years old') % {
|
|
||||||
'person' : text,
|
|
||||||
'age' : years}
|
|
||||||
|
|
||||||
# an anniversary
|
|
||||||
elif event == 'Anniversary':
|
|
||||||
|
|
||||||
txt_str = _('%(couple)s, <em>%(years)d</em> year anniversary') % {
|
|
||||||
'couple' : text,
|
|
||||||
'years' : years}
|
|
||||||
txt_str = '<span class="yearsmarried">%s</span>' % txt_str
|
|
||||||
|
|
||||||
if txt_str is not None:
|
|
||||||
day_list.append((years, date, txt_str, event))
|
|
||||||
|
|
||||||
# if there is more than one event on any given date, sort them based on years
|
|
||||||
# for birthdays and anniversaries.
|
|
||||||
# holidays will always appear first in the list.
|
|
||||||
if len(day_list) > 1:
|
|
||||||
day_list.sort()
|
|
||||||
|
|
||||||
return day_list
|
|
||||||
|
|
||||||
def get_marrital_status(family, db):
|
|
||||||
"""
|
|
||||||
Returns the marital status of two people, a couple
|
|
||||||
|
|
||||||
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():
|
|
||||||
event = db.get_event_from_handle(event_ref.ref)
|
|
||||||
if event.type in [gen.lib.EventType.MARRIAGE,
|
|
||||||
gen.lib.EventType.MARR_ALT]:
|
|
||||||
are_married = event
|
|
||||||
elif event.type in [gen.lib.EventType.DIVORCE,
|
|
||||||
gen.lib.EventType.ANNULMENT,
|
|
||||||
gen.lib.EventType.DIV_FILING]:
|
|
||||||
are_married = None
|
|
||||||
return are_married
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
Reference in New Issue
Block a user