2007-08-27 09:22:06 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2008-02-10 09:39:09 +05:30
|
|
|
# Copyright (C) 2007 Thom Sturgill
|
2009-01-30 07:49:04 +05:30
|
|
|
# Copyright (C) 2007-2009 Brian G. Matherly
|
2008-07-17 18:35:15 +05:30
|
|
|
# Copyright (C) 2008 Rob G. Healey <robhealey1@gmail.com>
|
2009-01-30 07:49:04 +05:30
|
|
|
# Copyright (C) 2008 Jason Simanek
|
|
|
|
# Copyright (C) 2008 Kees Bakker
|
2007-08-27 09:22:06 +05:30
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Pubilc License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
|
|
|
|
# $Id$
|
|
|
|
|
|
|
|
"""
|
|
|
|
Web Calendar generator.
|
2008-01-29 13:10:35 +05:30
|
|
|
|
2008-11-11 03:11:38 +05:30
|
|
|
Refactoring. This is an ongoing job until this plugin is in a better shape.
|
|
|
|
TODO list:
|
2009-01-27 04:27:25 +05:30
|
|
|
- change filename for one_day pages to yyyy/mm/dd.html (just numbers)
|
2008-11-11 03:11:38 +05:30
|
|
|
- progress bar, rethink its usage
|
2008-12-05 02:08:02 +05:30
|
|
|
- in year navigation, use month in link, or 'fullyear'
|
2008-11-11 03:11:38 +05:30
|
|
|
- untangle calendar_build, it's too complex the way it is
|
2008-12-05 02:08:02 +05:30
|
|
|
- use standard Gramps method to display surname, see _get_regular_surname
|
2008-11-11 03:11:38 +05:30
|
|
|
- daylight saving not just for USA and Europe
|
2008-11-11 04:17:48 +05:30
|
|
|
- move the close_file() from one_day() to caller
|
2007-08-27 09:22:06 +05:30
|
|
|
"""
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# python modules
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
import os
|
|
|
|
import time
|
|
|
|
import datetime
|
2008-07-17 18:35:15 +05:30
|
|
|
import calendar
|
2007-08-27 09:22:06 +05:30
|
|
|
import codecs
|
|
|
|
import shutil
|
|
|
|
from gettext import gettext as _
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Set up logging
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
import logging
|
|
|
|
log = logging.getLogger(".WebPage")
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS module
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2007-10-08 22:11:39 +05:30
|
|
|
import gen.lib
|
2007-08-27 09:22:06 +05:30
|
|
|
import const
|
|
|
|
from GrampsCfg import get_researcher
|
2008-10-02 09:32:10 +05:30
|
|
|
from gen.plug import PluginManager
|
|
|
|
from ReportBase import Report, ReportUtils, MenuReportOptions, CATEGORY_WEB
|
2008-09-27 19:26:17 +05:30
|
|
|
from gen.plug.menu import BooleanOption, NumberOption, StringOption, \
|
|
|
|
EnumeratedListOption, FilterOption, PersonOption, \
|
|
|
|
DestinationOption
|
2007-08-27 09:22:06 +05:30
|
|
|
import Utils
|
|
|
|
import GrampsLocale
|
2009-01-30 07:49:04 +05:30
|
|
|
from QuestionDialog import WarningDialog
|
2007-08-27 09:22:06 +05:30
|
|
|
from Utils import probably_alive
|
2008-07-17 18:35:15 +05:30
|
|
|
from DateHandler import displayer as _dd
|
|
|
|
from DateHandler import parser as _dp
|
2007-08-27 09:22:06 +05:30
|
|
|
|
2009-01-30 07:49:04 +05:30
|
|
|
import libholiday
|
|
|
|
|
2007-08-27 09:22:06 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# constants
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2008-07-17 18:35:15 +05:30
|
|
|
|
|
|
|
# This information defines the list of styles in the Web calendar
|
|
|
|
# options dialog as well as the location of the corresponding SCREEN
|
|
|
|
# stylesheets.
|
|
|
|
_CSS_FILES = [
|
|
|
|
# First is used as default selection.
|
2008-10-22 00:27:42 +05:30
|
|
|
[_("Basic-Ash"), 'Web_Basic-Ash.css'],
|
|
|
|
[_("Basic-Cypress"), 'Web_Basic-Cypress.css'],
|
|
|
|
[_("Basic-Lilac"), 'Web_Basic-Lilac.css'],
|
|
|
|
[_("Basic-Peach"), 'Web_Basic-Peach.css'],
|
|
|
|
[_("Basic-Spruce"), 'Web_Basic-Spruce.css'],
|
|
|
|
[_("Mainz"), 'Web_Mainz.css'],
|
|
|
|
[_("Nebraska"), 'Web_Nebraska.css'],
|
|
|
|
[_("Visually Impaired"), 'Web_Visually.css'],
|
2008-11-11 03:11:38 +05:30
|
|
|
[_("No style sheet"), ''],
|
2008-07-17 18:35:15 +05:30
|
|
|
]
|
2007-08-27 09:22:06 +05:30
|
|
|
|
2008-02-10 09:39:09 +05:30
|
|
|
_CHARACTER_SETS = [
|
2008-07-17 20:18:54 +05:30
|
|
|
# First is used as default selection.
|
2007-08-27 09:22:06 +05:30
|
|
|
[_('Unicode (recommended)'), 'utf-8'],
|
|
|
|
['ISO-8859-1', 'iso-8859-1' ],
|
|
|
|
['ISO-8859-2', 'iso-8859-2' ],
|
|
|
|
['ISO-8859-3', 'iso-8859-3' ],
|
|
|
|
['ISO-8859-4', 'iso-8859-4' ],
|
|
|
|
['ISO-8859-5', 'iso-8859-5' ],
|
|
|
|
['ISO-8859-6', 'iso-8859-6' ],
|
|
|
|
['ISO-8859-7', 'iso-8859-7' ],
|
|
|
|
['ISO-8859-8', 'iso-8859-8' ],
|
|
|
|
['ISO-8859-9', 'iso-8859-9' ],
|
|
|
|
['ISO-8859-10', 'iso-8859-10' ],
|
|
|
|
['ISO-8859-13', 'iso-8859-13' ],
|
|
|
|
['ISO-8859-14', 'iso-8859-14' ],
|
|
|
|
['ISO-8859-15', 'iso-8859-15' ],
|
|
|
|
['koi8_r', 'koi8_r', ],
|
|
|
|
]
|
|
|
|
|
2008-02-10 09:39:09 +05:30
|
|
|
_CC = [
|
2008-07-17 20:18:54 +05:30
|
|
|
'',
|
|
|
|
|
2008-02-10 09:39:09 +05:30
|
|
|
'<a rel="license" href="http://creativecommons.org/licenses/by/2.5/">'
|
2008-07-17 20:18:54 +05:30
|
|
|
'<img alt="Creative Commons License - By attribution" '
|
|
|
|
'title="Creative Commons License - By attribution" '
|
|
|
|
'src="%(gif_fname)s" /></a>',
|
|
|
|
|
2008-02-10 09:39:09 +05:30
|
|
|
'<a rel="license" href="http://creativecommons.org/licenses/by-nd/2.5/">'
|
|
|
|
'<img alt="Creative Commons License - By attribution, No derivations" '
|
2008-07-17 20:18:54 +05:30
|
|
|
'title="Creative Commons License - By attribution, No derivations" '
|
|
|
|
'src="%(gif_fname)s" /></a>',
|
|
|
|
|
2008-02-10 09:39:09 +05:30
|
|
|
'<a rel="license" href="http://creativecommons.org/licenses/by-sa/2.5/">'
|
|
|
|
'<img alt="Creative Commons License - By attribution, Share-alike" '
|
2008-07-17 20:18:54 +05:30
|
|
|
'title="Creative Commons License - By attribution, Share-alike" '
|
|
|
|
'src="%(gif_fname)s" /></a>',
|
|
|
|
|
2008-02-10 09:39:09 +05:30
|
|
|
'<a rel="license" href="http://creativecommons.org/licenses/by-nc/2.5/">'
|
|
|
|
'<img alt="Creative Commons License - By attribution, Non-commercial" '
|
2008-07-17 20:18:54 +05:30
|
|
|
'title="Creative Commons License - By attribution, Non-commercial" '
|
|
|
|
'src="%(gif_fname)s" /></a>',
|
|
|
|
|
2008-02-10 09:39:09 +05:30
|
|
|
'<a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/2.5/">'
|
2008-07-17 20:18:54 +05:30
|
|
|
'<img alt="Creative Commons License - By attribution, Non-commercial, No derivations" '
|
|
|
|
'title="Creative Commons License - By attribution, Non-commercial, No derivations" '
|
|
|
|
'src="%(gif_fname)s" /></a>',
|
|
|
|
|
2008-02-10 09:39:09 +05:30
|
|
|
'<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/2.5/">'
|
2008-07-17 20:18:54 +05:30
|
|
|
'<img alt="Creative Commons License - By attribution, Non-commerical, Share-alike" '
|
|
|
|
'title="Creative Commons License - By attribution, Non-commerical, Share-alike" '
|
|
|
|
'src="%(gif_fname)s" /></a>'
|
2007-08-27 09:22:06 +05:30
|
|
|
]
|
|
|
|
|
2008-02-10 09:39:09 +05:30
|
|
|
_COPY_OPTIONS = [
|
|
|
|
_('Standard copyright'),
|
2008-07-17 20:18:54 +05:30
|
|
|
|
2008-11-11 03:11:38 +05:30
|
|
|
# This must match _CC
|
2008-02-10 09:39:09 +05:30
|
|
|
_('Creative Commons - By attribution'),
|
|
|
|
_('Creative Commons - By attribution, No derivations'),
|
|
|
|
_('Creative Commons - By attribution, Share-alike'),
|
|
|
|
_('Creative Commons - By attribution, Non-commercial'),
|
|
|
|
_('Creative Commons - By attribution, Non-commercial, No derivations'),
|
|
|
|
_('Creative Commons - By attribution, Non-commercial, Share-alike'),
|
2008-07-17 20:18:54 +05:30
|
|
|
|
2008-02-10 09:39:09 +05:30
|
|
|
_('No copyright notice'),
|
|
|
|
]
|
|
|
|
|
2008-08-05 00:38:31 +05:30
|
|
|
def _make_date(year, month, day):
|
2007-12-15 21:19:53 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Return a Date object of the particular year/month/day.
|
2007-12-15 21:19:53 +05:30
|
|
|
"""
|
|
|
|
retval = gen.lib.Date()
|
|
|
|
retval.set_yr_mon_day(year, month, day)
|
|
|
|
return retval
|
|
|
|
|
2007-08-27 09:22:06 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
2008-02-10 09:39:09 +05:30
|
|
|
# WebCalReport
|
2007-08-27 09:22:06 +05:30
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2008-02-10 09:39:09 +05:30
|
|
|
class WebCalReport(Report):
|
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Create WebCalReport object that produces the report.
|
2008-02-10 09:39:09 +05:30
|
|
|
"""
|
2008-02-20 10:22:10 +05:30
|
|
|
def __init__(self, database, options):
|
|
|
|
Report.__init__(self, database, options)
|
2008-02-10 09:39:09 +05:30
|
|
|
menu = options.menu
|
2008-07-17 20:18:54 +05:30
|
|
|
|
2007-08-27 09:22:06 +05:30
|
|
|
self.database = database
|
|
|
|
self.options = options
|
2008-07-17 20:18:54 +05:30
|
|
|
|
2008-02-10 09:39:09 +05:30
|
|
|
self.html_dir = menu.get_option_by_name('target').get_value()
|
2008-10-08 01:41:46 +05:30
|
|
|
self.title_text = menu.get_option_by_name('title').get_value()
|
2008-02-10 09:39:09 +05:30
|
|
|
filter_option = menu.get_option_by_name('filter')
|
|
|
|
self.filter = filter_option.get_filter()
|
|
|
|
self.ext = menu.get_option_by_name('ext').get_value()
|
|
|
|
self.copy = menu.get_option_by_name('cright').get_value()
|
|
|
|
self.encoding = menu.get_option_by_name('encoding').get_value()
|
2008-07-17 18:35:15 +05:30
|
|
|
self.css = menu.get_option_by_name('css').get_value()
|
2008-10-08 01:41:46 +05:30
|
|
|
|
2008-07-17 20:18:54 +05:30
|
|
|
self.country = menu.get_option_by_name('country').get_value()
|
2008-08-08 02:30:05 +05:30
|
|
|
self.start_dow = menu.get_option_by_name('start_dow').get_value()
|
2008-10-08 01:41:46 +05:30
|
|
|
|
|
|
|
self.partyear = menu.get_option_by_name('partyear').get_value()
|
|
|
|
self.multiyear = menu.get_option_by_name('multiyear').get_value()
|
|
|
|
|
|
|
|
self.start_year = menu.get_option_by_name('start_year').get_value()
|
|
|
|
self.end_year = menu.get_option_by_name('end_year').get_value()
|
|
|
|
|
2008-07-17 18:35:15 +05:30
|
|
|
self.fullyear = menu.get_option_by_name('fullyear').get_value()
|
2008-10-08 01:41:46 +05:30
|
|
|
|
|
|
|
self.maiden_name = menu.get_option_by_name('maiden_name').get_value()
|
|
|
|
|
2008-07-17 20:18:54 +05:30
|
|
|
self.alive = menu.get_option_by_name('alive').get_value()
|
|
|
|
self.birthday = menu.get_option_by_name('birthdays').get_value()
|
|
|
|
self.anniv = menu.get_option_by_name('anniversaries').get_value()
|
2008-08-12 01:49:51 +05:30
|
|
|
self.home_link = menu.get_option_by_name('home_link').get_value().strip()
|
2008-07-17 20:18:54 +05:30
|
|
|
|
|
|
|
self.month_notes = [menu.get_option_by_name('note_jan').get_value(),
|
|
|
|
menu.get_option_by_name('note_feb').get_value(),
|
|
|
|
menu.get_option_by_name('note_mar').get_value(),
|
|
|
|
menu.get_option_by_name('note_apr').get_value(),
|
|
|
|
menu.get_option_by_name('note_may').get_value(),
|
|
|
|
menu.get_option_by_name('note_jun').get_value(),
|
|
|
|
menu.get_option_by_name('note_jul').get_value(),
|
|
|
|
menu.get_option_by_name('note_aug').get_value(),
|
|
|
|
menu.get_option_by_name('note_sep').get_value(),
|
|
|
|
menu.get_option_by_name('note_oct').get_value(),
|
|
|
|
menu.get_option_by_name('note_nov').get_value(),
|
|
|
|
menu.get_option_by_name('note_dec').get_value()]
|
|
|
|
|
2008-10-08 01:41:46 +05:30
|
|
|
# identify researcher name and e-mail address
|
|
|
|
# as Narrated WebSite already does
|
|
|
|
researcher = get_researcher()
|
|
|
|
self.author = researcher.name
|
|
|
|
if self.author:
|
|
|
|
self.author = self.author.replace(',,,', '')
|
|
|
|
self.email = researcher.email
|
|
|
|
|
2009-01-30 07:49:04 +05:30
|
|
|
self.start_month = 1 # set to January, and it can change
|
|
|
|
self.end_month = 12 # set to December, this value never changes
|
2008-10-08 01:41:46 +05:30
|
|
|
|
|
|
|
today = time.localtime() # set to today's date
|
|
|
|
self.today = datetime.date(today[0], today[1], today[2])
|
|
|
|
|
2008-08-05 02:16:46 +05:30
|
|
|
self.warn_dir = True # Only give warning once.
|
2009-01-27 04:27:25 +05:30
|
|
|
self.imgs = []
|
2008-07-31 03:07:24 +05:30
|
|
|
|
2008-11-11 03:11:38 +05:30
|
|
|
# self.calendar is a dict; key is the month number
|
|
|
|
# Each entry in the dict is also a dict; key is the day number.
|
|
|
|
# The day dict is a list of things to display for that day.
|
|
|
|
# These things are: birthdays and anniversaries
|
|
|
|
self.calendar = {}
|
|
|
|
|
2008-08-12 01:49:51 +05:30
|
|
|
calendar.setfirstweekday(_dow_gramps2iso[self.start_dow])
|
|
|
|
|
2008-07-17 20:18:54 +05:30
|
|
|
def copy_file(self, from_fname, to_fname, to_dir=''):
|
2008-07-17 18:35:15 +05:30
|
|
|
"""
|
2008-07-17 20:18:54 +05:30
|
|
|
Copy a file from a source to a (report) destination.
|
|
|
|
If to_dir is not present and if the target is not an archive,
|
|
|
|
then the destination directory will be created.
|
|
|
|
|
|
|
|
Normally 'to_fname' will be just a filename, without directory path.
|
|
|
|
|
|
|
|
'to_dir' is the relative path name in the destination root. It will
|
|
|
|
be prepended before 'to_fname'.
|
2008-07-17 18:35:15 +05:30
|
|
|
"""
|
2008-07-17 20:18:54 +05:30
|
|
|
dest = os.path.join(self.html_dir, to_dir, to_fname)
|
|
|
|
|
|
|
|
destdir = os.path.dirname(dest)
|
|
|
|
if not os.path.isdir(destdir):
|
|
|
|
os.makedirs(destdir)
|
|
|
|
|
|
|
|
if from_fname != dest:
|
|
|
|
shutil.copyfile(from_fname, dest)
|
2008-07-17 18:35:15 +05:30
|
|
|
elif self.warn_dir:
|
|
|
|
WarningDialog(
|
|
|
|
_("Possible destination error") + "\n" +
|
|
|
|
_("You appear to have set your target directory "
|
|
|
|
"to a directory used for data storage. This "
|
|
|
|
"could create problems with file management. "
|
|
|
|
"It is recommended that you consider using "
|
|
|
|
"a different directory to store your generated "
|
|
|
|
"web pages."))
|
|
|
|
self.warn_dir = False
|
|
|
|
|
2008-10-08 01:41:46 +05:30
|
|
|
def add_day_item(self, text, year, month, day, event):
|
2008-07-31 03:07:24 +05:30
|
|
|
if day == 0:
|
|
|
|
# This may happen for certain "about" dates.
|
|
|
|
day = 1 # Use first day of the month
|
2007-08-27 09:22:06 +05:30
|
|
|
month_dict = self.calendar.get(month, {})
|
|
|
|
day_list = month_dict.get(day, [])
|
2008-11-11 03:11:38 +05:30
|
|
|
|
2008-10-08 01:41:46 +05:30
|
|
|
if month > 0:
|
2008-11-11 03:11:38 +05:30
|
|
|
try:
|
2009-01-27 13:19:47 +05:30
|
|
|
my_date = _make_date(year, month, day)
|
2008-11-11 03:11:38 +05:30
|
|
|
except ValueError:
|
|
|
|
my_date = '...'
|
2008-10-08 01:41:46 +05:30
|
|
|
else:
|
2009-01-30 07:49:04 +05:30
|
|
|
my_date = '...' #Incomplete date as in about, circa, etc.
|
2008-11-11 03:11:38 +05:30
|
|
|
|
2009-01-27 13:19:47 +05:30
|
|
|
day_list.append((text, event, my_date))
|
2007-08-27 09:22:06 +05:30
|
|
|
month_dict[day] = day_list
|
|
|
|
self.calendar[month] = month_dict
|
|
|
|
|
2009-01-30 07:49:04 +05:30
|
|
|
def __get_holidays(self, year):
|
|
|
|
""" Get the holidays for the specified country and year """
|
|
|
|
holiday_table = libholiday.HolidayTable()
|
|
|
|
country = holiday_table.get_countries()[self.country]
|
|
|
|
holiday_table.load_holidays(year, country)
|
|
|
|
for month in range(1, 13):
|
|
|
|
for day in range(1, 32):
|
|
|
|
holiday_names = holiday_table.get_holidays(month, day)
|
|
|
|
for holiday_name in holiday_names:
|
|
|
|
self.add_holiday_item(holiday_name, year, month, day)
|
2007-08-27 09:22:06 +05:30
|
|
|
|
2008-11-11 03:11:38 +05:30
|
|
|
def add_holiday_item(self, text, year, month, day):
|
|
|
|
if day == 0:
|
|
|
|
# This may happen for certain "about" dates.
|
|
|
|
day = 1 # Use first day of the month
|
|
|
|
month_dict = self.holidays.get(month, {})
|
|
|
|
day_list = month_dict.get(day, [])
|
|
|
|
|
|
|
|
day_list.append(text)
|
|
|
|
month_dict[day] = day_list
|
|
|
|
self.holidays[month] = month_dict
|
|
|
|
|
2008-10-08 01:41:46 +05:30
|
|
|
def copy_calendar_files(self):
|
2007-08-27 09:22:06 +05:30
|
|
|
"""
|
2008-11-11 04:17:48 +05:30
|
|
|
Copies all the necessary files
|
2007-08-27 09:22:06 +05:30
|
|
|
"""
|
2009-01-27 04:27:25 +05:30
|
|
|
# Copy the normal stylesheet
|
2008-07-17 18:35:15 +05:30
|
|
|
if self.css != "":
|
2008-10-08 01:41:46 +05:30
|
|
|
fname = os.path.join(const.DATA_DIR, self.css)
|
2008-12-05 02:08:02 +05:30
|
|
|
self.copy_file(fname, self.css, "styles")
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2008-12-05 02:08:02 +05:30
|
|
|
# copy print stylesheet
|
2008-10-08 01:41:46 +05:30
|
|
|
fname = os.path.join(const.DATA_DIR, "Web_Print-Default.css")
|
2008-12-05 02:08:02 +05:30
|
|
|
self.copy_file(fname, "Web_Print-Default.css", "styles")
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2008-10-08 01:41:46 +05:30
|
|
|
# Copy GRAMPS favicon
|
2009-01-27 04:27:25 +05:30
|
|
|
fname = os.path.join(const.IMAGE_DIR, "favicon.ico")
|
|
|
|
self.copy_file(fname, "favicon.ico", "images")
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2008-10-08 01:41:46 +05:30
|
|
|
# copy copyright image
|
|
|
|
if 0 < self.copy < len(_CC):
|
2009-01-27 04:27:25 +05:30
|
|
|
fname = os.path.join(const.IMAGE_DIR, 'somerights20.gif')
|
|
|
|
self.copy_file(fname, 'somerights20.gif', 'images')
|
2008-10-08 01:41:46 +05:30
|
|
|
|
2009-01-27 04:27:25 +05:30
|
|
|
for f in self.imgs:
|
2008-10-22 00:27:42 +05:30
|
|
|
from_path = os.path.join(const.IMAGE_DIR, f)
|
|
|
|
self.copy_file(from_path, f, "images")
|
|
|
|
|
2008-11-11 04:17:48 +05:30
|
|
|
def display_month_navs(self, of, nr_up, year, currentsection, use_home=False):
|
2008-07-31 03:07:24 +05:30
|
|
|
"""
|
2008-10-08 01:41:46 +05:30
|
|
|
Will create and display the navigation menu bar
|
|
|
|
|
|
|
|
use_home will produce a link to wherever you specify as a home link
|
|
|
|
|
|
|
|
cal is one of these:
|
2008-11-11 03:11:38 +05:30
|
|
|
od = one_day(), wc = normal_cal(), yg = year_glance(), by = blank_year()
|
2008-10-08 01:41:46 +05:30
|
|
|
"""
|
|
|
|
|
|
|
|
navs = []
|
|
|
|
|
|
|
|
# check to see if we are using a home link???
|
|
|
|
if use_home:
|
2008-11-11 03:11:38 +05:30
|
|
|
navs.append((self.home_link, _('Home'), True))
|
2008-10-08 01:41:46 +05:30
|
|
|
|
2008-11-11 03:11:38 +05:30
|
|
|
for month in range(self.start_month, self.end_month + 1):
|
|
|
|
navs.append((month, month, True))
|
2008-10-08 01:41:46 +05:30
|
|
|
|
|
|
|
# Add a link for year_glance() if requested
|
2008-11-11 03:11:38 +05:30
|
|
|
navs.append(('fullyear', _('Year Glance'), self.fullyear))
|
2008-10-08 01:41:46 +05:30
|
|
|
|
2008-12-05 02:08:02 +05:30
|
|
|
of.write('<div id="subnavigation">\n')
|
2008-10-22 00:27:42 +05:30
|
|
|
of.write('\t<ul>\n')
|
2008-10-08 01:41:46 +05:30
|
|
|
|
2008-11-11 03:11:38 +05:30
|
|
|
for url_fname, nav_text, cond in navs:
|
|
|
|
url = ''
|
|
|
|
cs = False
|
|
|
|
if cond:
|
2008-10-08 01:41:46 +05:30
|
|
|
|
2008-11-11 03:11:38 +05:30
|
|
|
subdirs = ['..'] * nr_up
|
2008-11-11 04:17:48 +05:30
|
|
|
subdirs.append(str(year))
|
2008-10-08 01:41:46 +05:30
|
|
|
|
2008-11-11 03:11:38 +05:30
|
|
|
# Note. We use '/' here because it is a URL, not a OS dependent pathname
|
|
|
|
if type(url_fname) == int:
|
|
|
|
url_fname = _get_long_month_name(url_fname)
|
2008-10-08 01:41:46 +05:30
|
|
|
|
2008-11-11 03:11:38 +05:30
|
|
|
if type(nav_text) == int:
|
|
|
|
nav_text = _get_short_month_name(nav_text)
|
2008-10-08 01:41:46 +05:30
|
|
|
|
2008-11-11 03:11:38 +05:30
|
|
|
# Figure out if we need <li id="CurrentSection"> or just plain <li>
|
|
|
|
if url_fname == currentsection:
|
|
|
|
cs = True
|
2008-10-08 01:41:46 +05:30
|
|
|
|
2008-11-11 03:11:38 +05:30
|
|
|
url = url_fname
|
|
|
|
if not url.startswith('http:'):
|
|
|
|
url = '/'.join(subdirs + [url_fname])
|
2009-01-27 04:27:25 +05:30
|
|
|
if not _has_webpage_extension(url):
|
2008-11-11 03:11:38 +05:30
|
|
|
url += self.ext
|
2008-10-08 01:41:46 +05:30
|
|
|
|
2008-11-11 03:11:38 +05:30
|
|
|
cs = cs and ' id="CurrentSection"' or ''
|
|
|
|
of.write('\t\t<li%s><a href="%s">%s</a></li>\n' % (cs, url, nav_text))
|
2008-10-08 01:41:46 +05:30
|
|
|
|
2008-10-22 00:27:42 +05:30
|
|
|
of.write('\t</ul>\n')
|
|
|
|
of.write('</div>\n\n')
|
2008-10-08 01:41:46 +05:30
|
|
|
|
2008-11-11 03:11:38 +05:30
|
|
|
def display_year_navs(self, of, nr_up, currentsection):
|
2008-07-31 03:07:24 +05:30
|
|
|
"""
|
2008-10-08 01:41:46 +05:30
|
|
|
This will create the year navigation menu bar
|
|
|
|
"""
|
|
|
|
|
2008-10-22 00:27:42 +05:30
|
|
|
of.write('<div id="navigation">\n')
|
|
|
|
of.write('\t<ul>\n')
|
2008-10-08 01:41:46 +05:30
|
|
|
cols = 0
|
|
|
|
cal_year = self.start_year
|
2009-01-30 07:49:04 +05:30
|
|
|
while ((0 <= cols < 25) and
|
|
|
|
(self.start_year <= cal_year <= self.end_year)):
|
2008-10-08 01:41:46 +05:30
|
|
|
url = ''
|
|
|
|
cs = False
|
|
|
|
|
|
|
|
# begin subdir level
|
2008-11-11 03:11:38 +05:30
|
|
|
subdirs = ['..'] * nr_up
|
2008-10-08 01:41:46 +05:30
|
|
|
subdirs.append(str(cal_year))
|
|
|
|
|
|
|
|
# each year will link to January, unless self.partyear is True,
|
|
|
|
# then it will link to current month.
|
|
|
|
# this will always need an extension added
|
|
|
|
lng_month = _get_long_month_name(1)
|
|
|
|
if self.partyear:
|
|
|
|
if cal_year == self.today.year:
|
|
|
|
lng_month = _get_long_month_name(self.today.month)
|
|
|
|
|
2009-01-30 07:49:04 +05:30
|
|
|
# Note. We use '/' here because it is a URL, not a OS dependent
|
|
|
|
# pathname.
|
2008-11-11 04:17:48 +05:30
|
|
|
url = '/'.join(subdirs + [lng_month]) + self.ext
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2008-10-08 01:41:46 +05:30
|
|
|
# determine if we need to highlight???
|
|
|
|
if str(cal_year) == currentsection:
|
|
|
|
cs = True
|
|
|
|
|
|
|
|
# if True, highlight currentsection
|
|
|
|
cs = cs and ' id="CurrentSection"' or ''
|
|
|
|
|
2008-10-22 00:27:42 +05:30
|
|
|
of.write('\t\t<li%s><a href="%s">%s</a></li>\n' % (cs, url, str(cal_year)))
|
2008-10-08 01:41:46 +05:30
|
|
|
|
|
|
|
# increase year
|
|
|
|
cal_year += 1
|
|
|
|
|
|
|
|
# increase column
|
|
|
|
cols += 1
|
|
|
|
|
2008-10-22 00:27:42 +05:30
|
|
|
of.write('\t</ul>\n')
|
|
|
|
of.write('</div>\n\n')
|
2008-10-08 01:41:46 +05:30
|
|
|
|
2009-01-30 07:49:04 +05:30
|
|
|
def calendar_common(self, of, nr_up, year, currsec1, title, body_id,
|
|
|
|
use_home=False, add_print=True):
|
2008-10-08 01:41:46 +05:30
|
|
|
"""
|
|
|
|
Will create the common information for each calendar being created
|
|
|
|
"""
|
|
|
|
|
|
|
|
# Add Header
|
2008-11-11 03:11:38 +05:30
|
|
|
self.write_header(of, nr_up, title, add_print)
|
2008-10-08 01:41:46 +05:30
|
|
|
|
|
|
|
of.write('<body id="%s">\n' % body_id)
|
|
|
|
|
|
|
|
# Header Title
|
2008-11-11 03:11:38 +05:30
|
|
|
of.write('<div id="header">\n')
|
|
|
|
of.write('\t<h1 id="SiteTitle">%s</h1>\n' % title)
|
2008-10-08 01:41:46 +05:30
|
|
|
if self.author != '':
|
2008-10-22 00:27:42 +05:30
|
|
|
of.write('\t<p id="CreatorInfo">')
|
2008-10-08 01:41:46 +05:30
|
|
|
if self.email != '':
|
2008-10-22 00:27:42 +05:30
|
|
|
msg = _('Created for <a href="mailto:%(email)s?subject=WebCal">%(author)s</a>\n') % {
|
2008-10-08 01:41:46 +05:30
|
|
|
'email' : self.email,
|
|
|
|
'author' : self.author}
|
|
|
|
else:
|
|
|
|
msg = _('Created for %(author)s\n') % {'author' : self.author}
|
2008-10-22 00:27:42 +05:30
|
|
|
of.write('%s</p>\n' % msg)
|
|
|
|
of.write('</div>\n') # end header
|
2008-10-08 01:41:46 +05:30
|
|
|
|
2008-12-05 02:08:02 +05:30
|
|
|
if self.multiyear:
|
|
|
|
# create Year Navigation menu
|
|
|
|
self.display_year_navs(of, nr_up, str(year))
|
|
|
|
|
2008-10-08 01:41:46 +05:30
|
|
|
# adjust the months being created if self.partyear is True
|
|
|
|
# and year is eequal to current year, then start_month is current month
|
|
|
|
self.start_month = 1
|
|
|
|
if year == self.today.year:
|
|
|
|
if self.partyear:
|
|
|
|
self.start_month = self.today.month
|
|
|
|
|
|
|
|
# Create Month Navigation Menu
|
|
|
|
# identify currentsection for proper highlighting
|
2008-11-11 04:17:48 +05:30
|
|
|
self.display_month_navs(of, nr_up, year, currsec1, use_home)
|
2008-10-08 01:41:46 +05:30
|
|
|
|
2008-12-05 02:08:02 +05:30
|
|
|
of.write('<div class="content">\n')
|
|
|
|
|
2008-10-08 01:41:46 +05:30
|
|
|
def calendar_build(self, of, cal, year, month):
|
2008-07-17 18:35:15 +05:30
|
|
|
"""
|
|
|
|
This does the work of building the calendar
|
2009-01-27 13:19:47 +05:30
|
|
|
'cal' - one of "yg", "wc"
|
2008-07-31 03:07:24 +05:30
|
|
|
'month' - month number 1, 2, .., 12
|
2008-07-17 18:35:15 +05:30
|
|
|
"""
|
|
|
|
|
2008-10-08 01:41:46 +05:30
|
|
|
# define names for long and short month names
|
|
|
|
lng_month = _get_long_month_name(month)
|
|
|
|
shrt_month = _get_short_month_name(month)
|
|
|
|
|
2008-08-08 02:30:05 +05:30
|
|
|
# dow (day-of-week) uses Gramps numbering, sunday => 1, etc
|
|
|
|
start_dow = self.start_dow
|
|
|
|
col2day = [(x-1)%7+1 for x in range(start_dow, start_dow + 7)]
|
|
|
|
|
|
|
|
# Note. GrampsLocale has sunday => 1, monday => 2, etc
|
|
|
|
# We slice out the first empty element.
|
2008-12-05 02:08:02 +05:30
|
|
|
day_names = GrampsLocale.long_days
|
2008-08-08 02:30:05 +05:30
|
|
|
|
|
|
|
# Translate a Gramps day number into a HTMLclass
|
|
|
|
def get_class_for_daycol(col):
|
|
|
|
day = col2day[col]
|
|
|
|
if day == 1:
|
2008-08-05 00:38:31 +05:30
|
|
|
return "weekend sunday"
|
2008-08-08 02:30:05 +05:30
|
|
|
elif day == 7:
|
2008-08-05 00:38:31 +05:30
|
|
|
return "weekend saturday"
|
|
|
|
return "weekday"
|
|
|
|
|
2008-08-08 02:30:05 +05:30
|
|
|
def get_name_for_daycol(col):
|
|
|
|
day = col2day[col]
|
|
|
|
return day_names[day]
|
|
|
|
|
2009-01-30 07:49:04 +05:30
|
|
|
# monthinfo is filled using standard Python library
|
|
|
|
# calendar.monthcalendar. It fills a list of 7-day-lists. The first day
|
|
|
|
# of the 7-day-list is determined by calendar.firstweekday.
|
2008-08-08 02:30:05 +05:30
|
|
|
monthinfo = calendar.monthcalendar(year, month)
|
|
|
|
|
2009-01-30 07:49:04 +05:30
|
|
|
# Begin calendar head. We'll use the capitalized name, because here it
|
|
|
|
# seems appropriate for most countries.
|
2008-10-08 01:41:46 +05:30
|
|
|
month_name = lng_month.capitalize()
|
|
|
|
th_txt = month_name
|
2008-11-11 03:11:38 +05:30
|
|
|
if cal == 'wc': # normal_cal()
|
2008-10-08 01:41:46 +05:30
|
|
|
if not self.multiyear:
|
|
|
|
th_txt = '%s %d' % (month_name, year)
|
|
|
|
of.write('<!-- %s -->\n\n' % month_name)
|
2008-10-22 00:27:42 +05:30
|
|
|
of.write('<table id="%s" class="calendar">\n' % month_name)
|
|
|
|
of.write('\t<thead>\n')
|
|
|
|
of.write('\t\t<tr>\n')
|
|
|
|
of.write('\t\t\t<th colspan="7" class="monthName">%s</th>\n' % th_txt)
|
|
|
|
of.write('\t\t</tr>\n')
|
2008-07-17 18:35:15 +05:30
|
|
|
|
|
|
|
# Calendar weekday names header
|
2008-10-22 00:27:42 +05:30
|
|
|
of.write('\t\t<tr>\n')
|
2008-08-05 00:38:31 +05:30
|
|
|
for day_col in range(7):
|
2008-08-08 02:30:05 +05:30
|
|
|
dayclass = get_class_for_daycol(day_col)
|
2008-12-05 02:08:02 +05:30
|
|
|
dayname = get_name_for_daycol(day_col)
|
|
|
|
#of.write('\t\t\t<th class="%s">%s</th>\n' % (dayclass, get_name_for_daycol(day_col)))
|
|
|
|
of.write('\t\t\t<th class="%s"><abbr title="%s">%s</abbr></th>\n' % (dayclass, dayname, dayname[0]))
|
2008-10-22 00:27:42 +05:30
|
|
|
of.write('\t\t</tr>\n')
|
|
|
|
of.write('\t</thead>\n')
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2008-10-08 01:41:46 +05:30
|
|
|
# begin table body
|
2008-10-22 00:27:42 +05:30
|
|
|
of.write('\t<tbody>\n')
|
2008-07-31 03:07:24 +05:30
|
|
|
|
|
|
|
# Compute the first day to display for this month.
|
|
|
|
# It can also be a day in the previous month.
|
2008-07-17 18:35:15 +05:30
|
|
|
current_date = datetime.date(year, month, 1) # first day of the month
|
2008-08-12 01:49:51 +05:30
|
|
|
current_ord = current_date.toordinal() - monthinfo[0].count(0)
|
2008-07-17 18:35:15 +05:30
|
|
|
|
|
|
|
# get last month's last week for previous days in the month
|
|
|
|
if month == 1:
|
2008-10-08 01:41:46 +05:30
|
|
|
prevmonth = calendar.monthcalendar(year - 1, 12)
|
2008-07-17 18:35:15 +05:30
|
|
|
else:
|
|
|
|
prevmonth = calendar.monthcalendar(year, month-1)
|
|
|
|
num_weeks = len(prevmonth)
|
2008-07-31 03:07:24 +05:30
|
|
|
lastweek_prevmonth = prevmonth[num_weeks - 1]
|
2008-07-17 18:35:15 +05:30
|
|
|
|
|
|
|
# get next month's first week for next days in the month
|
|
|
|
if month == 12:
|
2008-10-08 01:41:46 +05:30
|
|
|
nextmonth = calendar.monthcalendar(year + 1, 1)
|
2008-07-17 18:35:15 +05:30
|
|
|
else:
|
|
|
|
nextmonth = calendar.monthcalendar(year, month + 1)
|
2008-07-31 03:07:24 +05:30
|
|
|
firstweek_nextmonth = nextmonth[0]
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2008-07-31 03:07:24 +05:30
|
|
|
nweeks = len(monthinfo)
|
2008-07-17 18:35:15 +05:30
|
|
|
for week_row in range(0, nweeks):
|
|
|
|
week = monthinfo[week_row]
|
2009-01-27 13:19:47 +05:30
|
|
|
# if you look this up in wikipedia, the first week is called week0
|
|
|
|
of.write('\t\t<tr class="week%d">\n' % week_row)
|
2008-07-31 03:07:24 +05:30
|
|
|
|
2008-08-05 00:38:31 +05:30
|
|
|
for day_col in range(0, 7):
|
2008-08-08 02:30:05 +05:30
|
|
|
dayclass = get_class_for_daycol(day_col)
|
2008-07-31 03:07:24 +05:30
|
|
|
|
2008-08-05 00:38:31 +05:30
|
|
|
day = week[day_col]
|
2009-01-30 07:49:04 +05:30
|
|
|
if day == 0: # a day in the previous or next month
|
|
|
|
if week_row == 0: # a day in the previous month
|
2008-08-05 00:38:31 +05:30
|
|
|
specday = lastweek_prevmonth[day_col]
|
2008-07-17 18:35:15 +05:30
|
|
|
specclass = "previous " + dayclass
|
2009-01-30 07:49:04 +05:30
|
|
|
elif week_row == nweeks-1: # a day in the next month
|
2008-08-05 00:38:31 +05:30
|
|
|
specday = firstweek_nextmonth[day_col]
|
2008-07-17 18:35:15 +05:30
|
|
|
specclass = "next " + dayclass
|
2008-07-31 03:07:24 +05:30
|
|
|
|
2008-12-05 02:08:02 +05:30
|
|
|
of.write('\t\t\t<td class="%s">\n' % specclass)
|
2008-10-22 00:27:42 +05:30
|
|
|
of.write('\t\t\t\t<div class="date">%d</div>\n' % specday)
|
|
|
|
of.write('\t\t\t</td>\n')
|
2008-07-31 03:07:24 +05:30
|
|
|
|
2009-01-30 07:49:04 +05:30
|
|
|
else: # normal day number in current month
|
2009-01-27 13:19:47 +05:30
|
|
|
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 > []:
|
|
|
|
|
|
|
|
hilightday = 'highlight ' + dayclass
|
|
|
|
|
|
|
|
# specify day class for this day
|
|
|
|
of.write('class="%s">\n' % hilightday)
|
|
|
|
|
|
|
|
# Year at a Glance
|
|
|
|
if cal == "yg":
|
|
|
|
# create yyyymmdd date string for
|
|
|
|
# "One Day" calendar pages filename
|
|
|
|
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_date = '/'.join([lng_month, fname_date])
|
|
|
|
fname_date += self.ext
|
|
|
|
of.write('\t\t\t\t<a href="%s" title="%s%d">\n'
|
|
|
|
% (fname_date, 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"
|
2008-10-22 00:27:42 +05:30
|
|
|
of.write('\t\t\t\t<div class="date">%d</div>\n' % day)
|
2008-10-08 01:41:46 +05:30
|
|
|
|
2009-01-27 13:19:47 +05:30
|
|
|
evt_dte = _make_date(thisday.year, thisday.month, thisday.day)
|
|
|
|
self.one_day(of, evt_dte, one_day_cal, holiday_list, bday_anniv_list)
|
|
|
|
|
|
|
|
# no holiday/ bday/ anniversary this day
|
2008-10-08 01:41:46 +05:30
|
|
|
else:
|
2008-07-17 18:35:15 +05:30
|
|
|
of.write('class="%s">\n' % dayclass)
|
2008-10-22 00:27:42 +05:30
|
|
|
of.write('\t\t\t\t<div class="date">%d</div>\n' % day)
|
2008-07-31 03:07:24 +05:30
|
|
|
|
2009-01-27 13:19:47 +05:30
|
|
|
# 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
|
|
|
|
of.write('\t\t\t</td>\n')
|
2008-10-08 01:41:46 +05:30
|
|
|
|
|
|
|
# change day number
|
2008-07-17 18:35:15 +05:30
|
|
|
current_ord += 1
|
2008-07-31 03:07:24 +05:30
|
|
|
|
2008-10-08 01:41:46 +05:30
|
|
|
# close the week/ row
|
2008-10-22 00:27:42 +05:30
|
|
|
of.write('\t\t</tr>\n')
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2009-01-27 13:19:47 +05:30
|
|
|
if cal == "yg":
|
2008-12-05 02:08:02 +05:30
|
|
|
# Fill up till we have 6 rows, so that the months align properly
|
|
|
|
for i in range(nweeks, 6):
|
|
|
|
of.write('\t\t<tr class="week%d">\n' % (i+1))
|
|
|
|
of.write('\t\t\t<td colspan="7"></td>\n')
|
|
|
|
of.write('\t\t</tr>\n')
|
|
|
|
|
|
|
|
# close table body
|
|
|
|
of.write('\t</tbody>\n')
|
|
|
|
|
2008-11-11 03:11:38 +05:30
|
|
|
def write_header(self, of, nr_up, title, add_print=True):
|
2008-07-17 18:35:15 +05:30
|
|
|
"""
|
2008-07-31 03:07:24 +05:30
|
|
|
This creates the header for the Calendars including style embedded for special purpose
|
2008-11-11 03:11:38 +05:30
|
|
|
'nr_up' - number of directory levels up, started from current page, to the
|
2008-08-02 02:17:04 +05:30
|
|
|
root of the directory tree (i.e. to self.html_dir).
|
2008-07-17 18:35:15 +05:30
|
|
|
"""
|
|
|
|
|
2008-10-22 00:27:42 +05:30
|
|
|
of.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"\n')
|
|
|
|
of.write(' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n')
|
2008-07-17 18:35:15 +05:30
|
|
|
xmllang = Utils.xml_lang()
|
2009-01-30 23:38:33 +05:30
|
|
|
of.write('<html xmlns="http://www.w3.org/1999/xhtml" '
|
|
|
|
'xml:lang="%s" lang="%s">\n' % (xmllang, xmllang))
|
2008-07-17 18:35:15 +05:30
|
|
|
of.write('<head>\n')
|
2008-10-22 00:27:42 +05:30
|
|
|
of.write('\t<title>%s</title>\n\n' % title)
|
|
|
|
of.write('\t<meta http-equiv="Content-Type" content="text/html;charset=%s" />\n'
|
2008-07-17 18:35:15 +05:30
|
|
|
% self.encoding)
|
2009-01-30 23:38:33 +05:30
|
|
|
of.write('\t<meta name="generator" content="%s %s %s" />\n' %
|
|
|
|
(const.PROGRAM_NAME, const.VERSION, const.URL_HOMEPAGE))
|
2008-10-22 00:27:42 +05:30
|
|
|
of.write('\t<meta name="author" content="%s" />\n\n' % self.author)
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2008-11-11 03:11:38 +05:30
|
|
|
subdirs = ['..'] * nr_up
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2008-12-05 02:08:02 +05:30
|
|
|
# link to stylesheet
|
|
|
|
fname = '/'.join(subdirs + ['styles'] + [self.css])
|
|
|
|
of.write('\t<link rel="stylesheet" href="%s" type="text/css" media="screen" />\n' % fname)
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2008-10-08 01:41:46 +05:30
|
|
|
# link to _CALENDARPRINT stylesheet
|
2008-11-11 03:11:38 +05:30
|
|
|
if add_print:
|
2008-12-05 02:08:02 +05:30
|
|
|
fname = '/'.join(subdirs + ['styles'] + ["Web_Print-Default.css"])
|
|
|
|
of.write('\t<link rel="stylesheet" href="%s" type="text/css" media="print" />\n' % fname)
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2008-10-08 01:41:46 +05:30
|
|
|
# link to GRAMPS favicon
|
2008-12-05 02:08:02 +05:30
|
|
|
fname = '/'.join(subdirs + ['images'] + ['favicon.ico'])
|
|
|
|
of.write('\t<link rel="shortcut icon" href="%s" type="image/icon" />\n' % fname)
|
2007-08-27 09:22:06 +05:30
|
|
|
|
2008-10-22 00:27:42 +05:30
|
|
|
of.write('</head>\n\n')
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2008-11-11 03:11:38 +05:30
|
|
|
def write_footer(self, of, nr_up):
|
2008-07-17 18:35:15 +05:30
|
|
|
"""
|
|
|
|
Writes the footer section of the pages
|
2008-11-11 03:11:38 +05:30
|
|
|
'nr_up' - number of directory levels up, started from current page, to the
|
2008-08-02 02:17:04 +05:30
|
|
|
root of the directory tree (i.e. to self.html_dir).
|
2008-07-17 18:35:15 +05:30
|
|
|
"""
|
|
|
|
|
2008-12-05 02:08:02 +05:30
|
|
|
of.write('<div class="fullclear"></div>\n')
|
|
|
|
of.write('</div>\n') # Closing "content"
|
|
|
|
|
2008-11-11 03:11:38 +05:30
|
|
|
of.write('<div id="footer">\n')
|
|
|
|
|
2008-07-17 18:35:15 +05:30
|
|
|
# Display date as user set in preferences
|
|
|
|
value = _dp.parse(time.strftime('%b %d %Y'))
|
|
|
|
value = _dd.display(value)
|
2008-11-11 03:11:38 +05:30
|
|
|
msg = _('Generated by <a href="http://gramps-project.org">'
|
|
|
|
'GRAMPS</a> on %(date)s') % {'date' : value}
|
2008-10-22 00:27:42 +05:30
|
|
|
of.write('\t<p id="createdate">%s</p>\n' % msg)
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2008-11-11 03:11:38 +05:30
|
|
|
copy_nr = self.copy
|
|
|
|
text = ''
|
|
|
|
if copy_nr == 0:
|
|
|
|
if self.author:
|
|
|
|
text = "© %s %s" % (self.today.year, self.author)
|
|
|
|
elif 0 < copy_nr < len(_CC):
|
|
|
|
subdirs = ['..'] * nr_up
|
2008-08-02 02:17:04 +05:30
|
|
|
# Note. We use '/' here because it is a URL, not a OS dependent pathname
|
2008-10-08 01:41:46 +05:30
|
|
|
fname = '/'.join(subdirs + ['images'] + ['somerights20.gif'])
|
2008-11-11 03:11:38 +05:30
|
|
|
text = _CC[copy_nr] % {'gif_fname' : fname}
|
2007-08-27 09:22:06 +05:30
|
|
|
else:
|
2008-10-08 01:41:46 +05:30
|
|
|
text = "© %s %s" % (self.today.year, self.author)
|
2008-10-22 00:27:42 +05:30
|
|
|
of.write('\t<p id="copyright">%s</p>\n' % text)
|
2008-11-11 03:11:38 +05:30
|
|
|
|
2008-10-22 00:27:42 +05:30
|
|
|
of.write('</div>\n')
|
2008-07-17 18:35:15 +05:30
|
|
|
of.write('</body>\n')
|
2007-08-27 09:22:06 +05:30
|
|
|
of.write('</html>\n')
|
|
|
|
|
2008-10-08 01:41:46 +05:30
|
|
|
def create_file(self, fname, subdir):
|
2008-08-01 02:12:05 +05:30
|
|
|
"""
|
|
|
|
Create a file in the html_dir tree.
|
|
|
|
If the directory does not exist, create it.
|
|
|
|
"""
|
2008-10-08 01:41:46 +05:30
|
|
|
|
|
|
|
fname = os.path.join(self.html_dir, subdir, fname)
|
|
|
|
|
2009-01-27 04:27:25 +05:30
|
|
|
if not _has_webpage_extension(fname):
|
2008-10-08 01:41:46 +05:30
|
|
|
fname += self.ext
|
|
|
|
|
|
|
|
destdir = os.path.dirname(fname)
|
|
|
|
|
|
|
|
if not os.path.isdir(destdir):
|
|
|
|
os.makedirs(destdir)
|
|
|
|
|
2008-08-01 02:12:05 +05:30
|
|
|
of = codecs.EncodedFile(open(fname, "w"), 'utf-8', self.encoding, 'xmlcharrefreplace')
|
2008-07-30 00:07:29 +05:30
|
|
|
return of
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2008-07-30 00:07:29 +05:30
|
|
|
def close_file(self, of):
|
|
|
|
of.close()
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2009-01-27 13:19:47 +05:30
|
|
|
def one_day(self, of, evt_dte, one_day_cal, holiday_list, bday_anniv_list):
|
2008-07-28 11:42:46 +05:30
|
|
|
"""
|
2008-10-08 01:41:46 +05:30
|
|
|
This method creates the One Day page for "Year At A Glance"
|
2008-07-30 00:07:29 +05:30
|
|
|
|
2008-10-08 01:41:46 +05:30
|
|
|
'holiday_list' - list of holidays to display on this day
|
|
|
|
'bday_anniv_list' - list of birthdays and anniversaries to display on this day
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2008-10-08 01:41:46 +05:30
|
|
|
'day_list' - a combination of both dictionaries to be able to create one day
|
2009-01-27 13:19:47 +05:30
|
|
|
nyears, date, text, event --- are necessary for figuring the age or years married
|
2008-10-08 01:41:46 +05:30
|
|
|
for each year being created...
|
2008-07-30 00:07:29 +05:30
|
|
|
"""
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2009-01-27 13:19:47 +05:30
|
|
|
# initialize day_list
|
2008-10-08 01:41:46 +05:30
|
|
|
day_list = []
|
|
|
|
|
2009-01-27 13:19:47 +05:30
|
|
|
# call day_list to fill
|
|
|
|
day_list = fill_day_list(evt_dte, holiday_list, bday_anniv_list)
|
2009-01-27 04:27:25 +05:30
|
|
|
|
2009-01-27 13:19:47 +05:30
|
|
|
# This is one_day in the year-at-a-glance calendar
|
|
|
|
if one_day_cal == "OneDay":
|
2009-01-27 04:27:25 +05:30
|
|
|
|
2009-01-27 13:19:47 +05:30
|
|
|
# break up evt_dte to get year, month, day for this day
|
|
|
|
year = evt_dte.get_year()
|
|
|
|
month = evt_dte.get_month()
|
|
|
|
day = evt_dte.get_day()
|
2009-01-27 04:27:25 +05:30
|
|
|
|
2009-01-27 13:19:47 +05:30
|
|
|
# create fname date string for "One Day" calendar pages filename
|
|
|
|
# using yyyymmdd for filename
|
|
|
|
two_digit_month = '%02d' % month
|
|
|
|
two_digit_day = '%02d' % day
|
|
|
|
fname_date = str(year) + str(two_digit_month) + str(two_digit_day)
|
2009-01-27 04:27:25 +05:30
|
|
|
|
2009-01-27 13:19:47 +05:30
|
|
|
# define names for long month
|
|
|
|
lng_month = _get_long_month_name(month)
|
2009-01-27 04:27:25 +05:30
|
|
|
|
2009-01-27 13:19:47 +05:30
|
|
|
# Name the file, and create it (see code in calendar_build)
|
|
|
|
fpath = os.path.join(str(year), lng_month)
|
|
|
|
of = self.create_file(fname_date, fpath)
|
2009-01-27 04:27:25 +05:30
|
|
|
|
2009-01-27 13:19:47 +05:30
|
|
|
nr_up = 2 # number of directory levels up to get to root
|
2009-01-27 04:27:25 +05:30
|
|
|
|
2009-01-27 13:19:47 +05:30
|
|
|
# set date display as in user prevferences
|
|
|
|
pg_date = _dd.display(evt_dte)
|
2009-01-27 04:27:25 +05:30
|
|
|
|
2009-01-27 13:19:47 +05:30
|
|
|
self.calendar_common(of, nr_up, year, lng_month, _('One Day Within A Year'), pg_date)
|
2009-01-27 04:27:25 +05:30
|
|
|
|
2009-01-27 13:19:47 +05:30
|
|
|
of.write('\t<h3 id="OneDay">%s</h3>\n' % pg_date)
|
2009-01-27 04:27:25 +05:30
|
|
|
|
2009-01-27 13:19:47 +05:30
|
|
|
# for both "WebCal" and "One Day"
|
|
|
|
of.write('\t\t\t\t\t<ul>\n')
|
|
|
|
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')
|
2009-01-27 04:27:25 +05:30
|
|
|
|
2009-01-27 13:19:47 +05:30
|
|
|
# if calendar is one_day(), write footer, and close the file
|
|
|
|
if one_day_cal == "OneDay":
|
|
|
|
self.write_footer(of, nr_up)
|
|
|
|
self.close_file(of)
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2008-10-08 01:41:46 +05:30
|
|
|
def year_glance(self, year):
|
2008-07-17 18:35:15 +05:30
|
|
|
"""
|
|
|
|
This method will create the Full Year At A Glance Page...
|
|
|
|
"""
|
|
|
|
|
2008-11-11 03:11:38 +05:30
|
|
|
nr_up = 1 # Number of directory levels up to get to root
|
2008-07-30 00:07:29 +05:30
|
|
|
|
|
|
|
# Name the file, and create it
|
2008-10-08 01:41:46 +05:30
|
|
|
cal_fname = 'fullyear'
|
2008-08-02 02:17:04 +05:30
|
|
|
of = self.create_file(cal_fname, str(year))
|
2008-07-30 00:07:29 +05:30
|
|
|
|
2008-10-08 01:41:46 +05:30
|
|
|
# page title
|
2008-11-11 04:17:48 +05:30
|
|
|
title = _("%(year)d, At A Glance") % {'year' : year}
|
2008-07-30 00:07:29 +05:30
|
|
|
|
2008-12-05 02:08:02 +05:30
|
|
|
self.calendar_common(of, nr_up, year, 'fullyear', title, 'fullyearlinked')
|
2008-07-30 00:07:29 +05:30
|
|
|
|
2008-10-08 01:41:46 +05:30
|
|
|
# page description
|
2008-12-05 02:08:02 +05:30
|
|
|
of.write('<div class="content">\n')
|
2008-10-22 00:27:42 +05:30
|
|
|
of.write('<p id="description">\n')
|
2008-11-11 03:11:38 +05:30
|
|
|
# TODO. The "red square" is only valid for some style sheets.
|
2008-10-22 00:27:42 +05:30
|
|
|
of.write(_('This calendar is meant to give you access to all your data at a glance '
|
2008-12-05 02:08:02 +05:30
|
|
|
'compressed into one page. Clicking on a date will take you to a '
|
|
|
|
'page that shows all the events for that date, if there are any!\n'))
|
|
|
|
of.write('</p>\n')
|
|
|
|
of.write('</div>\n\n')
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2009-01-27 04:27:25 +05:30
|
|
|
# generate progress pass for "Year At A Glance"
|
|
|
|
self.progress.set_pass(_('Creating Year At A Glance calendars'), self.end_month - self.start_month)
|
|
|
|
|
2008-11-11 03:11:38 +05:30
|
|
|
for month in range(self.start_month, self.end_month + 1):
|
2008-07-17 18:35:15 +05:30
|
|
|
|
|
|
|
# build the calendar
|
2008-10-08 01:41:46 +05:30
|
|
|
self.calendar_build(of, "yg", year, month)
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2008-10-08 01:41:46 +05:30
|
|
|
# create note section for "Year At A Glance"
|
2008-07-17 20:18:54 +05:30
|
|
|
note = self.month_notes[month-1].strip()
|
|
|
|
note = note or " "
|
2008-10-22 00:27:42 +05:30
|
|
|
of.write('\t<tfoot>\n')
|
|
|
|
of.write('\t\t<tr>\n')
|
2008-12-05 02:08:02 +05:30
|
|
|
of.write('\t\t\t<td colspan="7">%s</td>\n' % note)
|
2008-10-22 00:27:42 +05:30
|
|
|
of.write('\t\t</tr>\n')
|
|
|
|
of.write('\t</tfoot>\n')
|
|
|
|
of.write('</table>\n\n')
|
2008-10-08 01:41:46 +05:30
|
|
|
|
2009-01-27 04:27:25 +05:30
|
|
|
# increase progress bar
|
2008-10-08 01:41:46 +05:30
|
|
|
self.progress.step()
|
|
|
|
|
2008-07-30 00:07:29 +05:30
|
|
|
# write footer section, and close file
|
2008-11-11 03:11:38 +05:30
|
|
|
self.write_footer(of, nr_up)
|
2008-07-31 03:07:24 +05:30
|
|
|
self.close_file(of)
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2007-08-27 09:22:06 +05:30
|
|
|
def write_report(self):
|
2008-10-08 01:41:46 +05:30
|
|
|
"""
|
|
|
|
The short method that runs through each month and creates a page.
|
2007-08-27 09:22:06 +05:30
|
|
|
|
2008-10-08 01:41:46 +05:30
|
|
|
if self.partyear, use will enter the start month, ending month, start year, and ending year
|
|
|
|
else, year is equal to the current year, set by self.today
|
|
|
|
"""
|
|
|
|
|
|
|
|
# open progress meter bar
|
2009-01-27 04:27:25 +05:30
|
|
|
self.progress = Utils.ProgressMeter(_("Generate XHTML Calendars"), '')
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2008-10-08 01:41:46 +05:30
|
|
|
# get data from database for birthdays/ anniversaries
|
2008-11-11 04:17:48 +05:30
|
|
|
# TODO. Verify that we collect correct info based on start_year
|
|
|
|
self.collect_data(self.start_year)
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2009-01-27 04:27:25 +05:30
|
|
|
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",
|
|
|
|
]
|
|
|
|
|
2008-10-08 01:41:46 +05:30
|
|
|
# Copy all files for the calendars being created
|
|
|
|
self.copy_calendar_files()
|
2007-08-27 09:22:06 +05:30
|
|
|
|
2008-10-08 01:41:46 +05:30
|
|
|
# create calendars with multiple years up to twenty-five years
|
|
|
|
# navigation bar length will only support twenty-five years at any given time
|
|
|
|
if self.multiyear:
|
2008-11-11 03:11:38 +05:30
|
|
|
# Clip to max 25 years
|
2008-11-11 04:17:48 +05:30
|
|
|
if ((self.end_year - self.start_year + 1) > 25):
|
|
|
|
self.end_year = self.start_year + 25 - 1
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2008-10-08 01:41:46 +05:30
|
|
|
for cal_year in range(self.start_year, (self.end_year + 1)):
|
|
|
|
|
|
|
|
# generate progress pass for year ????
|
|
|
|
self.progress.set_pass(_('Creating year %d calendars' % cal_year), '')
|
|
|
|
|
|
|
|
# initialize the holidays dict to fill:
|
|
|
|
self.holidays = {}
|
|
|
|
|
2009-01-30 07:49:04 +05:30
|
|
|
# get the information, first from holidays:
|
|
|
|
if self.country != 0:
|
|
|
|
self.__get_holidays(cal_year)
|
2008-10-08 01:41:46 +05:30
|
|
|
|
|
|
|
# adjust the months being created if self.partyear is True,
|
|
|
|
# and if the year is the current year, then start month is current month
|
|
|
|
self.start_month = 1
|
|
|
|
if cal_year == self.today.year:
|
|
|
|
if self.partyear:
|
|
|
|
self.start_month = self.today.month
|
|
|
|
|
|
|
|
# create "WebCal" calendar pages
|
2008-11-11 03:11:38 +05:30
|
|
|
self.normal_cal(cal_year)
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2008-10-08 01:41:46 +05:30
|
|
|
# create "Year At A Glance" and "One Day" calendar pages
|
|
|
|
if self.fullyear:
|
|
|
|
self.year_glance(cal_year)
|
|
|
|
|
|
|
|
# a single year
|
|
|
|
else:
|
2008-11-11 04:17:48 +05:30
|
|
|
cal_year = self.start_year
|
|
|
|
|
2008-10-08 01:41:46 +05:30
|
|
|
self.holidays = {}
|
2009-01-30 07:49:04 +05:30
|
|
|
|
|
|
|
# get the information, first from holidays:
|
|
|
|
if self.country != 0:
|
|
|
|
self.__get_holidays(cal_year)
|
2008-10-08 01:41:46 +05:30
|
|
|
|
|
|
|
# generate progress pass for single year
|
2008-11-11 03:11:38 +05:30
|
|
|
#self.progress.set_pass(_('Creating calendars'), self.end_month - self.start_month)
|
2008-10-08 01:41:46 +05:30
|
|
|
|
|
|
|
# adjust the months being created if self.partyear is True,
|
|
|
|
# and if the year is the current year, then start month is current month
|
|
|
|
self.start_month = 1
|
2008-11-11 04:17:48 +05:30
|
|
|
if cal_year == self.today.year:
|
2008-10-08 01:41:46 +05:30
|
|
|
if self.partyear:
|
|
|
|
self.start_month = self.today.month
|
|
|
|
|
2008-11-11 04:17:48 +05:30
|
|
|
# create "WebCal" calendar pages
|
|
|
|
self.normal_cal(cal_year)
|
2008-10-08 01:41:46 +05:30
|
|
|
|
|
|
|
# create "Year At A Glance"
|
|
|
|
if self.fullyear:
|
2008-11-11 04:17:48 +05:30
|
|
|
self.year_glance(cal_year)
|
2008-07-17 18:35:15 +05:30
|
|
|
|
|
|
|
# Close the progress meter
|
2007-08-27 09:22:06 +05:30
|
|
|
self.progress.close()
|
|
|
|
|
2008-11-11 03:11:38 +05:30
|
|
|
def normal_cal(self, year):
|
2008-07-30 00:07:29 +05:30
|
|
|
"""
|
|
|
|
This method provides information and header/ footer to the calendar month
|
|
|
|
"""
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2008-10-08 01:41:46 +05:30
|
|
|
# do some error correcting if needed
|
|
|
|
if self.multiyear:
|
|
|
|
if self.end_year < self.start_year:
|
2008-11-11 03:11:38 +05:30
|
|
|
# Huh? Why start_year+1?
|
2008-10-08 01:41:46 +05:30
|
|
|
self.end_year = self.start_year + 1
|
2008-07-30 00:07:29 +05:30
|
|
|
|
2008-11-11 03:11:38 +05:30
|
|
|
nr_up = 1 # Number of directory levels up to get to self.html_dir / root
|
2008-07-30 00:07:29 +05:30
|
|
|
|
2009-01-27 04:27:25 +05:30
|
|
|
# generate progress pass for "WebCal"
|
|
|
|
self.progress.set_pass(_('Creating WebCal calendars'), self.end_month - self.start_month)
|
|
|
|
|
2008-11-11 03:11:38 +05:30
|
|
|
for month in range(self.start_month, self.end_month + 1):
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2008-10-08 01:41:46 +05:30
|
|
|
# Name the file, and create it
|
|
|
|
cal_fname = _get_long_month_name(month)
|
|
|
|
of = self.create_file(cal_fname, str(year))
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2008-11-11 04:17:48 +05:30
|
|
|
self.calendar_common(of, nr_up, year, cal_fname, self.title_text, 'WebCal', use_home=True)
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2008-10-08 01:41:46 +05:30
|
|
|
# build the calendar
|
2008-11-11 03:11:38 +05:30
|
|
|
self.calendar_build(of, "wc", year, month)
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2008-10-08 01:41:46 +05:30
|
|
|
# create note section for "WebCal"
|
|
|
|
note = self.month_notes[month-1].strip()
|
|
|
|
note = note or " "
|
2008-10-22 00:27:42 +05:30
|
|
|
of.write('\t<tfoot>\n')
|
|
|
|
of.write('\t\t<tr>\n')
|
2008-12-05 02:08:02 +05:30
|
|
|
of.write('\t\t\t<td colspan="7">%s</td>\n' % note)
|
2008-10-22 00:27:42 +05:30
|
|
|
of.write('\t\t</tr>\n')
|
|
|
|
of.write('\t</tfoot>\n')
|
|
|
|
of.write('</table>\n\n')
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2008-10-08 01:41:46 +05:30
|
|
|
# write footer section, and close file
|
2008-11-11 03:11:38 +05:30
|
|
|
self.write_footer(of, nr_up)
|
2008-10-08 01:41:46 +05:30
|
|
|
self.close_file(of)
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2008-10-08 01:41:46 +05:30
|
|
|
# increase progress bar
|
|
|
|
self.progress.step()
|
2007-08-27 09:22:06 +05:30
|
|
|
|
2008-12-11 18:38:37 +05:30
|
|
|
def collect_data(self, this_year):
|
2007-08-27 09:22:06 +05:30
|
|
|
"""
|
|
|
|
This method runs through the data, and collects the relevant dates
|
|
|
|
and text.
|
2008-10-08 01:41:46 +05:30
|
|
|
|
|
|
|
TODO The use of living variable is too loosely and too liberable to be
|
|
|
|
properly used. It only checks to see i an individual was dead as of
|
|
|
|
January, 1, ????--see line 1147
|
|
|
|
|
|
|
|
if person is dead, then do nothing more!!!
|
2007-08-27 09:22:06 +05:30
|
|
|
"""
|
2008-12-16 03:12:58 +05:30
|
|
|
people = self.database.get_person_handles(sort_handles=False)
|
|
|
|
self.progress.set_pass(_('Applying Filter...'), len(people))
|
|
|
|
people = self.filter.apply(self.database, people, self.progress)
|
2008-10-08 01:41:46 +05:30
|
|
|
|
|
|
|
self.progress.set_pass(_("Reading database..."), len(people))
|
2007-08-27 09:22:06 +05:30
|
|
|
for person_handle in people:
|
2008-07-17 18:35:15 +05:30
|
|
|
self.progress.step()
|
2007-08-27 09:22:06 +05:30
|
|
|
person = self.database.get_person_from_handle(person_handle)
|
2008-10-08 01:41:46 +05:30
|
|
|
family_list = person.get_family_handle_list()
|
2007-08-27 09:22:06 +05:30
|
|
|
birth_ref = person.get_birth_ref()
|
|
|
|
birth_date = None
|
|
|
|
if birth_ref:
|
|
|
|
birth_event = self.database.get_event_from_handle(birth_ref.ref)
|
|
|
|
birth_date = birth_event.get_date_object()
|
2009-01-27 13:19:47 +05:30
|
|
|
|
|
|
|
# determine birthday information???
|
|
|
|
if self.birthday and birth_date is not None:
|
|
|
|
|
|
|
|
# determine if birthdadate is a valid date???
|
|
|
|
complete_date = False
|
|
|
|
if birth_date.is_valid():
|
|
|
|
complete_date = True
|
|
|
|
if complete_date:
|
|
|
|
|
2008-10-08 01:41:46 +05:30
|
|
|
year = birth_date.get_year()
|
|
|
|
month = birth_date.get_month()
|
|
|
|
day = birth_date.get_day()
|
|
|
|
|
|
|
|
# add some things to handle maiden name:
|
|
|
|
father_lastname = None # husband, actually
|
|
|
|
sex = person.get_gender()
|
|
|
|
if sex == gen.lib.Person.FEMALE:
|
|
|
|
if self.maiden_name in ['spouse_first', 'spouse_last']: # get husband's last name:
|
|
|
|
if len(family_list) > 0:
|
|
|
|
if self.maiden_name == 'spouse_first':
|
|
|
|
fhandle = family_list[0]
|
|
|
|
else:
|
|
|
|
fhandle = family_list[-1]
|
|
|
|
fam = self.database.get_family_from_handle(fhandle)
|
|
|
|
father_handle = fam.get_father_handle()
|
|
|
|
mother_handle = fam.get_mother_handle()
|
|
|
|
if mother_handle == person_handle:
|
|
|
|
if father_handle:
|
|
|
|
father = self.database.get_person_from_handle(father_handle)
|
|
|
|
if father != None:
|
|
|
|
father_name = father.get_primary_name()
|
|
|
|
father_lastname = _get_regular_surname(sex, father_name)
|
|
|
|
short_name = _get_short_name(person, father_lastname)
|
2009-01-27 13:19:47 +05:30
|
|
|
alive = probably_alive(person, self.database, _make_date(this_year, month, day))
|
2008-10-08 01:41:46 +05:30
|
|
|
text = _('%(short_name)s') % {'short_name' : short_name}
|
2009-01-27 13:19:47 +05:30
|
|
|
if ((self.alive and alive) or not self.alive):
|
|
|
|
self.add_day_item(text, year, month, day, 'Birthday')
|
|
|
|
|
|
|
|
# add anniversary if requested
|
|
|
|
if self.anniv:
|
|
|
|
for fhandle in family_list:
|
|
|
|
fam = self.database.get_family_from_handle(fhandle)
|
|
|
|
father_handle = fam.get_father_handle()
|
|
|
|
mother_handle = fam.get_mother_handle()
|
|
|
|
if father_handle == person.get_handle():
|
|
|
|
spouse_handle = mother_handle
|
|
|
|
else:
|
|
|
|
continue # with next person if this was the marriage event
|
|
|
|
if spouse_handle:
|
|
|
|
spouse = self.database.get_person_from_handle(spouse_handle)
|
|
|
|
if spouse:
|
|
|
|
spouse_name = _get_short_name(spouse)
|
|
|
|
short_name = _get_short_name(person)
|
|
|
|
|
|
|
|
are_married = get_marrital_status(fam, self.database)
|
|
|
|
if are_married is not None:
|
|
|
|
for event_ref in fam.get_event_ref_list():
|
|
|
|
event = self.database.get_event_from_handle(event_ref.ref)
|
|
|
|
event_obj = event.get_date_object()
|
|
|
|
year = event_obj.get_year()
|
|
|
|
month = event_obj.get_month()
|
|
|
|
day = event_obj.get_day()
|
|
|
|
|
|
|
|
# determine if anniversary date is a valid date???
|
|
|
|
complete_date = False
|
|
|
|
if event_obj.get_valid():
|
|
|
|
complete_date = True
|
|
|
|
if complete_date:
|
|
|
|
|
|
|
|
text = _('%(spouse)s and %(person)s') % {
|
|
|
|
'spouse' : spouse_name,
|
|
|
|
'person' : short_name}
|
|
|
|
|
|
|
|
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')
|
2007-08-27 09:22:06 +05:30
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
2008-02-10 09:39:09 +05:30
|
|
|
# WebCalOptions
|
2007-08-27 09:22:06 +05:30
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2008-02-10 09:39:09 +05:30
|
|
|
class WebCalOptions(MenuReportOptions):
|
2007-08-27 09:22:06 +05:30
|
|
|
"""
|
|
|
|
Defines options and provides handling interface.
|
|
|
|
"""
|
2008-07-17 20:18:54 +05:30
|
|
|
|
2008-02-10 09:39:09 +05:30
|
|
|
def __init__(self, name, dbase):
|
|
|
|
self.__db = dbase
|
|
|
|
self.__pid = None
|
|
|
|
self.__filter = None
|
|
|
|
MenuReportOptions.__init__(self, name, dbase)
|
2007-08-27 09:22:06 +05:30
|
|
|
|
2008-02-10 09:39:09 +05:30
|
|
|
def add_menu_options(self, menu):
|
|
|
|
"""
|
|
|
|
Add options to the menu for the web calendar.
|
|
|
|
"""
|
|
|
|
self.__add_report_options(menu)
|
|
|
|
self.__add_content_options(menu)
|
|
|
|
self.__add_notes_options(menu)
|
2008-07-17 20:18:54 +05:30
|
|
|
|
2008-02-10 09:39:09 +05:30
|
|
|
def __add_report_options(self, menu):
|
|
|
|
"""
|
|
|
|
Options on the "Report Options" tab.
|
|
|
|
"""
|
|
|
|
category_name = _("Report Options")
|
2008-07-17 20:18:54 +05:30
|
|
|
|
|
|
|
target = DestinationOption( _("Destination"),
|
|
|
|
os.path.join(const.USER_HOME, "WEBCAL"))
|
2008-02-10 09:39:09 +05:30
|
|
|
target.set_help( _("The destination directory for the web files"))
|
|
|
|
target.set_directory_entry(True)
|
|
|
|
menu.add_option(category_name, "target", target)
|
2008-07-17 20:18:54 +05:30
|
|
|
|
|
|
|
title = StringOption(_('Calendar Title'), _('My Family Calendar'))
|
2008-07-17 18:35:15 +05:30
|
|
|
title.set_help(_("The title of the calendar"))
|
|
|
|
menu.add_option(category_name, "title", title)
|
2008-07-17 20:18:54 +05:30
|
|
|
|
2008-07-17 18:35:15 +05:30
|
|
|
self.__filter = FilterOption(_("Filter"), 0)
|
|
|
|
self.__filter.set_help(
|
|
|
|
_("Select filter to restrict people that appear on calendar"))
|
|
|
|
menu.add_option(category_name, "filter", self.__filter)
|
|
|
|
self.__filter.connect('value-changed', self.__filter_changed)
|
2008-07-17 20:18:54 +05:30
|
|
|
|
2008-07-17 18:35:15 +05:30
|
|
|
self.__pid = PersonOption(_("Filter Person"))
|
|
|
|
self.__pid.set_help(_("The center person for the filter"))
|
|
|
|
menu.add_option(category_name, "pid", self.__pid)
|
|
|
|
self.__pid.connect('value-changed', self.__update_filters)
|
2008-07-17 20:18:54 +05:30
|
|
|
|
2008-07-17 18:35:15 +05:30
|
|
|
self.__update_filters()
|
|
|
|
|
2008-02-10 09:39:09 +05:30
|
|
|
ext = EnumeratedListOption(_("File extension"), ".html" )
|
|
|
|
for etype in ['.html', '.htm', '.shtml', '.php', '.php3', '.cgi']:
|
|
|
|
ext.add_item(etype, etype)
|
|
|
|
ext.set_help( _("The extension to be used for the web files"))
|
|
|
|
menu.add_option(category_name, "ext", ext)
|
2008-07-17 20:18:54 +05:30
|
|
|
|
2008-02-10 09:39:09 +05:30
|
|
|
cright = EnumeratedListOption(_('Copyright'), 0 )
|
2008-08-08 02:30:05 +05:30
|
|
|
for index, copt in enumerate(_COPY_OPTIONS):
|
2008-02-10 09:39:09 +05:30
|
|
|
cright.add_item(index, copt)
|
|
|
|
cright.set_help( _("The copyright to be used for the web files"))
|
|
|
|
menu.add_option(category_name, "cright", cright)
|
2008-07-17 20:18:54 +05:30
|
|
|
|
|
|
|
encoding = EnumeratedListOption(_('Character set encoding'), _CHARACTER_SETS[0][1])
|
2008-02-10 09:39:09 +05:30
|
|
|
for eopt in _CHARACTER_SETS:
|
|
|
|
encoding.add_item(eopt[1], eopt[0])
|
|
|
|
encoding.set_help( _("The encoding to be used for the web files"))
|
|
|
|
menu.add_option(category_name, "encoding", encoding)
|
2008-07-17 18:35:15 +05:30
|
|
|
|
|
|
|
css = EnumeratedListOption(_('StyleSheet'), _CSS_FILES[0][1])
|
|
|
|
for style in _CSS_FILES:
|
|
|
|
css.add_item(style[1], style[0])
|
|
|
|
css.set_help( _("The Style Sheet to be used for the web page"))
|
|
|
|
menu.add_option(category_name, "css", css)
|
2008-07-17 20:18:54 +05:30
|
|
|
|
2008-02-10 09:39:09 +05:30
|
|
|
def __add_content_options(self, menu):
|
|
|
|
"""
|
|
|
|
Options on the "Content Options" tab.
|
|
|
|
"""
|
|
|
|
category_name = _("Content Options")
|
2008-07-17 20:18:54 +05:30
|
|
|
|
2008-10-08 01:41:46 +05:30
|
|
|
# set to today's date for use in menu, etc.
|
|
|
|
# 0 = year, 1 = month, 2 = day
|
|
|
|
today = time.localtime()
|
2009-01-30 07:49:04 +05:30
|
|
|
today = datetime.date(today[0], today[1], today[2])
|
2008-10-08 01:41:46 +05:30
|
|
|
|
|
|
|
partyear = BooleanOption(_('Create Partial Year calendar'), False)
|
|
|
|
partyear.set_help(_('Create a partial year calendar. The start month will be'
|
2008-10-22 00:27:42 +05:30
|
|
|
' equal to the current month to the end of the year.'))
|
2008-10-08 01:41:46 +05:30
|
|
|
menu.add_option(category_name, 'partyear', partyear)
|
|
|
|
|
|
|
|
self.__multiyear = BooleanOption(_('Create multiple year calendars'), False)
|
|
|
|
self.__multiyear.set_help(_('Whether to create Multiple year calendars or not.'))
|
|
|
|
menu.add_option(category_name, 'multiyear', self.__multiyear)
|
|
|
|
self.__multiyear.connect('value-changed', self.__multiyear_changed)
|
2008-02-10 09:39:09 +05:30
|
|
|
|
2009-01-30 07:49:04 +05:30
|
|
|
self.__start_year = NumberOption(_('Start Year for the Calendar(s)'), today.year, 1900, 3000)
|
2008-10-08 01:41:46 +05:30
|
|
|
self.__start_year.set_help(_('Enter the starting year for the calendars between 1900 - 3000'))
|
|
|
|
menu.add_option(category_name, 'start_year', self.__start_year)
|
|
|
|
|
2009-01-30 07:49:04 +05:30
|
|
|
self.__end_year = NumberOption(_('End Year for the Calendar(s)'), today.year, 1900, 3000)
|
2008-10-08 01:41:46 +05:30
|
|
|
self.__end_year.set_help(_('Enter the ending year for the calendars between 1900 - 3000.'
|
|
|
|
' if multiple years is selected, then only twenty years at any given time'))
|
|
|
|
menu.add_option(category_name, 'end_year', self.__end_year)
|
|
|
|
|
|
|
|
self.__multiyear_changed()
|
|
|
|
|
|
|
|
fullyear = BooleanOption(_('Create "Year At A Glance" Calendar(s)'), False)
|
|
|
|
fullyear.set_help(_('Whether to create A one-page mini calendar with dates highlighted'))
|
2008-07-17 18:35:15 +05:30
|
|
|
menu.add_option(category_name, 'fullyear', fullyear)
|
|
|
|
|
2008-02-10 09:39:09 +05:30
|
|
|
country = EnumeratedListOption(_('Country for holidays'), 0 )
|
2009-01-30 07:49:04 +05:30
|
|
|
holiday_table = libholiday.HolidayTable()
|
|
|
|
for index, item in enumerate(holiday_table.get_countries()):
|
2008-02-10 09:39:09 +05:30
|
|
|
country.add_item(index, item)
|
2008-10-08 01:41:46 +05:30
|
|
|
country.set_help(_("Holidays will be included for the selected "
|
2008-02-10 09:39:09 +05:30
|
|
|
"country"))
|
|
|
|
menu.add_option(category_name, "country", country)
|
|
|
|
|
2008-10-08 01:41:46 +05:30
|
|
|
maiden_name = EnumeratedListOption(_("Birthday surname"), "own")
|
|
|
|
maiden_name.add_item("spouse_first", _("Wives use husband's surname (from first family listed)"))
|
|
|
|
maiden_name.add_item("spouse_last", _("Wives use husband's surname (from last family listed)"))
|
|
|
|
maiden_name.add_item("own", _("Wives use their own surname"))
|
|
|
|
maiden_name.set_help(_("Select married women's displayed surname"))
|
|
|
|
menu.add_option(category_name, "maiden_name", maiden_name)
|
|
|
|
|
2008-08-08 02:30:05 +05:30
|
|
|
# Default selection ????
|
|
|
|
start_dow = EnumeratedListOption(_("First day of week"), 1)
|
|
|
|
for count in range(1, 8):
|
|
|
|
start_dow.add_item(count, GrampsLocale.long_days[count].capitalize())
|
|
|
|
start_dow.set_help(_("Select the first day of the week for the calendar"))
|
|
|
|
menu.add_option(category_name, "start_dow", start_dow)
|
|
|
|
|
2008-07-17 20:18:54 +05:30
|
|
|
home_link = StringOption(_('Home link'), '../index.html')
|
2008-07-17 18:35:15 +05:30
|
|
|
home_link.set_help(_("The link to be included to direct the user to "
|
|
|
|
"the main page of the web site"))
|
|
|
|
menu.add_option(category_name, "home_link", home_link)
|
2008-07-17 20:18:54 +05:30
|
|
|
|
2008-02-10 09:39:09 +05:30
|
|
|
alive = BooleanOption(_("Include only living people"), True)
|
|
|
|
alive.set_help(_("Include only living people in the calendar"))
|
|
|
|
menu.add_option(category_name, "alive", alive)
|
|
|
|
|
|
|
|
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)
|
2008-07-17 20:18:54 +05:30
|
|
|
|
2008-02-10 09:39:09 +05:30
|
|
|
def __add_notes_options(self, menu):
|
|
|
|
"""
|
|
|
|
Options on the "Months Notes" tabs.
|
|
|
|
"""
|
2008-07-17 18:35:15 +05:30
|
|
|
category_name = _("Jan - Jun Notes")
|
2007-08-27 09:22:06 +05:30
|
|
|
|
2008-07-17 20:18:54 +05:30
|
|
|
note_jan = StringOption(_('Jan Note'), _('This prints in January'))
|
2008-02-10 09:39:09 +05:30
|
|
|
note_jan.set_help(_("The note for the month of January"))
|
|
|
|
menu.add_option(category_name, "note_jan", note_jan)
|
2008-07-17 20:18:54 +05:30
|
|
|
|
|
|
|
note_feb = StringOption(_('Feb Note'), _('This prints in February'))
|
2008-02-10 09:39:09 +05:30
|
|
|
note_feb.set_help(_("The note for the month of February"))
|
|
|
|
menu.add_option(category_name, "note_feb", note_feb)
|
2008-07-17 20:18:54 +05:30
|
|
|
|
|
|
|
note_mar = StringOption(_('Mar Note'), _('This prints in March'))
|
2008-02-10 09:39:09 +05:30
|
|
|
note_mar.set_help(_("The note for the month of March"))
|
|
|
|
menu.add_option(category_name, "note_mar", note_mar)
|
2008-07-17 20:18:54 +05:30
|
|
|
|
|
|
|
note_apr = StringOption(_('Apr Note'), _('This prints in April'))
|
2008-02-10 09:39:09 +05:30
|
|
|
note_apr.set_help(_("The note for the month of April"))
|
|
|
|
menu.add_option(category_name, "note_apr", note_apr)
|
2008-07-17 20:18:54 +05:30
|
|
|
|
|
|
|
note_may = StringOption(_('May Note'), _('This prints in May'))
|
2008-02-10 09:39:09 +05:30
|
|
|
note_may.set_help(_("The note for the month of May"))
|
|
|
|
menu.add_option(category_name, "note_may", note_may)
|
2008-07-17 20:18:54 +05:30
|
|
|
|
|
|
|
note_jun = StringOption(_('Jun Note'), _('This prints in June'))
|
2008-02-10 09:39:09 +05:30
|
|
|
note_jun.set_help(_("The note for the month of June"))
|
|
|
|
menu.add_option(category_name, "note_jun", note_jun)
|
2008-07-17 20:18:54 +05:30
|
|
|
|
2008-07-17 18:35:15 +05:30
|
|
|
category_name = _("Jul - Dec Notes")
|
2007-08-27 09:22:06 +05:30
|
|
|
|
2008-07-17 20:18:54 +05:30
|
|
|
note_jul = StringOption(_('Jul Note'), _('This prints in July'))
|
2008-02-10 09:39:09 +05:30
|
|
|
note_jul.set_help(_("The note for the month of July"))
|
|
|
|
menu.add_option(category_name, "note_jul", note_jul)
|
2008-07-17 20:18:54 +05:30
|
|
|
|
|
|
|
note_aug = StringOption(_('Aug Note'), _('This prints in August'))
|
2008-02-10 09:39:09 +05:30
|
|
|
note_aug.set_help(_("The note for the month of August"))
|
|
|
|
menu.add_option(category_name, "note_aug", note_aug)
|
2008-07-17 20:18:54 +05:30
|
|
|
|
|
|
|
note_sep = StringOption(_('Sep Note'), _('This prints in September'))
|
2008-02-10 09:39:09 +05:30
|
|
|
note_sep.set_help(_("The note for the month of September"))
|
|
|
|
menu.add_option(category_name, "note_sep", note_sep)
|
2008-07-17 20:18:54 +05:30
|
|
|
|
|
|
|
note_oct = StringOption(_('Oct Note'), _('This prints in October'))
|
2008-02-10 09:39:09 +05:30
|
|
|
note_oct.set_help(_("The note for the month of October"))
|
|
|
|
menu.add_option(category_name, "note_oct", note_oct)
|
2008-07-17 20:18:54 +05:30
|
|
|
|
|
|
|
note_nov = StringOption(_('Nov Note'), _('This prints in November'))
|
2008-02-10 09:39:09 +05:30
|
|
|
note_nov.set_help(_("The note for the month of November"))
|
|
|
|
menu.add_option(category_name, "note_nov", note_nov)
|
2008-07-17 20:18:54 +05:30
|
|
|
|
|
|
|
note_dec = StringOption(_('Dec Note'), _('This prints in December'))
|
2008-02-10 09:39:09 +05:30
|
|
|
note_dec.set_help(_("The note for the month of December"))
|
|
|
|
menu.add_option(category_name, "note_dec", note_dec)
|
2007-08-27 09:22:06 +05:30
|
|
|
|
2008-02-10 09:39:09 +05:30
|
|
|
def __update_filters(self):
|
|
|
|
"""
|
|
|
|
Update the filter list based on the selected person
|
|
|
|
"""
|
|
|
|
gid = self.__pid.get_value()
|
|
|
|
person = self.__db.get_person_from_gramps_id(gid)
|
|
|
|
filter_list = ReportUtils.get_person_filters(person, False)
|
|
|
|
self.__filter.set_filters(filter_list)
|
2008-07-17 20:18:54 +05:30
|
|
|
|
2008-02-10 09:39:09 +05:30
|
|
|
def __filter_changed(self):
|
|
|
|
"""
|
|
|
|
Handle filter change. If the filter is not specific to a person,
|
|
|
|
disable the person option
|
|
|
|
"""
|
|
|
|
filter_value = self.__filter.get_value()
|
|
|
|
if filter_value in [1, 2, 3, 4]:
|
|
|
|
# Filters 1, 2, 3 and 4 rely on the center person
|
|
|
|
self.__pid.set_available(True)
|
2007-08-27 09:22:06 +05:30
|
|
|
else:
|
2008-02-10 09:39:09 +05:30
|
|
|
# The rest don't
|
|
|
|
self.__pid.set_available(False)
|
|
|
|
|
2008-10-08 01:41:46 +05:30
|
|
|
def __multiyear_changed(self):
|
|
|
|
"""
|
|
|
|
Handles the ability to print multiple year calendars or not?
|
|
|
|
"""
|
|
|
|
|
|
|
|
self.__start_year.set_available(True)
|
|
|
|
if self.__multiyear.get_value():
|
|
|
|
self.__end_year.set_available(True)
|
|
|
|
else:
|
|
|
|
self.__end_year.set_available(False)
|
|
|
|
|
2008-08-05 01:01:38 +05:30
|
|
|
|
2008-10-08 01:41:46 +05:30
|
|
|
def _get_regular_surname(sex, name):
|
2008-08-05 01:01:38 +05:30
|
|
|
"""
|
|
|
|
Return a name string built from the components of the Name instance.
|
|
|
|
"""
|
|
|
|
surname = name.get_surname()
|
|
|
|
prefix = name.get_surname_prefix()
|
|
|
|
if prefix:
|
|
|
|
surname = prefix + " " + surname
|
2008-10-08 01:41:46 +05:30
|
|
|
if sex == gen.lib.Person.FEMALE:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
suffix = name.get_suffix()
|
|
|
|
if suffix:
|
|
|
|
surname = surname + ", " + suffix
|
2008-08-05 01:01:38 +05:30
|
|
|
return surname
|
|
|
|
|
|
|
|
def _get_short_name(person, maiden_name=None):
|
2008-07-30 02:53:44 +05:30
|
|
|
""" Return person's name, unless maiden_name given, unless married_name listed. """
|
|
|
|
# Get all of a person's names:
|
|
|
|
primary_name = person.get_primary_name()
|
2008-10-08 01:41:46 +05:30
|
|
|
sex = person.get_gender()
|
2008-07-30 02:53:44 +05:30
|
|
|
|
|
|
|
married_name = None
|
|
|
|
names = [primary_name] + person.get_alternate_names()
|
|
|
|
for n in names:
|
|
|
|
if int(n.get_type()) == gen.lib.NameType.MARRIED:
|
|
|
|
married_name = n
|
|
|
|
|
|
|
|
# Now, decide which to use:
|
|
|
|
if maiden_name is not None:
|
|
|
|
if married_name is not None:
|
2008-10-08 01:41:46 +05:30
|
|
|
first_name, family_name = married_name.get_first_name(), _get_regular_surname(sex, married_name)
|
2008-07-30 02:53:44 +05:30
|
|
|
call_name = married_name.get_call_name()
|
|
|
|
else:
|
|
|
|
first_name, family_name = primary_name.get_first_name(), maiden_name
|
|
|
|
call_name = primary_name.get_call_name()
|
|
|
|
else:
|
2008-10-08 01:41:46 +05:30
|
|
|
first_name, family_name = primary_name.get_first_name(), _get_regular_surname(sex, primary_name)
|
2008-07-30 02:53:44 +05:30
|
|
|
call_name = primary_name.get_call_name()
|
|
|
|
|
|
|
|
# If they have a nickname use it
|
|
|
|
if call_name is not None and call_name.strip() != "":
|
|
|
|
first_name = call_name.strip()
|
|
|
|
else: # else just get the first name:
|
|
|
|
first_name = first_name.strip()
|
|
|
|
if " " in first_name:
|
|
|
|
first_name, rest = first_name.split(" ", 1) # just one split max
|
|
|
|
return ("%s %s" % (first_name, family_name)).strip()
|
|
|
|
|
2008-10-08 01:41:46 +05:30
|
|
|
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
|
|
|
|
|
2009-01-27 04:27:25 +05:30
|
|
|
def _has_webpage_extension(fname):
|
|
|
|
for ext in ('.html', '.htm' '.shtml', '.cgi', '.php', '.php3'):
|
|
|
|
if fname.endswith(ext):
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2008-08-08 02:30:05 +05:30
|
|
|
# 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 ]
|
|
|
|
|
|
|
|
def _gramps2iso(dow):
|
|
|
|
""" Convert GRAMPS day of week to ISO day of week """
|
|
|
|
# GRAMPS: SUN = 1
|
|
|
|
# ISO: MON = 1
|
|
|
|
return (dow + 5) % 7 + 1
|
|
|
|
|
2008-10-08 01:41:46 +05:30
|
|
|
# define names for long and short month in GrampsLocale
|
|
|
|
_lng_month = GrampsLocale.long_months
|
|
|
|
_shrt_month = GrampsLocale.short_months
|
|
|
|
|
|
|
|
def _get_long_month_name(month):
|
|
|
|
return _lng_month[month]
|
|
|
|
|
|
|
|
def _get_short_month_name(month):
|
|
|
|
return _shrt_month[month]
|
|
|
|
|
2009-01-27 13:19:47 +05:30
|
|
|
def fill_day_list(evt_dte, 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...
|
|
|
|
|
|
|
|
evt_dte -- 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, evt_dte, line, _('Holiday')))
|
|
|
|
|
|
|
|
# birthday/ anniversary on this day
|
|
|
|
if bday_anniv_list > []:
|
|
|
|
for text, event, date in bday_anniv_list:
|
|
|
|
|
|
|
|
# '...' signifies an incomplete date for an event. See add_day_item()
|
|
|
|
txt_str = None
|
|
|
|
if date != '...':
|
|
|
|
|
|
|
|
# number of years married, ex: 10
|
|
|
|
nyears = evt_dte.get_year() - date.get_year()
|
|
|
|
|
|
|
|
# number of years for birthday, ex: 10 years
|
|
|
|
age_str = evt_dte - date
|
|
|
|
age_str.format(precision=1)
|
|
|
|
|
|
|
|
# a birthday
|
|
|
|
if event == 'Birthday':
|
|
|
|
|
|
|
|
if nyears == 0:
|
|
|
|
txt_str = _('%(person)s, <em>birth</em>') % {
|
|
|
|
'person' : text}
|
|
|
|
else:
|
|
|
|
txt_str = _('%(person)s, <em>%(age)s</em> old') % {
|
|
|
|
'person' : text,
|
|
|
|
'age' : age_str}
|
|
|
|
|
|
|
|
# an anniversary
|
|
|
|
elif event == 'Anniversary':
|
|
|
|
|
|
|
|
if nyears == 0:
|
|
|
|
txt_str = _('%(couple)s, <em>wedding</em>') % {
|
|
|
|
'couple' : text}
|
|
|
|
else:
|
|
|
|
txt_str = _('%(couple)s, <em>%(years)d</em> year anniversary') % {
|
|
|
|
'couple' : text,
|
|
|
|
'years' : nyears}
|
|
|
|
txt_str = '<span class="yearsmarried">%s</span>' % txt_str
|
|
|
|
|
|
|
|
if txt_str is not None:
|
|
|
|
day_list.append((nyears, 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
|
|
|
|
|
2007-08-27 09:22:06 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2008-05-19 00:54:28 +05:30
|
|
|
pmgr = PluginManager.get_instance()
|
|
|
|
pmgr.register_report(
|
2007-08-27 09:22:06 +05:30
|
|
|
name = 'WebCal',
|
|
|
|
category = CATEGORY_WEB,
|
2008-02-10 09:39:09 +05:30
|
|
|
report_class = WebCalReport,
|
|
|
|
options_class = WebCalOptions,
|
2008-10-02 09:32:10 +05:30
|
|
|
modes = PluginManager.REPORT_MODE_GUI,
|
2008-03-02 04:17:48 +05:30
|
|
|
translated_name = _("Web Calendar"),
|
2008-03-03 00:46:34 +05:30
|
|
|
status = _("Stable"),
|
2008-03-02 04:17:48 +05:30
|
|
|
author_name = "Thom Sturgill",
|
|
|
|
author_email = "thsturgill@yahoo.com",
|
|
|
|
description = _("Produces web (HTML) calendars."),
|
2007-08-27 09:22:06 +05:30
|
|
|
)
|