2010-04-01 21:46:01 +05:30
|
|
|
# encoding: utf-8
|
2009-10-24 19:23:20 +05:30
|
|
|
#
|
2007-08-27 09:22:06 +05:30
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2010-03-20 06:01:03 +05:30
|
|
|
# Copyright (C) 2007 Thom Sturgill
|
2009-01-30 07:49:04 +05:30
|
|
|
# Copyright (C) 2007-2009 Brian G. Matherly
|
2011-01-18 07:08:04 +05:30
|
|
|
# Copyright (C) 2008-2011 Rob G. Healey <robhealey1@gmail.com>
|
2010-03-20 06:01:03 +05:30
|
|
|
# Copyright (C) 2008 Jason Simanek
|
2010-05-01 09:42:42 +05:30
|
|
|
# Copyright (C) 2010 Jakim Friant
|
2007-08-27 09:22:06 +05:30
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
2009-08-08 19:58:19 +05:30
|
|
|
# it under the terms of the GNU General Public License as published by
|
2007-08-27 09:22:06 +05:30
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
2009-12-10 12:20:21 +05:30
|
|
|
# This program is distributed in the hope that it will be useful,
|
2007-08-27 09:22:06 +05:30
|
|
|
# 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
|
|
|
|
#
|
|
|
|
|
2009-12-21 19:13:50 +05:30
|
|
|
# $Id$
|
2007-08-27 09:22:06 +05:30
|
|
|
|
|
|
|
"""
|
|
|
|
Web Calendar generator.
|
|
|
|
"""
|
2010-04-23 01:11:48 +05:30
|
|
|
|
2007-08-27 09:22:06 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
# python modules
|
|
|
|
#------------------------------------------------------------------------
|
2010-04-23 01:11:48 +05:30
|
|
|
from functools import partial
|
2009-09-24 02:01:21 +05:30
|
|
|
import os, codecs, shutil, re
|
2009-04-03 05:34:29 +05:30
|
|
|
import datetime, calendar
|
2010-01-18 10:12:17 +05:30
|
|
|
from gen.ggettext import sgettext as _
|
|
|
|
from gen.ggettext import ngettext
|
2009-11-03 19:52:37 +05:30
|
|
|
from itertools import imap
|
2007-08-27 09:22:06 +05:30
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
# Set up logging
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
import logging
|
|
|
|
log = logging.getLogger(".WebPage")
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
# GRAMPS module
|
|
|
|
#------------------------------------------------------------------------
|
2010-03-20 06:01:03 +05:30
|
|
|
import gen.lib
|
2007-08-27 09:22:06 +05:30
|
|
|
import const
|
2010-03-06 18:59:02 +05:30
|
|
|
import constfunc
|
2010-08-12 10:56:45 +05:30
|
|
|
from gen.plug.report import Report
|
2010-05-01 09:42:42 +05:30
|
|
|
from gen.plug.report import utils as ReportUtils
|
|
|
|
from gui.plug.report import MenuReportOptions
|
2008-09-27 19:26:17 +05:30
|
|
|
from gen.plug.menu import BooleanOption, NumberOption, StringOption, \
|
|
|
|
EnumeratedListOption, FilterOption, PersonOption, \
|
2009-09-24 02:01:21 +05:30
|
|
|
DestinationOption, NoteOption
|
2007-08-27 09:22:06 +05:30
|
|
|
import GrampsLocale
|
2009-01-30 07:49:04 +05:30
|
|
|
from QuestionDialog import WarningDialog
|
2009-06-19 20:53:58 +05:30
|
|
|
from Utils import probably_alive, xml_lang, get_researcher
|
|
|
|
from gui.utils import ProgressMeter
|
2008-07-17 18:35:15 +05:30
|
|
|
from DateHandler import displayer as _dd
|
2007-08-27 09:22:06 +05:30
|
|
|
|
2010-01-14 09:38:04 +05:30
|
|
|
from gen.display.name import displayer as _nd
|
2009-04-06 09:19:47 +05:30
|
|
|
|
2009-01-30 07:49:04 +05:30
|
|
|
import libholiday
|
2009-04-03 05:34:29 +05:30
|
|
|
from libhtml import Html
|
2009-06-06 15:19:40 +05:30
|
|
|
from libhtmlconst import _CHARACTER_SETS, _CC, _COPY_OPTIONS
|
2010-08-12 10:56:45 +05:30
|
|
|
from gui.pluginmanager import GuiPluginManager
|
2009-01-30 07:49:04 +05:30
|
|
|
|
2009-09-24 02:01:21 +05:30
|
|
|
# import styled notes from
|
|
|
|
# src/plugins/lib/libhtmlbackend.py
|
|
|
|
from libhtmlbackend import HtmlBackend
|
2007-08-27 09:22:06 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# constants
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2009-09-12 09:22:42 +05:30
|
|
|
# full clear line for proper styling
|
|
|
|
fullclear = Html("div", class_ = "fullclear", inline = True)
|
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
# Web page filename extensions
|
|
|
|
_WEB_EXT = ['.html', '.htm', '.shtml', '.php', '.php3', '.cgi']
|
|
|
|
|
2009-02-26 13:55:45 +05:30
|
|
|
# Calendar stylesheet names
|
|
|
|
_CALENDARSCREEN = 'calendar-screen.css'
|
|
|
|
_CALENDARPRINT = 'calendar-print.css'
|
|
|
|
|
2010-08-12 10:56:45 +05:30
|
|
|
PLUGMAN = GuiPluginManager.get_instance()
|
|
|
|
CSS = PLUGMAN.process_plugin_data('WEBSTUFF')
|
|
|
|
|
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)
|
2009-02-27 00:46:02 +05:30
|
|
|
mgobn = lambda name:options.menu.get_option_by_name(name).get_value()
|
2008-07-17 20:18:54 +05:30
|
|
|
|
2009-09-24 02:01:21 +05:30
|
|
|
# class to do conversion of styled notes to html markup
|
|
|
|
self._backend = HtmlBackend()
|
|
|
|
|
2007-08-27 09:22:06 +05:30
|
|
|
self.database = database
|
|
|
|
self.options = options
|
2008-07-17 20:18:54 +05:30
|
|
|
|
2009-02-27 00:46:02 +05:30
|
|
|
self.html_dir = mgobn('target')
|
|
|
|
self.title_text = mgobn('title')
|
|
|
|
filter_option = options.menu.get_option_by_name('filter')
|
2008-02-10 09:39:09 +05:30
|
|
|
self.filter = filter_option.get_filter()
|
2009-04-06 09:19:47 +05:30
|
|
|
self.name_format = mgobn('name_format')
|
2009-02-27 00:46:02 +05:30
|
|
|
self.ext = mgobn('ext')
|
|
|
|
self.copy = mgobn('cright')
|
|
|
|
self.css = mgobn('css')
|
2008-10-08 01:41:46 +05:30
|
|
|
|
2009-02-27 00:46:02 +05:30
|
|
|
self.country = mgobn('country')
|
|
|
|
self.start_dow = mgobn('start_dow')
|
2008-10-08 01:41:46 +05:30
|
|
|
|
2009-02-27 00:46:02 +05:30
|
|
|
self.multiyear = mgobn('multiyear')
|
|
|
|
self.start_year = mgobn('start_year')
|
|
|
|
self.end_year = mgobn('end_year')
|
2008-10-08 01:41:46 +05:30
|
|
|
|
2009-02-27 00:46:02 +05:30
|
|
|
self.maiden_name = mgobn('maiden_name')
|
2008-10-08 01:41:46 +05:30
|
|
|
|
2009-02-27 00:46:02 +05:30
|
|
|
self.alive = mgobn('alive')
|
|
|
|
self.birthday = mgobn('birthdays')
|
|
|
|
self.anniv = mgobn('anniversaries')
|
|
|
|
self.home_link = mgobn('home_link')
|
2009-02-26 13:55:45 +05:30
|
|
|
|
2011-01-27 01:40:22 +05:30
|
|
|
self.month_notes = [mgobn('note_' + month)
|
2009-02-27 00:46:02 +05:30
|
|
|
for month in ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul',
|
|
|
|
'aug', 'sep', 'oct', 'nov', 'dec']]
|
2008-07-17 20:18:54 +05:30
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
self.encoding = mgobn('encoding')
|
|
|
|
self.fullyear = mgobn('fullyear')
|
|
|
|
self.makeoneday = mgobn('makeoneday')
|
|
|
|
|
2008-10-08 01:41:46 +05:30
|
|
|
# identify researcher name and e-mail address
|
2009-02-26 13:55:45 +05:30
|
|
|
# as NarrativeWeb already does
|
2008-10-08 01:41:46 +05:30
|
|
|
researcher = get_researcher()
|
|
|
|
self.author = researcher.name
|
|
|
|
if self.author:
|
|
|
|
self.author = self.author.replace(',,,', '')
|
|
|
|
self.email = researcher.email
|
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
# set to today's date
|
2010-03-20 06:01:03 +05:30
|
|
|
self.today = gen.lib.date.Today()
|
2008-10-08 01:41:46 +05:30
|
|
|
|
2008-08-05 02:16:46 +05:30
|
|
|
self.warn_dir = True # Only give warning once.
|
2009-10-08 11:18:43 +05:30
|
|
|
|
2009-10-07 10:45:34 +05:30
|
|
|
self.link_to_narweb = mgobn('link_to_narweb')
|
|
|
|
self.narweb_prefix = mgobn('prefix')
|
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 = {}
|
|
|
|
|
2009-02-10 12:49:56 +05:30
|
|
|
calendar.setfirstweekday(dow_gramps2iso[self.start_dow])
|
2008-08-12 01:49:51 +05:30
|
|
|
|
2009-09-24 02:01:21 +05:30
|
|
|
def get_note_format(self, note):
|
|
|
|
"""
|
|
|
|
will get the note from the database, and will return either the
|
|
|
|
styled text or plain note
|
|
|
|
"""
|
|
|
|
|
|
|
|
# retrieve the body of the note
|
|
|
|
note_text = note.get()
|
|
|
|
|
|
|
|
# styled notes
|
|
|
|
htmlnotetext = self.styled_note(note.get_styledtext(),
|
|
|
|
note.get_format())
|
2009-12-24 13:25:26 +05:30
|
|
|
text = htmlnotetext or Html("p", note_text)
|
2009-09-24 02:01:21 +05:30
|
|
|
|
|
|
|
# return text of the note to its callers
|
|
|
|
return text
|
|
|
|
|
|
|
|
#################################################
|
2009-12-24 13:25:26 +05:30
|
|
|
# Will produce styled notes for WebCal by using:
|
2009-09-24 02:01:21 +05:30
|
|
|
# src/plugins/lib/libhtmlbackend.py
|
|
|
|
#################################################
|
|
|
|
def styled_note(self, styledtext, format):
|
|
|
|
"""
|
|
|
|
styledtext : assumed a StyledText object to write
|
|
|
|
format : = 0 : Flowed, = 1 : Preformatted
|
|
|
|
style_name : name of the style to use for default presentation
|
|
|
|
"""
|
|
|
|
text = str(styledtext)
|
|
|
|
|
|
|
|
if not text:
|
|
|
|
return ''
|
|
|
|
|
|
|
|
s_tags = styledtext.get_tags()
|
|
|
|
#FIXME: following split should be regex to match \n\s*\n instead?
|
|
|
|
markuptext = self._backend.add_markup_from_styled(text, s_tags,
|
|
|
|
split='\n\n')
|
|
|
|
htmllist = Html("div", id="grampsstylednote")
|
|
|
|
if format == 1:
|
|
|
|
#preformatted, retain whitespace.
|
|
|
|
#so use \n\n for paragraph detection
|
|
|
|
#FIXME: following split should be regex to match \n\s*\n instead?
|
|
|
|
htmllist += Html('pre', indent=None, inline = True)
|
|
|
|
for line in markuptext.split('\n\n'):
|
2009-12-24 13:25:26 +05:30
|
|
|
htmllist += Html("p")
|
2009-09-24 02:01:21 +05:30
|
|
|
for realline in line.split('\n'):
|
|
|
|
htmllist += realline
|
|
|
|
htmllist += Html('br')
|
|
|
|
|
|
|
|
elif format == 0:
|
|
|
|
#flowed
|
|
|
|
#FIXME: following split should be regex to match \n\s*\n instead?
|
|
|
|
for line in markuptext.split('\n\n'):
|
2009-12-24 13:25:26 +05:30
|
|
|
htmllist += Html("p")
|
2009-09-24 02:01:21 +05:30
|
|
|
htmllist += line
|
|
|
|
|
|
|
|
return htmllist
|
2009-03-21 04:43:06 +05:30
|
|
|
|
2009-12-24 13:25:26 +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
|
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
# ---------------------------------------------------------------------------------------
|
2009-04-03 05:34:29 +05:30
|
|
|
# Adds Birthdays, Anniversaries, and holidays
|
2009-03-21 04:43:06 +05:30
|
|
|
# ---------------------------------------------------------------------------------------
|
2008-10-08 01:41:46 +05:30
|
|
|
def add_day_item(self, text, year, month, day, event):
|
2009-04-03 05:34:29 +05:30
|
|
|
"""
|
|
|
|
adds birthdays, anniversaries, and holidays to their perspective lists
|
|
|
|
|
|
|
|
text -- line to be added
|
|
|
|
year, month, day -- date to add the text to
|
|
|
|
|
|
|
|
event -- one of 'BirthDay', 'Anniversary', or 'Holiday'
|
|
|
|
"""
|
|
|
|
|
|
|
|
# This may happen for certain "about" dates.
|
|
|
|
# Use first day of the month
|
2008-07-31 03:07:24 +05:30
|
|
|
if day == 0:
|
2009-04-03 05:34:29 +05:30
|
|
|
day = 1
|
2009-03-26 16:47:57 +05:30
|
|
|
|
|
|
|
# determine which dictionary to use???
|
|
|
|
if event in ['Birthday', 'Anniversary']:
|
|
|
|
month_dict = self.calendar.get(month, {})
|
|
|
|
else:
|
|
|
|
month_dict = self.holidays.get(month, {})
|
2007-08-27 09:22:06 +05:30
|
|
|
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:
|
2010-03-20 06:01:03 +05:30
|
|
|
event_date = gen.lib.Date(year, month, day)
|
2008-11-11 03:11:38 +05:30
|
|
|
except ValueError:
|
2010-03-20 06:01:03 +05:30
|
|
|
event_date = gen.lib.Date.EMPTY
|
2008-10-08 01:41:46 +05:30
|
|
|
else:
|
2010-03-20 06:01:03 +05:30
|
|
|
event_date = gen.lib.Date.EMPTY # Incomplete date....
|
2008-11-11 03:11:38 +05:30
|
|
|
|
2009-02-04 11:05:34 +05:30
|
|
|
day_list.append((text, event, event_date))
|
2007-08-27 09:22:06 +05:30
|
|
|
month_dict[day] = day_list
|
2009-03-26 16:47:57 +05:30
|
|
|
|
|
|
|
# determine which dictionary to add it to???
|
|
|
|
if event in ['Birthday', 'Anniversary']:
|
|
|
|
self.calendar[month] = month_dict
|
|
|
|
else:
|
|
|
|
self.holidays[month] = month_dict
|
2007-08-27 09:22:06 +05:30
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
# ---------------------------------------------------------------------------------------
|
2009-03-26 16:47:57 +05:30
|
|
|
# Retrieves Holidays from the Holiday file,
|
|
|
|
# src/plugins/lib/holidays.xml
|
2009-03-21 04:43:06 +05:30
|
|
|
# ---------------------------------------------------------------------------------------
|
2009-01-30 07:49:04 +05:30
|
|
|
def __get_holidays(self, year):
|
2009-03-21 04:43:06 +05:30
|
|
|
|
2010-02-10 22:26:53 +05:30
|
|
|
# _('translation')
|
|
|
|
self.progress.set_pass((_('Calculating Holidays for year %04d') % year), 365)
|
2009-03-21 04:43:06 +05:30
|
|
|
|
2009-01-30 07:49:04 +05:30
|
|
|
""" 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:
|
2009-03-26 16:47:57 +05:30
|
|
|
self.add_day_item(holiday_name, year, month, day, 'Holiday')
|
2009-02-10 12:49:56 +05:30
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
# increment progress bar
|
|
|
|
self.progress.step()
|
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------------------
|
|
|
|
# Copies all of the calendar files for all calendars
|
|
|
|
# ---------------------------------------------------------------------------------------
|
2008-10-08 01:41:46 +05:30
|
|
|
def copy_calendar_files(self):
|
2007-08-27 09:22:06 +05:30
|
|
|
"""
|
2009-02-08 02:11:27 +05:30
|
|
|
Copies all the necessary stylesheets and images for these calendars
|
2007-08-27 09:22:06 +05:30
|
|
|
"""
|
2009-02-08 02:11:27 +05:30
|
|
|
# Copy the screen stylesheet
|
|
|
|
if self.css:
|
2010-08-12 10:56:45 +05:30
|
|
|
fname = CSS[self.css]["filename"]
|
2009-02-26 13:55:45 +05:30
|
|
|
self.copy_file(fname, _CALENDARSCREEN, "styles")
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2010-03-27 04:21:53 +05:30
|
|
|
# copy Navigation Menu Layout if Blue or Visually is being used
|
2010-08-12 10:56:45 +05:30
|
|
|
if CSS[self.css]["navigation"]:
|
|
|
|
fname = CSS["Navigation-Horizontal"]["filename"]
|
2010-03-27 04:21:53 +05:30
|
|
|
self.copy_file(fname, "Web_Navigation-Menus.css", "styles")
|
|
|
|
|
2008-12-05 02:08:02 +05:30
|
|
|
# copy print stylesheet
|
2010-08-12 10:56:45 +05:30
|
|
|
fname = CSS["Print-Default"]["filename"]
|
2009-02-26 13:55:45 +05:30
|
|
|
self.copy_file(fname, _CALENDARPRINT, "styles")
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2009-02-08 02:11:27 +05:30
|
|
|
imgs = []
|
|
|
|
|
2010-08-12 10:56:45 +05:30
|
|
|
# Mainz stylesheet graphics
|
|
|
|
# will only be used if Mainz is slected as the stylesheet
|
|
|
|
imgs += CSS[self.css]["images"]
|
2009-02-08 02:11:27 +05:30
|
|
|
|
2008-10-08 01:41:46 +05:30
|
|
|
# copy copyright image
|
2011-03-08 02:12:00 +05:30
|
|
|
# the proper way would be to call "filename", but it is NOT working...
|
2009-02-22 05:44:08 +05:30
|
|
|
if 0 < self.copy <= len(_CC):
|
2011-03-08 04:04:38 +05:30
|
|
|
imgs += [CSS["Copyright"]["filename"]]
|
2011-03-08 02:12:00 +05:30
|
|
|
|
|
|
|
# copy Gramps favicon #2
|
2011-03-08 04:04:38 +05:30
|
|
|
imgs += [CSS["favicon2"]["filename"]]
|
2008-10-08 01:41:46 +05:30
|
|
|
|
2010-08-12 10:56:45 +05:30
|
|
|
for from_path in imgs:
|
|
|
|
fdir, fname = os.path.split(from_path)
|
2009-02-08 02:11:27 +05:30
|
|
|
self.copy_file(from_path, fname, "images")
|
2008-10-22 00:27:42 +05:30
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
# ---------------------------------------------------------------------------------------
|
|
|
|
# Creates file name passed to it
|
|
|
|
# ---------------------------------------------------------------------------------------
|
|
|
|
def create_file(self, fname, subdir):
|
2008-07-31 03:07:24 +05:30
|
|
|
"""
|
2009-03-21 04:43:06 +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
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
fname -- filename to be created
|
|
|
|
subdir -- any subdirs to be added
|
2008-10-08 01:41:46 +05:30
|
|
|
"""
|
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
fname = os.path.join(self.html_dir, subdir, fname)
|
2008-10-08 01:41:46 +05:30
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
if not _has_webpage_extension(fname):
|
|
|
|
fname += self.ext
|
2008-10-08 01:41:46 +05:30
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
destdir = os.path.dirname(fname)
|
2008-10-08 01:41:46 +05:30
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
if not os.path.isdir(destdir):
|
|
|
|
os.makedirs(destdir)
|
2008-10-08 01:41:46 +05:30
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
of = codecs.EncodedFile(open(fname, "w"), 'utf-8', self.encoding, 'xmlcharrefreplace')
|
|
|
|
return of
|
2008-10-08 01:41:46 +05:30
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
# ---------------------------------------------------------------------------------------
|
|
|
|
# Closes all file name passed to it
|
|
|
|
# ---------------------------------------------------------------------------------------
|
|
|
|
def close_file(self, of):
|
|
|
|
""" will close whatever filename is passed to it """
|
|
|
|
of.close()
|
2008-10-08 01:41:46 +05:30
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
# ---------------------------------------------------------------------------------------
|
|
|
|
# Beginning of Calendar Creation
|
|
|
|
# ---------------------------------------------------------------------------------------
|
2010-03-27 04:21:53 +05:30
|
|
|
def write_header(self, nr_up, title, body_id = None, add_print = True):
|
2009-03-21 04:43:06 +05:30
|
|
|
"""
|
|
|
|
This creates the header for the Calendars
|
|
|
|
'nr_up' - number of directory levels up, started from current page, to the
|
|
|
|
root of the directory tree (i.e. to self.html_dir).
|
|
|
|
title -- to be inserted into page header section
|
|
|
|
add_print -- whether to add printer stylesheet or not
|
|
|
|
* only webcalendar() and one_day() only!
|
|
|
|
"""
|
2009-02-12 16:09:13 +05:30
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
# number of subdirectories up to reach root
|
|
|
|
subdirs = '../'*nr_up
|
2009-02-13 01:36:32 +05:30
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
# Header contants
|
2009-04-06 09:19:47 +05:30
|
|
|
xmllang = xml_lang()
|
2009-11-03 00:37:32 +05:30
|
|
|
_META1 = 'name="generator" content="%s %s %s"' % \
|
|
|
|
(const.PROGRAM_NAME, const.VERSION, const.URL_HOMEPAGE)
|
2009-03-21 21:55:47 +05:30
|
|
|
_META2 = 'name="author" content="%s"' % self.author
|
|
|
|
|
2009-09-11 11:54:13 +05:30
|
|
|
page, head, body = Html.page(title, self.encoding, xmllang)
|
2009-03-21 04:43:06 +05:30
|
|
|
|
2010-03-27 04:21:53 +05:30
|
|
|
# add body id tag if not None
|
|
|
|
if body_id is not None:
|
|
|
|
body.attr = "id = '%(idtag)s'" % { 'idtag' : body_id }
|
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
# GRAMPS favicon
|
2010-09-11 22:36:49 +05:30
|
|
|
fname1 = os.path.join(subdirs, "images", "favicon2.ico")
|
2009-03-21 04:43:06 +05:30
|
|
|
|
|
|
|
# _CALENDARSCREEN stylesheet
|
2009-09-12 09:22:42 +05:30
|
|
|
fname2 = os.path.join(subdirs, "styles", _CALENDARSCREEN)
|
2009-03-21 04:43:06 +05:30
|
|
|
|
2009-03-21 21:55:47 +05:30
|
|
|
# create additional meta tags
|
2009-09-11 11:54:13 +05:30
|
|
|
meta = Html("meta", attr = _META1) + (
|
|
|
|
Html("meta", attr = _META2, indent=False)
|
2009-03-21 21:55:47 +05:30
|
|
|
)
|
2009-03-21 04:43:06 +05:30
|
|
|
|
2009-03-21 21:55:47 +05:30
|
|
|
# links for GRAMPS favicon and stylesheets
|
2010-09-11 22:36:49 +05:30
|
|
|
links = Html("link", rel = 'shortcut icon', href = fname1, type = "image/x-icon") + (
|
|
|
|
Html("link",rel = "stylesheet", href = fname2, type = "text/css", media = "screen", indent = False)
|
2009-03-21 04:43:06 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
# add printer stylesheet to webcalendar() and one_day() only
|
|
|
|
if add_print:
|
2009-09-12 09:22:42 +05:30
|
|
|
fname = os.path.join(subdirs, "styles", _CALENDARPRINT)
|
2010-09-11 22:36:49 +05:30
|
|
|
links += Html("link",rel = "stylesheet", href = fname,type = "text/css", media = "print", indent = False)
|
2010-03-27 04:21:53 +05:30
|
|
|
|
|
|
|
# add horizontal menu if css == Blue or Visually because there is no menus
|
2010-08-12 10:56:45 +05:30
|
|
|
if CSS[self.css]["navigation"]:
|
2010-03-27 04:21:53 +05:30
|
|
|
|
|
|
|
# Link to Navigation Menus stylesheet
|
|
|
|
fname = os.path.join(subdirs, "styles", "Web_Navigation-Menus.css")
|
2010-09-11 22:36:49 +05:30
|
|
|
links.extend(
|
|
|
|
Html("link", href = fname, type = "text/css", media = "screen", rel = "stylesheet")
|
|
|
|
)
|
2009-03-21 04:43:06 +05:30
|
|
|
|
2009-12-24 13:25:26 +05:30
|
|
|
# add meta tags and links to head section
|
|
|
|
head += (meta, links)
|
|
|
|
|
2009-03-24 20:28:16 +05:30
|
|
|
# start header division section
|
2010-09-11 22:36:49 +05:30
|
|
|
header = Html("div", id = "header") + (
|
2009-03-24 20:28:16 +05:30
|
|
|
|
|
|
|
# page title
|
2009-09-11 11:54:13 +05:30
|
|
|
Html("h1", title, id = "SiteTitle", inline = True)
|
2009-03-24 20:28:16 +05:30
|
|
|
)
|
2009-09-24 02:01:21 +05:30
|
|
|
body += header
|
2009-03-24 20:28:16 +05:30
|
|
|
|
|
|
|
# Created for ?
|
2009-09-24 02:01:21 +05:30
|
|
|
msg = None
|
|
|
|
if self.author and self.email:
|
|
|
|
msg = _('Created for <a href="mailto:%(email)s?'
|
|
|
|
'subject=WebCal">%(author)s</a>') % {'email' : self.email,
|
|
|
|
'author' : self.author}
|
|
|
|
elif self.author:
|
|
|
|
msg = _('Created for %(author)s') % {'author' : self.author}
|
2009-03-24 20:28:16 +05:30
|
|
|
|
2009-09-24 02:01:21 +05:30
|
|
|
if msg is not None:
|
2010-09-11 22:36:49 +05:30
|
|
|
header += Html("p", msg, id = "CreatorInfo")
|
2009-03-24 20:28:16 +05:30
|
|
|
|
2009-12-24 13:25:26 +05:30
|
|
|
# return to its callers; either webcalendar(), year_glance(), or one_day()
|
2009-04-03 05:34:29 +05:30
|
|
|
return page, body
|
2008-10-08 01:41:46 +05:30
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
# ---------------------------------------------------------------------------------------
|
|
|
|
# Creates year navigation, if multiyear
|
|
|
|
# ---------------------------------------------------------------------------------------
|
2009-03-24 20:28:16 +05:30
|
|
|
def year_navigation(self, nr_up, currentsection):
|
2008-07-31 03:07:24 +05:30
|
|
|
"""
|
2009-09-24 02:01:21 +05:30
|
|
|
This will create the year navigation menu bar for a total of seventeen (17) years
|
2009-02-08 02:11:27 +05:30
|
|
|
|
|
|
|
nr_up = number of directories up to reach root directory
|
|
|
|
currentsection = proper styling of this navigation bar
|
2008-10-08 01:41:46 +05:30
|
|
|
"""
|
|
|
|
|
2009-09-24 02:01:21 +05:30
|
|
|
# limit number of years to eighteen (18) years and only one row of years
|
|
|
|
nyears = ((self.end_year - self.start_year) + 1)
|
|
|
|
num_years = nyears if 0 < nyears < 19 else 18
|
2008-10-08 01:41:46 +05:30
|
|
|
|
2009-09-24 02:01:21 +05:30
|
|
|
# begin year division and begin unordered list
|
|
|
|
with Html("div", id = "subnavigation") as section:
|
|
|
|
unordered = Html("ul")
|
|
|
|
section += unordered
|
2008-10-08 01:41:46 +05:30
|
|
|
|
2009-09-24 02:01:21 +05:30
|
|
|
for cal_year in xrange(self.start_year, (self.start_year + num_years)):
|
|
|
|
url = ''
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2009-09-24 02:01:21 +05:30
|
|
|
# begin subdir level
|
|
|
|
subdirs = ['..'] * nr_up
|
|
|
|
subdirs.append(str(cal_year))
|
2008-10-08 01:41:46 +05:30
|
|
|
|
2009-09-24 02:01:21 +05:30
|
|
|
# each year will link to current month.
|
|
|
|
# this will always need an extension added
|
2011-05-17 05:51:22 +05:30
|
|
|
full_month_name = _dd.long_months[self.today.get_month() ]
|
2009-03-21 04:43:06 +05:30
|
|
|
|
2009-09-24 02:01:21 +05:30
|
|
|
# Note. We use '/' here because it is a URL, not a OS dependent
|
|
|
|
# pathname.
|
|
|
|
url = '/'.join(subdirs + [full_month_name]) + self.ext
|
2008-10-08 01:41:46 +05:30
|
|
|
|
2009-09-24 02:01:21 +05:30
|
|
|
# Figure out if we need <li class="CurrentSection"> or just plain <li>
|
|
|
|
cs = str(cal_year) == currentsection and 'class="CurrentSection"' or ''
|
2010-04-22 06:57:53 +05:30
|
|
|
unordered += Html("li", attr = cs, inline = True) + (
|
2011-05-17 05:51:22 +05:30
|
|
|
Html("a", str(cal_year), href = url, title = str(cal_year) ) )
|
2008-10-08 01:41:46 +05:30
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
# return yearnav to its caller
|
2009-09-22 03:52:45 +05:30
|
|
|
return section
|
2009-03-21 04:43:06 +05:30
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------------------
|
|
|
|
# Creates month navigation for all Calendars
|
|
|
|
# ---------------------------------------------------------------------------------------
|
2009-03-24 20:28:16 +05:30
|
|
|
def month_navigation(self, nr_up, year, currentsection, add_home):
|
2008-10-08 01:41:46 +05:30
|
|
|
"""
|
2009-03-21 04:43:06 +05:30
|
|
|
Will create and display the navigation menu bar
|
2009-02-08 02:11:27 +05:30
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
of = calendar filename being created
|
|
|
|
nr_up = number of directories up to reach root directory
|
2009-02-08 02:11:27 +05:30
|
|
|
year = year being created
|
2009-03-21 04:43:06 +05:30
|
|
|
currentsection = month name being created for proper CSS styling
|
|
|
|
use_home = if creating a link to home
|
|
|
|
-- a link to root directory of website
|
2008-10-08 01:41:46 +05:30
|
|
|
"""
|
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
navs = []
|
2008-10-08 01:41:46 +05:30
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
# An optional link to a home page
|
2010-10-15 22:52:05 +05:30
|
|
|
if self.home_link:
|
2011-05-17 05:51:22 +05:30
|
|
|
navs.append((self.home_link, _('Home'), add_home))
|
2010-03-27 04:21:53 +05:30
|
|
|
navs.extend(
|
2011-05-17 05:51:22 +05:30
|
|
|
(_dd.long_months[month], _dd.short_months[month], True) for month in xrange(1, 13) )
|
2009-03-21 04:43:06 +05:30
|
|
|
|
|
|
|
# Add a link for year_glance() if requested
|
|
|
|
navs.append(('fullyearlinked', _('Year Glance'), self.fullyear))
|
|
|
|
|
2009-09-22 03:52:45 +05:30
|
|
|
# begin month subnavigation
|
2009-09-24 02:01:21 +05:30
|
|
|
with Html("div", id = "navigation") as section:
|
2009-03-21 04:43:06 +05:30
|
|
|
|
2009-09-22 03:52:45 +05:30
|
|
|
unordered = Html("ul")
|
|
|
|
section += unordered
|
2009-03-21 04:43:06 +05:30
|
|
|
|
2009-09-22 03:52:45 +05:30
|
|
|
navs = [(u, n) for u, n, c in navs if c]
|
|
|
|
for url_fname, nav_text in navs:
|
2009-03-21 04:43:06 +05:30
|
|
|
|
2009-09-22 03:52:45 +05:30
|
|
|
# Note. We use '/' here because it is a URL, not a OS dependent pathname
|
|
|
|
# need to leave home link alone, so look for it ...
|
|
|
|
url = url_fname
|
|
|
|
add_subdirs = True
|
|
|
|
if not (url.startswith('http:') or url.startswith('/')):
|
2009-11-03 00:37:32 +05:30
|
|
|
add_subdirs = not any(url.endswith(ext)
|
|
|
|
for ext in _WEB_EXT)
|
2009-09-22 03:52:45 +05:30
|
|
|
|
|
|
|
# whether to add subdirs or not???
|
|
|
|
if add_subdirs:
|
|
|
|
subdirs = ['..'] * nr_up
|
|
|
|
subdirs.append(str(year))
|
|
|
|
url = '/'.join(subdirs + [url_fname])
|
2009-03-21 04:43:06 +05:30
|
|
|
|
2009-09-22 03:52:45 +05:30
|
|
|
if not _has_webpage_extension(url):
|
|
|
|
url += self.ext
|
2008-10-08 01:41:46 +05:30
|
|
|
|
2009-09-22 03:52:45 +05:30
|
|
|
# Figure out if we need <li class="CurrentSection"> or just plain <li>
|
|
|
|
cs = url_fname == currentsection and 'class="CurrentSection"' or ''
|
2011-05-17 06:15:35 +05:30
|
|
|
|
|
|
|
if nav_text == _("Home"):
|
|
|
|
title = _("Narrative Web Home")
|
|
|
|
else:
|
|
|
|
title = url_fname
|
2009-09-22 03:52:45 +05:30
|
|
|
unordered += Html("li", attr = cs, inline = True) + (
|
2009-03-21 04:43:06 +05:30
|
|
|
|
2009-09-22 03:52:45 +05:30
|
|
|
# create hyperlink
|
2011-05-17 06:15:35 +05:30
|
|
|
Html("a", nav_text, href = url, title = title) )
|
2009-03-21 04:43:06 +05:30
|
|
|
|
|
|
|
# return monthnav to its caller
|
2009-09-22 03:52:45 +05:30
|
|
|
return section
|
2009-03-21 04:43:06 +05:30
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------------------
|
|
|
|
# Creates the Calendar Table
|
|
|
|
# ---------------------------------------------------------------------------------------
|
|
|
|
def calendar_build(self, cal, year, month):
|
2008-07-17 18:35:15 +05:30
|
|
|
"""
|
|
|
|
This does the work of building the calendar
|
2009-12-14 14:17:01 +05:30
|
|
|
|
|
|
|
@param: cal - either "yg" year_glance(), or "wc" webcalendar()
|
|
|
|
@param: year -- year being created
|
|
|
|
@param: 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
|
2011-05-17 05:51:22 +05:30
|
|
|
full_month_name = _dd.long_months[month]
|
|
|
|
abbr_month_name = _dd.short_months[month]
|
2008-10-08 01:41:46 +05:30
|
|
|
|
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)]
|
|
|
|
|
|
|
|
def get_class_for_daycol(col):
|
2009-02-10 12:49:56 +05:30
|
|
|
""" Translate a Gramps day number into a HTMLclass """
|
2008-08-08 02:30:05 +05:30
|
|
|
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):
|
2009-02-10 12:49:56 +05:30
|
|
|
""" Translate a Gramps day number into a HTMLclass """
|
2008-08-08 02:30:05 +05:30
|
|
|
day = col2day[col]
|
|
|
|
return day_names[day]
|
|
|
|
|
2009-02-03 13:31:31 +05:30
|
|
|
# Note. GrampsLocale has sunday => 1, monday => 2, etc
|
|
|
|
# We slice out the first empty element.
|
|
|
|
day_names = GrampsLocale.long_days
|
2008-08-08 02:30:05 +05:30
|
|
|
|
2009-09-24 02:01:21 +05:30
|
|
|
def __get_previous_month_day(year, month, day_col):
|
|
|
|
|
|
|
|
if month == 1:
|
|
|
|
prevmonth = calendar.monthcalendar(year - 1, 12)
|
|
|
|
else:
|
|
|
|
prevmonth = calendar.monthcalendar(year, month-1)
|
|
|
|
num_weeks = len(prevmonth)
|
|
|
|
lastweek_prevmonth = prevmonth[num_weeks - 1]
|
|
|
|
previous_month_day = lastweek_prevmonth[day_col]
|
|
|
|
|
|
|
|
# return previous month day number based on day_col
|
|
|
|
# day_col is based on range(0 - 6)
|
|
|
|
return previous_month_day
|
|
|
|
|
|
|
|
def __get_next_month_day(year, month, day_col):
|
|
|
|
|
|
|
|
if month == 12:
|
|
|
|
nextmonth = calendar.monthcalendar(year + 1, 1)
|
|
|
|
else:
|
|
|
|
nextmonth = calendar.monthcalendar(year, month + 1)
|
|
|
|
firstweek_nextmonth = nextmonth[0]
|
|
|
|
next_month_day = firstweek_nextmonth[day_col]
|
|
|
|
|
|
|
|
# return next month day number based on day_col
|
|
|
|
# day_col is based on range(0 - 6)
|
|
|
|
return next_month_day
|
|
|
|
|
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.
|
2009-02-04 06:29:12 +05:30
|
|
|
month_name = full_month_name.capitalize()
|
2008-10-08 01:41:46 +05:30
|
|
|
th_txt = month_name
|
2009-03-21 04:43:06 +05:30
|
|
|
if cal == 'wc': # webcalendar()
|
2008-10-08 01:41:46 +05:30
|
|
|
if not self.multiyear:
|
|
|
|
th_txt = '%s %d' % (month_name, year)
|
2009-03-21 04:43:06 +05:30
|
|
|
|
2009-09-24 02:01:21 +05:30
|
|
|
# begin calendar table and table head
|
2009-12-14 14:17:01 +05:30
|
|
|
with Html("table", class_ = "calendar", id = month_name) as table:
|
2009-03-21 04:43:06 +05:30
|
|
|
|
2009-12-14 14:17:01 +05:30
|
|
|
thead = Html("thead")
|
|
|
|
table += thead
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2009-12-14 14:17:01 +05:30
|
|
|
trow = Html("tr") + (
|
|
|
|
Html("th", th_txt, class_ ='monthName', colspan=7, inline = True)
|
2009-03-26 16:47:57 +05:30
|
|
|
)
|
2009-12-14 14:17:01 +05:30
|
|
|
thead += trow
|
2009-03-21 04:43:06 +05:30
|
|
|
|
2009-12-14 14:17:01 +05:30
|
|
|
# Calendar weekday names header
|
|
|
|
trow = Html("tr")
|
|
|
|
thead += trow
|
|
|
|
|
|
|
|
for day_col in range(7):
|
|
|
|
dayclass = get_class_for_daycol(day_col)
|
|
|
|
dayname = get_name_for_daycol(day_col)
|
|
|
|
trow += Html("th", class_ =dayclass, inline = True) + (
|
2009-12-24 13:25:26 +05:30
|
|
|
Html('abbr', dayname[0], title = dayname)
|
2009-12-14 14:17:01 +05:30
|
|
|
)
|
2008-07-31 03:07:24 +05:30
|
|
|
|
2009-12-14 14:17:01 +05:30
|
|
|
# begin table body
|
|
|
|
tbody = Html("tbody")
|
|
|
|
table += tbody
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2009-12-14 14:17:01 +05:30
|
|
|
# get first of the month and month information
|
|
|
|
current_date, current_ord, monthinfo = get_first_day_of_month(year, month)
|
2009-03-21 04:43:06 +05:30
|
|
|
|
2009-12-14 14:17:01 +05:30
|
|
|
# begin calendar table rows, starting week0
|
|
|
|
nweeks = len(monthinfo)
|
|
|
|
for week_row in range(0, nweeks):
|
|
|
|
week = monthinfo[week_row]
|
2008-07-31 03:07:24 +05:30
|
|
|
|
2009-12-14 14:17:01 +05:30
|
|
|
# if you look this up in wikipedia, the first week is called week0
|
|
|
|
trow = Html("tr", class_ = "week%02d" % week_row)
|
|
|
|
tbody += trow
|
2008-07-31 03:07:24 +05:30
|
|
|
|
2009-12-14 14:17:01 +05:30
|
|
|
# begin calendar day column
|
|
|
|
for day_col in range(0, 7):
|
|
|
|
dayclass = get_class_for_daycol(day_col)
|
2009-03-21 04:43:06 +05:30
|
|
|
|
2009-12-14 14:17:01 +05:30
|
|
|
# day number, can also be a zero -- a day before or after month
|
|
|
|
day = week[day_col]
|
2009-03-21 04:43:06 +05:30
|
|
|
|
2009-12-14 14:17:01 +05:30
|
|
|
# start the beginning variable for <td>, table cell
|
|
|
|
tcell_id = "%s%02d" % (abbr_month_name, day)
|
2009-03-21 04:43:06 +05:30
|
|
|
|
2009-12-14 14:17:01 +05:30
|
|
|
# add calendar date division
|
|
|
|
datediv = Html("div", day, class_ = "date", inline = True)
|
2009-03-26 16:47:57 +05:30
|
|
|
|
2009-12-14 14:17:01 +05:30
|
|
|
# a day in the previous or next month
|
|
|
|
if day == 0:
|
2009-03-26 16:47:57 +05:30
|
|
|
|
2009-12-14 14:17:01 +05:30
|
|
|
# day in previous month
|
|
|
|
specday = __get_previous_month_day(year, month, day_col) if week_row == 0 \
|
|
|
|
else __get_next_month_day(year, month, day_col)
|
2008-07-31 03:07:24 +05:30
|
|
|
|
2009-12-14 14:17:01 +05:30
|
|
|
specclass = "previous " if week_row == 0 else "Next "
|
|
|
|
specclass += dayclass
|
2008-07-31 03:07:24 +05:30
|
|
|
|
2009-12-14 14:17:01 +05:30
|
|
|
# continue table cell, <td>, without id tag
|
|
|
|
tcell = Html("td", class_ = specclass, inline = True) + (
|
2009-03-21 04:43:06 +05:30
|
|
|
|
2009-12-14 14:17:01 +05:30
|
|
|
# adds date for previous and next month days
|
|
|
|
Html("div", specday, class_ = "date", inline = True)
|
|
|
|
)
|
2009-03-21 04:43:06 +05:30
|
|
|
|
2009-12-14 14:17:01 +05:30
|
|
|
# normal day number in current month
|
|
|
|
else:
|
|
|
|
thisday = datetime.date.fromordinal(current_ord)
|
2009-03-21 04:43:06 +05:30
|
|
|
|
2009-12-14 14:17:01 +05:30
|
|
|
# Something this month
|
|
|
|
if thisday.month == month:
|
|
|
|
holiday_list = self.holidays.get(month, {}).get(thisday.day, [])
|
|
|
|
bday_anniv_list = self.calendar.get(month, {}).get(thisday.day, [])
|
2009-03-21 04:43:06 +05:30
|
|
|
|
2009-12-14 14:17:01 +05:30
|
|
|
# date is an instance because of subtracting abilities in date.py
|
2010-03-20 06:01:03 +05:30
|
|
|
event_date = gen.lib.Date(thisday.year, thisday.month, thisday.day)
|
2009-01-27 13:19:47 +05:30
|
|
|
|
2009-12-14 14:17:01 +05:30
|
|
|
# get events for this day
|
|
|
|
day_list = get_day_list(event_date, holiday_list, bday_anniv_list)
|
2009-01-27 13:19:47 +05:30
|
|
|
|
2009-12-14 14:17:01 +05:30
|
|
|
# is there something this day?
|
|
|
|
if day_list:
|
2009-01-27 13:19:47 +05:30
|
|
|
|
2009-12-14 14:17:01 +05:30
|
|
|
hilightday = 'highlight ' + dayclass
|
|
|
|
tcell = Html("td", id = tcell_id, class_ = hilightday)
|
2009-02-03 13:31:31 +05:30
|
|
|
|
2009-12-14 14:17:01 +05:30
|
|
|
# Year at a Glance
|
|
|
|
if cal == "yg":
|
2009-03-21 04:43:06 +05:30
|
|
|
|
2009-12-14 14:17:01 +05:30
|
|
|
# make one day pages and hyperlink
|
|
|
|
if self.makeoneday:
|
2009-03-21 04:43:06 +05:30
|
|
|
|
2009-12-14 14:17:01 +05:30
|
|
|
# create yyyymmdd date string for
|
|
|
|
# "One Day" calendar page filename
|
|
|
|
fname_date = '%04d%02d%02d' % (year,month,day) + self.ext
|
2009-03-21 04:43:06 +05:30
|
|
|
|
2009-12-14 14:17:01 +05:30
|
|
|
# create hyperlink to one_day()
|
|
|
|
fname_date = full_month_name + '/' + fname_date
|
2009-12-24 13:25:26 +05:30
|
|
|
tcell += Html("a", datediv, href = fname_date, inline = True)
|
2008-10-08 01:41:46 +05:30
|
|
|
|
2009-12-14 14:17:01 +05:30
|
|
|
# only year_glance() needs this to create the one_day() pages
|
|
|
|
self.one_day(event_date, fname_date, day_list)
|
2009-03-26 16:47:57 +05:30
|
|
|
|
2009-12-14 14:17:01 +05:30
|
|
|
# just year_glance(), but no one_day() pages
|
|
|
|
else:
|
2009-03-21 04:43:06 +05:30
|
|
|
|
2009-12-14 14:17:01 +05:30
|
|
|
# continue table cell, <td>, without id tag
|
|
|
|
tcell = Html("td", class_ = hilightday, inline = True) + (
|
|
|
|
|
|
|
|
# adds date division
|
|
|
|
Html("div", day, class_ = "date", inline = True)
|
|
|
|
)
|
|
|
|
|
|
|
|
# WebCal
|
|
|
|
else:
|
|
|
|
|
|
|
|
# add date to table cell
|
|
|
|
tcell += datediv
|
2009-03-21 04:43:06 +05:30
|
|
|
|
2009-12-14 14:17:01 +05:30
|
|
|
# list the events
|
|
|
|
unordered = Html("ul")
|
|
|
|
tcell += unordered
|
2009-03-21 04:43:06 +05:30
|
|
|
|
2009-12-14 14:17:01 +05:30
|
|
|
for nyears, date, text, event in day_list:
|
2010-03-20 06:01:03 +05:30
|
|
|
unordered += Html("li", text, inline = False
|
|
|
|
if event == 'Anniversary' else True)
|
2009-09-24 02:01:21 +05:30
|
|
|
|
2009-12-14 14:17:01 +05:30
|
|
|
# no events for this day
|
|
|
|
else:
|
2009-01-27 13:19:47 +05:30
|
|
|
|
2009-12-14 14:17:01 +05:30
|
|
|
# create empty day with date
|
|
|
|
tcell = Html("td", class_ = dayclass, inline = True) + (
|
2008-07-31 03:07:24 +05:30
|
|
|
|
2009-12-14 14:17:01 +05:30
|
|
|
# adds date division
|
|
|
|
Html("div", day, class_ = "date", inline = True)
|
|
|
|
)
|
|
|
|
|
|
|
|
# nothing for this month
|
|
|
|
else:
|
|
|
|
tcell = Html("td", class_ = dayclass) + (
|
2009-03-21 04:43:06 +05:30
|
|
|
|
2009-03-26 16:47:57 +05:30
|
|
|
# adds date division
|
2009-09-11 11:54:13 +05:30
|
|
|
Html("div", day, class_ = "date", inline = True)
|
2009-03-26 16:47:57 +05:30
|
|
|
)
|
2009-03-21 04:43:06 +05:30
|
|
|
|
2009-09-24 02:01:21 +05:30
|
|
|
# attach table cell to table row
|
2009-03-21 04:43:06 +05:30
|
|
|
# close the day column
|
2009-09-24 02:01:21 +05:30
|
|
|
trow += tcell
|
2008-10-08 01:41:46 +05:30
|
|
|
|
2009-12-14 14:17:01 +05:30
|
|
|
# change day number
|
|
|
|
current_ord += 1
|
2008-07-31 03:07:24 +05:30
|
|
|
|
2009-12-14 14:17:01 +05:30
|
|
|
if cal == "yg":
|
|
|
|
for weeks in xrange(nweeks, 6):
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2009-12-14 14:17:01 +05:30
|
|
|
# each calendar must have six weeks for proper styling and alignment
|
|
|
|
with Html("tr", class_ = "week%02d" % (weeks + 1)) as six_weeks:
|
|
|
|
tbody += six_weeks
|
2009-09-24 02:01:21 +05:30
|
|
|
|
2009-12-14 14:17:01 +05:30
|
|
|
for emptydays in range(7):
|
|
|
|
six_weeks += Html("td", class_ = "emptyDays", inline = True)
|
2007-08-27 09:22:06 +05:30
|
|
|
|
2009-12-14 14:17:01 +05:30
|
|
|
# return calendar table to its callers
|
|
|
|
return table
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
# ---------------------------------------------------------------------------------------
|
|
|
|
# Creates the Web Calendars; the primary part of this plugin
|
|
|
|
# ---------------------------------------------------------------------------------------
|
|
|
|
def webcalendar(self, year):
|
2008-07-17 18:35:15 +05:30
|
|
|
"""
|
2009-03-21 04:43:06 +05:30
|
|
|
This method provides information and header/ footer to the calendar month
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
year -- year being created
|
|
|
|
"""
|
2008-12-05 02:08:02 +05:30
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
# do some error correcting if needed
|
|
|
|
if self.multiyear:
|
|
|
|
if self.end_year < self.start_year:
|
|
|
|
self.end_year = self.start_year
|
2008-11-11 03:11:38 +05:30
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
nr_up = 1 # Number of directory levels up to get to self.html_dir / root
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
# generate progress pass for "WebCal"
|
|
|
|
self.progress.set_pass(_('Formatting months ...'), 12)
|
2008-11-11 03:11:38 +05:30
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
for month in range(1, 13):
|
2011-05-17 05:51:22 +05:30
|
|
|
cal_fname = _dd.long_months[month]
|
2009-03-21 04:43:06 +05:30
|
|
|
of = self.create_file(cal_fname, str(year))
|
2009-02-13 01:36:32 +05:30
|
|
|
|
2009-03-24 20:28:16 +05:30
|
|
|
# Add xml, doctype, meta and stylesheets
|
|
|
|
# body has already been added to webcal already once
|
2010-03-27 04:21:53 +05:30
|
|
|
webcal, body = self.write_header(nr_up, self.title_text)
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
# create Year Navigation menu
|
2009-09-24 02:01:21 +05:30
|
|
|
if (self.multiyear and ((self.end_year - self.start_year) > 0)):
|
2009-03-24 20:28:16 +05:30
|
|
|
body += self.year_navigation(nr_up, str(year))
|
2008-07-30 00:07:29 +05:30
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
# Create Month Navigation Menu
|
|
|
|
# identify currentsection for proper highlighting
|
2011-05-17 05:51:22 +05:30
|
|
|
currentsection = _dd.long_months[month]
|
2009-03-24 20:28:16 +05:30
|
|
|
body += self.month_navigation(nr_up, year, currentsection, True)
|
2009-02-04 07:33:27 +05:30
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
# build the calendar
|
|
|
|
monthly_calendar = self.calendar_build("wc", year, month)
|
2009-09-24 02:01:21 +05:30
|
|
|
body += monthly_calendar
|
2009-02-04 07:33:27 +05:30
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
# create note section for webcalendar()
|
2011-05-17 05:51:22 +05:30
|
|
|
# One has to be minused because the array starts at zero, but January =1
|
2009-03-21 04:43:06 +05:30
|
|
|
note = self.month_notes[month-1].strip()
|
2009-09-24 02:01:21 +05:30
|
|
|
if note:
|
|
|
|
note = self.database.get_note_from_gramps_id(note)
|
|
|
|
note = self.get_note_format(note)
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2009-03-21 21:55:47 +05:30
|
|
|
# table foot section
|
2009-09-24 02:01:21 +05:30
|
|
|
cal_foot = Html("tfoot")
|
|
|
|
monthly_calendar += cal_foot
|
2009-01-27 04:27:25 +05:30
|
|
|
|
2009-09-24 02:01:21 +05:30
|
|
|
trow = Html("tr") + (
|
2009-12-14 14:17:01 +05:30
|
|
|
Html("td", note, colspan=7, inline = True)
|
2009-09-24 02:01:21 +05:30
|
|
|
)
|
|
|
|
cal_foot += trow
|
2009-01-27 04:27:25 +05:30
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
# create blank line for stylesheets
|
2009-03-24 20:28:16 +05:30
|
|
|
# create footer division section
|
2009-03-21 04:43:06 +05:30
|
|
|
footer = self.write_footer(nr_up)
|
2009-09-12 09:22:42 +05:30
|
|
|
body += (fullclear, footer)
|
2009-02-03 13:31:31 +05:30
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
# send calendar page to web output
|
2009-11-03 13:02:45 +05:30
|
|
|
# and close the file
|
|
|
|
self.XHTMLWriter(webcal, of)
|
2009-01-27 04:27:25 +05:30
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
# increase progress bar
|
|
|
|
self.progress.step()
|
2009-01-27 04:27:25 +05:30
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
# ---------------------------------------------------------------------------------------
|
|
|
|
# Creates Year At A Glance Calendar
|
|
|
|
# ---------------------------------------------------------------------------------------
|
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...
|
2009-02-04 07:33:27 +05:30
|
|
|
year -- year being created
|
2008-07-17 18:35:15 +05:30
|
|
|
"""
|
|
|
|
|
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
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
# generate progress pass for "Year At A Glance"
|
|
|
|
self.progress.set_pass(_('Creating Year At A Glance calendar'), 12)
|
|
|
|
|
|
|
|
of = self.create_file('fullyearlinked', 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
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
# Create page header
|
2009-09-24 02:01:21 +05:30
|
|
|
# body has already been added to yearglance already once
|
2010-03-27 04:21:53 +05:30
|
|
|
yearglance, body = self.write_header(nr_up, title, "fullyearlinked", False)
|
2009-03-21 04:43:06 +05:30
|
|
|
|
|
|
|
# create Year Navigation menu
|
2009-09-24 02:01:21 +05:30
|
|
|
if (self.multiyear and ((self.end_year - self.start_year) > 0)):
|
2009-03-24 20:28:16 +05:30
|
|
|
body += self.year_navigation(nr_up, str(year))
|
2009-03-21 04:43:06 +05:30
|
|
|
|
|
|
|
# Create Month Navigation Menu
|
|
|
|
# identify currentsection for proper highlighting
|
2009-09-24 02:01:21 +05:30
|
|
|
body += self.month_navigation(nr_up, year, "fullyearlinked", True)
|
2009-02-11 09:09:52 +05:30
|
|
|
|
|
|
|
msg = (_('This calendar is meant to give you access '
|
2009-03-21 04:43:06 +05:30
|
|
|
'to all your data at a glance compressed into one page. Clicking '
|
|
|
|
'on a date will take you to a page that shows all the events for '
|
2010-10-15 22:52:05 +05:30
|
|
|
'that date, if there are any.\n'))
|
2009-03-21 04:43:06 +05:30
|
|
|
|
|
|
|
# page description
|
2009-09-24 02:01:21 +05:30
|
|
|
body += Html("div", class_ = "content") + (
|
2009-03-17 11:22:43 +05:30
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
# message line
|
2009-12-24 13:25:26 +05:30
|
|
|
Html("p", msg, id='description')
|
2009-03-21 04:43:06 +05:30
|
|
|
)
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2009-02-10 07:08:08 +05:30
|
|
|
for month in range(1, 13):
|
2008-07-17 18:35:15 +05:30
|
|
|
|
|
|
|
# build the calendar
|
2009-03-21 04:43:06 +05:30
|
|
|
monthly_calendar = self.calendar_build("yg", year, month)
|
2009-09-24 02:01:21 +05:30
|
|
|
body += monthly_calendar
|
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()
|
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
# create blank line for stylesheets
|
|
|
|
# write footer section
|
|
|
|
footer = self.write_footer(nr_up)
|
2009-09-12 09:22:42 +05:30
|
|
|
body += (fullclear, footer)
|
2009-03-21 04:43:06 +05:30
|
|
|
|
|
|
|
# send calendar page to web output
|
2009-11-03 13:02:45 +05:30
|
|
|
# and close the file
|
|
|
|
self.XHTMLWriter(yearglance, of)
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
# ---------------------------------------------------------------------------------------
|
|
|
|
# Creates the individual days for year_glance()
|
|
|
|
# ---------------------------------------------------------------------------------------
|
|
|
|
def one_day(self, event_date, fname_date, day_list):
|
2008-10-08 01:41:46 +05:30
|
|
|
"""
|
2009-03-21 04:43:06 +05:30
|
|
|
This method creates the One Day page for "Year At A Glance"
|
2008-10-08 01:41:46 +05:30
|
|
|
|
2009-03-25 09:24:47 +05:30
|
|
|
event_date -- date for the listed events
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
fname_date -- filename date from calendar_build()
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
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...
|
|
|
|
"""
|
2007-08-27 09:22:06 +05:30
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
nr_up = 2 # number of directory levels up to get to root
|
2008-10-08 01:41:46 +05:30
|
|
|
|
2009-09-24 02:01:21 +05:30
|
|
|
# get year and month from event_date for use in this section
|
2009-03-21 04:43:06 +05:30
|
|
|
year = event_date.get_year()
|
2009-09-24 02:01:21 +05:30
|
|
|
month = event_date.get_month()
|
2008-10-08 01:41:46 +05:30
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
od = self.create_file(fname_date, str(year))
|
2008-10-08 01:41:46 +05:30
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
# page title
|
|
|
|
title = _('One Day Within A Year')
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
# create page header
|
2010-03-27 04:21:53 +05:30
|
|
|
oneday, body = self.write_header(nr_up, title, "OneDay")
|
2009-02-04 07:33:27 +05:30
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
# create Year Navigation menu
|
2009-09-24 02:01:21 +05:30
|
|
|
if (self.multiyear and ((self.end_year - self.start_year) > 0)):
|
2009-03-24 20:28:16 +05:30
|
|
|
body += self.year_navigation(nr_up, str(year))
|
2008-07-30 00:07:29 +05:30
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
# Create Month Navigation Menu
|
|
|
|
# identify currentsection for proper highlighting
|
2011-05-17 05:51:22 +05:30
|
|
|
currentsection = _dd.long_months[month]
|
2009-09-24 02:01:21 +05:30
|
|
|
body += self.month_navigation(nr_up, year, currentsection, True)
|
2009-01-27 04:27:25 +05:30
|
|
|
|
2009-03-25 09:24:47 +05:30
|
|
|
# set date display as in user prevferences
|
2009-12-24 13:25:26 +05:30
|
|
|
body += Html("h3", _dd.display(event_date), inline = True)
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
# list the events
|
2009-10-08 11:18:43 +05:30
|
|
|
ordered = Html("ol")
|
2009-09-24 02:01:21 +05:30
|
|
|
body += ordered
|
2009-03-21 04:43:06 +05:30
|
|
|
for nyears, date, text, event in day_list:
|
2009-10-08 11:18:43 +05:30
|
|
|
ordered += Html("li", text, inline = False if event == 'Anniversary' else True)
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
# create blank line for stylesheets
|
|
|
|
# write footer section
|
|
|
|
footer = self.write_footer(nr_up)
|
2009-09-12 09:22:42 +05:30
|
|
|
body += (fullclear, footer)
|
2008-07-17 18:35:15 +05:30
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
# send calendar page to web output
|
2009-11-03 13:02:45 +05:30
|
|
|
# and close the file
|
|
|
|
self.XHTMLWriter(oneday, od)
|
2009-03-21 04:43:06 +05:30
|
|
|
|
2009-11-03 13:02:45 +05:30
|
|
|
######################################################################################
|
|
|
|
# Support Functions for linking to Narratted Web Site
|
|
|
|
######################################################################################
|
2009-10-07 10:45:34 +05:30
|
|
|
def build_url_fname_html(self, fname, subdir=None, prefix=None):
|
|
|
|
return self.build_url_fname(fname, subdir, prefix) + self.ext
|
|
|
|
|
2009-12-24 13:25:26 +05:30
|
|
|
def build_url_fname(self, fname, subdir, prefix = None):
|
2009-10-07 10:45:34 +05:30
|
|
|
"""
|
|
|
|
Create part of the URL given the filename and optionally the subdirectory.
|
|
|
|
If the subdirectory is given, then two extra levels of subdirectory are inserted
|
|
|
|
between 'subdir' and the filename. The reason is to prevent directories with
|
|
|
|
too many entries.
|
|
|
|
If 'prefix' is set, then is inserted in front of the result.
|
|
|
|
|
|
|
|
The extension is added to the filename as well.
|
|
|
|
|
|
|
|
Notice that we do NOT use os.path.join() because we're creating a URL.
|
|
|
|
Imagine we run gramps on Windows (heaven forbits), we don't want to
|
|
|
|
see backslashes in the URL.
|
|
|
|
"""
|
2010-03-06 18:59:02 +05:30
|
|
|
if (constfunc.win()):
|
2009-10-07 10:45:34 +05:30
|
|
|
fname = fname.replace('\\',"/")
|
|
|
|
subdirs = self.build_subdirs(subdir, fname)
|
2009-11-03 00:37:32 +05:30
|
|
|
return (prefix or '') + "/".join(subdirs + [fname])
|
2009-10-07 10:45:34 +05:30
|
|
|
|
|
|
|
def build_subdirs(self, subdir, fname):
|
|
|
|
"""
|
|
|
|
If subdir is given, then two extra levels of subdirectory are inserted
|
|
|
|
between 'subdir' and the filename. The reason is to prevent directories with
|
|
|
|
too many entries.
|
|
|
|
|
|
|
|
For example, this may return ['ppl', '8', '1'] given 'ppl', "aec934857df74d36618"
|
|
|
|
"""
|
|
|
|
subdirs = []
|
|
|
|
if subdir:
|
|
|
|
subdirs.append(subdir)
|
|
|
|
subdirs.append(fname[-1].lower())
|
|
|
|
subdirs.append(fname[-2].lower())
|
|
|
|
return subdirs
|
|
|
|
|
2009-04-06 09:19:47 +05:30
|
|
|
# ---------------------------------------------------------------------------------------
|
|
|
|
# Get person's short name
|
|
|
|
# ---------------------------------------------------------------------------------------
|
|
|
|
def get_name(self, person, maiden_name = None):
|
|
|
|
"""
|
|
|
|
Return person's name, unless maiden_name given, unless married_name
|
|
|
|
listed.
|
|
|
|
|
|
|
|
person -- person to get short name from
|
|
|
|
maiden_name -- either a woman's maiden name or man's surname
|
|
|
|
"""
|
|
|
|
# Get all of a person's names:
|
|
|
|
primary_name = person.primary_name
|
|
|
|
married_name = None
|
|
|
|
names = [primary_name] + person.get_alternate_names()
|
2009-11-03 19:52:37 +05:30
|
|
|
for name in names:
|
2010-03-20 06:01:03 +05:30
|
|
|
if int(name.get_type()) == gen.lib.NameType.MARRIED:
|
2009-11-03 19:52:37 +05:30
|
|
|
married_name = name
|
|
|
|
break
|
2009-04-06 09:19:47 +05:30
|
|
|
|
|
|
|
# Now, decide which to use:
|
|
|
|
if maiden_name is not None:
|
|
|
|
if married_name is not None:
|
2010-03-20 06:01:03 +05:30
|
|
|
name = gen.lib.Name(married_name)
|
2009-04-06 09:19:47 +05:30
|
|
|
else:
|
2010-03-20 06:01:03 +05:30
|
|
|
name = gen.lib.Name(primary_name)
|
2011-03-12 08:26:19 +05:30
|
|
|
surname_obj = name.get_primary_surname()
|
2011-05-11 15:02:04 +05:30
|
|
|
surname_obj.set_surname(maiden_name)
|
2009-04-06 09:19:47 +05:30
|
|
|
else:
|
2010-03-20 06:01:03 +05:30
|
|
|
name = gen.lib.Name(primary_name)
|
2009-04-06 09:19:47 +05:30
|
|
|
name.set_display_as(self.name_format)
|
|
|
|
return _nd.display_name(name)
|
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
# ---------------------------------------------------------------------------------------
|
|
|
|
# The database slave; Gathers information for calendars
|
|
|
|
# ---------------------------------------------------------------------------------------
|
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.
|
|
|
|
"""
|
2009-12-24 13:25:26 +05:30
|
|
|
db = self.database
|
|
|
|
|
|
|
|
people = db.iter_person_handles()
|
|
|
|
self.progress.set_pass(_('Applying Filter...'), db.get_number_of_people())
|
|
|
|
people = self.filter.apply(db, people, self.progress)
|
2008-10-08 01:41:46 +05:30
|
|
|
|
|
|
|
self.progress.set_pass(_("Reading database..."), len(people))
|
2009-12-24 13:25:26 +05:30
|
|
|
for person in imap(db.get_person_from_handle, people):
|
2008-07-17 18:35:15 +05:30
|
|
|
self.progress.step()
|
2009-09-24 02:01:21 +05:30
|
|
|
|
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()
|
2010-03-20 06:01:03 +05:30
|
|
|
birth_date = gen.lib.Date.EMPTY
|
2007-08-27 09:22:06 +05:30
|
|
|
if birth_ref:
|
2009-12-24 13:25:26 +05:30
|
|
|
birth_event = db.get_event_from_handle(birth_ref.ref)
|
2007-08-27 09:22:06 +05:30
|
|
|
birth_date = birth_event.get_date_object()
|
2009-01-27 13:19:47 +05:30
|
|
|
|
|
|
|
# determine birthday information???
|
2010-04-22 06:57:53 +05:30
|
|
|
if (self.birthday and birth_date is not gen.lib.Date.EMPTY and birth_date.is_valid()):
|
2009-02-14 06:27:34 +05:30
|
|
|
|
2009-12-24 13:25:26 +05:30
|
|
|
year = birth_date.get_year() or this_year
|
2010-04-01 06:32:55 +05:30
|
|
|
month = birth_date.get_month()
|
|
|
|
day = birth_date.get_day()
|
2009-02-14 06:27:34 +05:30
|
|
|
|
2009-04-06 09:19:47 +05:30
|
|
|
# date to figure if someone is still alive
|
2009-12-12 13:12:42 +05:30
|
|
|
# current year of calendar, month nd day is their birth month and birth day
|
2010-03-20 06:01:03 +05:30
|
|
|
prob_alive_date = gen.lib.Date(this_year, month, day)
|
2009-02-14 06:27:34 +05:30
|
|
|
|
|
|
|
# add some things to handle maiden name:
|
|
|
|
father_surname = None # husband, actually
|
2010-03-20 06:01:03 +05:30
|
|
|
if person.gender == gen.lib.Person.FEMALE:
|
2009-02-14 06:27:34 +05:30
|
|
|
|
|
|
|
# get husband's last name:
|
|
|
|
if self.maiden_name in ['spouse_first', 'spouse_last']:
|
2009-12-12 13:12:42 +05:30
|
|
|
if family_list:
|
2009-02-14 06:27:34 +05:30
|
|
|
if self.maiden_name == 'spouse_first':
|
|
|
|
fhandle = family_list[0]
|
|
|
|
else:
|
|
|
|
fhandle = family_list[-1]
|
2009-12-24 13:25:26 +05:30
|
|
|
fam = db.get_family_from_handle(fhandle)
|
2009-02-14 06:27:34 +05:30
|
|
|
father_handle = fam.get_father_handle()
|
|
|
|
mother_handle = fam.get_mother_handle()
|
2009-11-03 19:52:37 +05:30
|
|
|
if mother_handle == person.handle:
|
2009-02-14 06:27:34 +05:30
|
|
|
if father_handle:
|
2009-12-24 13:25:26 +05:30
|
|
|
father = db.get_person_from_handle(father_handle)
|
2009-02-24 08:22:06 +05:30
|
|
|
if father is not None:
|
2010-03-20 06:01:03 +05:30
|
|
|
father_surname = _get_regular_surname(person.gender,
|
2010-04-22 06:57:53 +05:30
|
|
|
father.get_primary_name())
|
2009-04-06 09:19:47 +05:30
|
|
|
short_name = self.get_name(person, father_surname)
|
2009-12-24 13:25:26 +05:30
|
|
|
alive = probably_alive(person, db, prob_alive_date)
|
2009-02-14 06:27:34 +05:30
|
|
|
if (self.alive and alive) or not self.alive:
|
2009-10-08 11:18:43 +05:30
|
|
|
|
|
|
|
# add link to NarrativeWeb
|
2009-10-07 10:45:34 +05:30
|
|
|
if self.link_to_narweb:
|
2010-05-23 10:21:59 +05:30
|
|
|
text = str(Html("a", short_name,
|
2009-12-12 13:12:42 +05:30
|
|
|
href = self.build_url_fname_html(person.handle, "ppl",
|
2010-05-23 10:21:59 +05:30
|
|
|
prefix = self.narweb_prefix)))
|
2009-10-07 10:45:34 +05:30
|
|
|
else:
|
|
|
|
text = short_name
|
2009-02-14 06:27:34 +05:30
|
|
|
self.add_day_item(text, year, month, day, 'Birthday')
|
2009-01-27 13:19:47 +05:30
|
|
|
|
|
|
|
# add anniversary if requested
|
|
|
|
if self.anniv:
|
|
|
|
for fhandle in family_list:
|
2009-12-24 13:25:26 +05:30
|
|
|
fam = db.get_family_from_handle(fhandle)
|
2009-01-27 13:19:47 +05:30
|
|
|
father_handle = fam.get_father_handle()
|
|
|
|
mother_handle = fam.get_mother_handle()
|
2009-02-08 02:11:27 +05:30
|
|
|
if father_handle == person.handle:
|
2009-01-27 13:19:47 +05:30
|
|
|
spouse_handle = mother_handle
|
|
|
|
else:
|
|
|
|
continue # with next person if this was the marriage event
|
|
|
|
if spouse_handle:
|
2009-12-24 13:25:26 +05:30
|
|
|
spouse = db.get_person_from_handle(spouse_handle)
|
2009-01-27 13:19:47 +05:30
|
|
|
if spouse:
|
2009-04-06 09:19:47 +05:30
|
|
|
spouse_name = self.get_name(spouse)
|
|
|
|
short_name = self.get_name(person)
|
2009-01-27 13:19:47 +05:30
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
# will return a marriage event or False if not married any longer
|
2009-12-24 13:25:26 +05:30
|
|
|
marriage_event = get_marriage_event(db, fam)
|
2009-03-17 05:02:47 +05:30
|
|
|
if marriage_event:
|
2009-12-24 13:25:26 +05:30
|
|
|
event_date = marriage_event.get_date_object()
|
2010-04-01 06:32:55 +05:30
|
|
|
if event_date is not gen.lib.Date.EMPTY and event_date.is_valid():
|
2009-12-24 13:25:26 +05:30
|
|
|
year = event_date.get_year()
|
|
|
|
month = event_date.get_month()
|
|
|
|
day = event_date.get_day()
|
2009-01-27 13:19:47 +05:30
|
|
|
|
2009-12-24 13:25:26 +05:30
|
|
|
# date to figure if someone is still alive
|
2010-03-20 06:01:03 +05:30
|
|
|
prob_alive_date = gen.lib.Date(this_year, month, day)
|
2009-02-04 11:05:34 +05:30
|
|
|
|
2009-10-07 10:45:34 +05:30
|
|
|
if self.link_to_narweb:
|
2010-05-23 10:21:59 +05:30
|
|
|
spouse_name = str(Html("a", spouse_name,
|
2009-12-24 13:25:26 +05:30
|
|
|
href = self.build_url_fname_html(spouse_handle, 'ppl',
|
2010-05-23 10:21:59 +05:30
|
|
|
prefix = self.narweb_prefix)))
|
|
|
|
short_name = str(Html("a", short_name,
|
2009-12-24 13:25:26 +05:30
|
|
|
href = self.build_url_fname_html(person.handle, 'ppl',
|
2010-05-23 10:21:59 +05:30
|
|
|
prefix = self.narweb_prefix)))
|
2009-10-07 10:45:34 +05:30
|
|
|
|
2009-12-24 13:25:26 +05:30
|
|
|
alive1 = probably_alive(person, db, prob_alive_date)
|
|
|
|
alive2 = probably_alive(spouse, db, prob_alive_date)
|
2009-02-24 08:22:06 +05:30
|
|
|
if ((self.alive and alive1 and alive2) or not self.alive):
|
2009-12-24 13:25:26 +05:30
|
|
|
|
|
|
|
text = _('%(spouse)s and %(person)s') % {
|
|
|
|
'spouse' : spouse_name,
|
|
|
|
'person' : short_name}
|
|
|
|
|
2009-02-24 08:22:06 +05:30
|
|
|
self.add_day_item(text, year, month, day, 'Anniversary')
|
2007-08-27 09:22:06 +05:30
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
# ---------------------------------------------------------------------------------------
|
|
|
|
# Closes the Calendars; the end
|
|
|
|
# ---------------------------------------------------------------------------------------
|
|
|
|
def write_footer(self, nr_up):
|
|
|
|
"""
|
|
|
|
Writes the footer section of the pages
|
|
|
|
'nr_up' - number of directory levels up, started from current page, to the
|
|
|
|
root of the directory tree (i.e. to self.html_dir).
|
|
|
|
"""
|
|
|
|
|
2009-12-24 13:25:26 +05:30
|
|
|
# begin calendar footer
|
|
|
|
with Html("div", id = "footer") as footer:
|
2009-03-21 04:43:06 +05:30
|
|
|
|
2009-12-24 13:25:26 +05:30
|
|
|
# Display date as user set in preferences
|
|
|
|
msg = _('Generated by <a href="http://gramps-project.org">'
|
2010-03-20 06:01:03 +05:30
|
|
|
'Gramps</a> on %(date)s') % {'date' : _dd.display(
|
|
|
|
gen.lib.date.Today())}
|
2009-12-24 13:25:26 +05:30
|
|
|
footer += Html("p", msg, id = 'createdate')
|
2009-03-21 04:43:06 +05:30
|
|
|
|
2009-12-24 13:25:26 +05:30
|
|
|
copy_nr = self.copy
|
|
|
|
text = ''
|
|
|
|
if copy_nr == 0:
|
|
|
|
if self.author:
|
|
|
|
text = "© %s %s" % (self.today.get_year(), self.author)
|
|
|
|
elif 0 < copy_nr < len(_CC):
|
|
|
|
subdirs = ['..'] * nr_up
|
|
|
|
# Note. We use '/' here because it is a URL, not a OS dependent pathname
|
|
|
|
fname = '/'.join(subdirs + ['images'] + ['somerights20.gif'])
|
|
|
|
text = _CC[copy_nr] % {'gif_fname' : fname}
|
|
|
|
else:
|
2009-03-21 04:43:06 +05:30
|
|
|
text = "© %s %s" % (self.today.get_year(), self.author)
|
|
|
|
|
2009-12-24 13:25:26 +05:30
|
|
|
footer += Html("p", text, id = 'copyright')
|
2009-03-21 04:43:06 +05:30
|
|
|
|
2009-12-24 13:25:26 +05:30
|
|
|
# return footer to its callers
|
2009-03-21 04:43:06 +05:30
|
|
|
return footer
|
|
|
|
|
2009-11-03 13:02:45 +05:30
|
|
|
# ---------------------------------------------------------------------------------------
|
|
|
|
# # Web Page Fortmatter and writer
|
|
|
|
# ---------------------------------------------------------------------------------------
|
|
|
|
def XHTMLWriter(self, page, of):
|
|
|
|
"""
|
|
|
|
This function is simply to make the web page look pretty and readable
|
|
|
|
It is not for the browser, but for us, humans
|
|
|
|
"""
|
|
|
|
|
|
|
|
# writes the file out from the page variable; Html instance
|
2010-08-12 10:56:45 +05:30
|
|
|
# This didn't work for some reason, but it does in NarWeb:
|
|
|
|
#page.write(partial(print, file=of.write))
|
|
|
|
page.write(lambda line: of.write(line + '\n'))
|
2009-11-03 13:02:45 +05:30
|
|
|
# close the file now...
|
|
|
|
self.close_file(of)
|
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
# ---------------------------------------------------------------------------------------
|
|
|
|
# The work horse of this plugin; stages everything
|
|
|
|
# ---------------------------------------------------------------------------------------
|
|
|
|
def write_report(self):
|
|
|
|
"""
|
|
|
|
The short method that runs through each month and creates a page.
|
|
|
|
"""
|
|
|
|
|
|
|
|
# Create progress meter bar
|
2009-04-06 09:19:47 +05:30
|
|
|
self.progress = ProgressMeter(_("Web Calendar Report"), '')
|
2009-03-21 04:43:06 +05:30
|
|
|
|
|
|
|
# get data from database for birthdays/ anniversaries
|
|
|
|
self.collect_data(self.start_year)
|
|
|
|
|
|
|
|
# Copy all files for the calendars being created
|
|
|
|
self.copy_calendar_files()
|
|
|
|
|
|
|
|
if self.multiyear:
|
2009-09-24 02:01:21 +05:30
|
|
|
|
|
|
|
# limit number of years to eighteen (18) years and only one row of years
|
|
|
|
nyears = ((self.end_year - self.start_year) + 1)
|
|
|
|
num_years = nyears if 0 < nyears < 19 else 18
|
|
|
|
|
|
|
|
for cal_year in xrange(self.start_year, (self.start_year + num_years)):
|
2009-03-21 04:43:06 +05:30
|
|
|
|
|
|
|
# initialize the holidays dict to fill:
|
|
|
|
self.holidays = {}
|
|
|
|
|
|
|
|
# get the information, zero is equal to None
|
|
|
|
if self.country != 0:
|
|
|
|
self.__get_holidays(cal_year)
|
|
|
|
|
|
|
|
# create webcalendar() calendar pages
|
|
|
|
self.webcalendar(cal_year)
|
|
|
|
|
|
|
|
# create "Year At A Glance" and
|
|
|
|
# "One Day" calendar pages
|
|
|
|
if self.fullyear:
|
|
|
|
self.year_glance(cal_year)
|
|
|
|
|
|
|
|
# a single year
|
|
|
|
else:
|
|
|
|
cal_year = self.start_year
|
|
|
|
|
|
|
|
self.holidays = {}
|
|
|
|
|
|
|
|
# get the information, first from holidays:
|
|
|
|
if self.country != 0:
|
|
|
|
self.__get_holidays(cal_year)
|
|
|
|
|
|
|
|
# create webcalendar() calendar pages
|
|
|
|
self.webcalendar(cal_year)
|
|
|
|
|
|
|
|
# create "Year At A Glance" and
|
|
|
|
# "One Day" calendar pages
|
|
|
|
if self.fullyear:
|
|
|
|
self.year_glance(cal_year)
|
|
|
|
|
|
|
|
# Close the progress meter
|
|
|
|
self.progress.close()
|
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------------------
|
|
|
|
# WebCalOptions; Creates the Menu
|
|
|
|
#----------------------------------------------------------------------------------------
|
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
|
2009-10-07 10:45:34 +05:30
|
|
|
self.__links = None
|
|
|
|
self.__prefix = None
|
2008-02-10 09:39:09 +05:30
|
|
|
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)
|
2009-03-21 04:43:06 +05:30
|
|
|
self.__add_advanced_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()
|
|
|
|
|
2009-04-06 09:19:47 +05:30
|
|
|
# We must figure out the value of the first option before we can
|
|
|
|
# create the EnumeratedListOption
|
|
|
|
fmt_list = _nd.get_name_format()
|
2011-05-11 15:02:04 +05:30
|
|
|
defaultnum = _nd.get_default_format()
|
|
|
|
default = 0
|
|
|
|
for ind,val in enumerate(fmt_list):
|
|
|
|
if val[0] == defaultnum:
|
|
|
|
default = ind
|
|
|
|
break
|
|
|
|
name_format = EnumeratedListOption(_("Name format"),
|
|
|
|
fmt_list[default][0])
|
2009-04-06 09:19:47 +05:30
|
|
|
for num, name, fmt_str, act in fmt_list:
|
|
|
|
name_format.add_item(num, name)
|
|
|
|
name_format.set_help(_("Select the format to display names"))
|
|
|
|
menu.add_option(category_name, "name_format", name_format)
|
|
|
|
|
2008-02-10 09:39:09 +05:30
|
|
|
ext = EnumeratedListOption(_("File extension"), ".html" )
|
2009-11-03 00:37:32 +05:30
|
|
|
for etype in _WEB_EXT:
|
2008-02-10 09:39:09 +05:30
|
|
|
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
|
|
|
|
2010-08-12 10:56:45 +05:30
|
|
|
css = EnumeratedListOption(_('StyleSheet'), CSS["default"]["id"])
|
2011-02-26 14:07:47 +05:30
|
|
|
for (fname, id) in sorted([(CSS[key]["translation"], CSS[key]["id"])
|
|
|
|
for key in CSS.keys()]):
|
2010-08-12 10:56:45 +05:30
|
|
|
if CSS[id]["user"]:
|
2011-02-26 14:07:47 +05:30
|
|
|
css.add_item(CSS[id]["id"], CSS[id]["translation"])
|
2010-03-27 04:21:53 +05:30
|
|
|
css.set_help( _('The stylesheet to be used for the web pages'))
|
2008-07-17 18:35:15 +05:30
|
|
|
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.
|
2010-03-20 06:01:03 +05:30
|
|
|
today = gen.lib.date.Today()
|
2009-03-26 16:47:57 +05:30
|
|
|
|
|
|
|
self.__multiyear = BooleanOption(_('Create multiple year calendars'), False)
|
|
|
|
self.__multiyear.set_help(_('Whether to create Multiple year calendars or not.'))
|
2008-10-08 01:41:46 +05:30
|
|
|
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-03-26 16:47:57 +05:30
|
|
|
self.__start_year = NumberOption(_('Start Year for the Calendar(s)'), today.get_year(),
|
|
|
|
1900, 3000)
|
2009-02-10 12:49:56 +05:30
|
|
|
self.__start_year.set_help(_('Enter the starting year for the calendars '
|
|
|
|
'between 1900 - 3000'))
|
2008-10-08 01:41:46 +05:30
|
|
|
menu.add_option(category_name, 'start_year', self.__start_year)
|
|
|
|
|
2009-03-26 16:47:57 +05:30
|
|
|
self.__end_year = NumberOption(_('End Year for the Calendar(s)'), today.get_year(),
|
|
|
|
1900, 3000)
|
2009-02-10 12:49:56 +05:30
|
|
|
self.__end_year.set_help(_('Enter the ending year for the calendars '
|
2009-03-26 16:47:57 +05:30
|
|
|
'between 1900 - 3000.'))
|
2008-10-08 01:41:46 +05:30
|
|
|
menu.add_option(category_name, 'end_year', self.__end_year)
|
|
|
|
|
|
|
|
self.__multiyear_changed()
|
|
|
|
|
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()
|
2009-12-05 08:39:21 +05:30
|
|
|
countries = holiday_table.get_countries()
|
|
|
|
countries.sort()
|
|
|
|
if (len(countries) == 0 or
|
|
|
|
(len(countries) > 0 and countries[0] != '')):
|
|
|
|
countries.insert(0, '')
|
|
|
|
count = 0
|
|
|
|
for c in countries:
|
|
|
|
country.add_item(count, c)
|
|
|
|
count += 1
|
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")
|
2009-02-10 12:49:56 +05:30
|
|
|
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)"))
|
2008-10-08 01:41:46 +05:30
|
|
|
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)
|
|
|
|
|
2009-12-08 07:52:26 +05:30
|
|
|
home_link = StringOption(_('Home link'), '../../NAVWEB/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
|
|
|
|
2009-09-24 02:01:21 +05:30
|
|
|
note_jan = NoteOption(_('January Note'))
|
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
|
|
|
|
2009-09-24 02:01:21 +05:30
|
|
|
note_feb = NoteOption(_('February Note'))
|
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
|
|
|
|
2009-09-24 02:01:21 +05:30
|
|
|
note_mar = NoteOption(_('March Note'))
|
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
|
|
|
|
2009-09-24 02:01:21 +05:30
|
|
|
note_apr = NoteOption(_('April Note'))
|
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
|
|
|
|
2009-09-24 02:01:21 +05:30
|
|
|
note_may = NoteOption(_('May Note'))
|
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
|
|
|
|
2009-09-24 02:01:21 +05:30
|
|
|
note_jun = NoteOption(_('June Note'))
|
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
|
|
|
|
2009-09-24 02:01:21 +05:30
|
|
|
note_jul = NoteOption(_('July Note'))
|
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
|
|
|
|
2009-09-24 02:01:21 +05:30
|
|
|
note_aug = NoteOption(_('August Note'))
|
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
|
|
|
|
2009-09-24 02:01:21 +05:30
|
|
|
note_sep = NoteOption(_('September Note'))
|
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
|
|
|
|
2009-09-24 02:01:21 +05:30
|
|
|
note_oct = NoteOption(_('October Note'))
|
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
|
|
|
|
2009-09-24 02:01:21 +05:30
|
|
|
note_nov = NoteOption(_('November Note'))
|
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
|
|
|
|
2009-09-24 02:01:21 +05:30
|
|
|
note_dec = NoteOption(_('December Note'))
|
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
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
def __add_advanced_options(self, menu):
|
|
|
|
"""
|
|
|
|
Options for the advanced menu
|
|
|
|
"""
|
|
|
|
|
|
|
|
category_name = _('Advanced Options')
|
|
|
|
|
2009-03-24 20:28:16 +05:30
|
|
|
encoding = EnumeratedListOption(_('Character set encoding'), _CHARACTER_SETS[0][1])
|
2009-03-21 04:43:06 +05:30
|
|
|
for eopt in _CHARACTER_SETS:
|
|
|
|
encoding.add_item(eopt[1], eopt[0])
|
2009-03-24 20:28:16 +05:30
|
|
|
encoding.set_help( _('The encoding to be used for the web files'))
|
2009-03-21 04:43:06 +05:30
|
|
|
menu.add_option(category_name, "encoding", encoding)
|
|
|
|
|
2009-03-24 20:28:16 +05:30
|
|
|
fullyear = BooleanOption(_('Create "Year At A Glance" Calendar'), False)
|
2009-03-21 04:43:06 +05:30
|
|
|
fullyear.set_help(_('Whether to create A one-page mini calendar '
|
|
|
|
'with dates highlighted'))
|
|
|
|
menu.add_option(category_name, 'fullyear', fullyear)
|
|
|
|
|
|
|
|
makeoneday = BooleanOption(_('Create one day event pages for'
|
2009-10-07 10:45:34 +05:30
|
|
|
' Year At A Glance calendar'), False)
|
2009-03-21 04:43:06 +05:30
|
|
|
makeoneday.set_help(_('Whether to create one day pages or not'))
|
|
|
|
menu.add_option(category_name, 'makeoneday', makeoneday)
|
|
|
|
|
2009-10-07 10:45:34 +05:30
|
|
|
self.__links = BooleanOption(_('Link to Narrated Web Report'), False)
|
|
|
|
self.__links.set_help(_('Whether to link data to web report or not'))
|
|
|
|
menu.add_option(category_name, 'link_to_narweb', self.__links)
|
|
|
|
self.__links.connect('value-changed', self.__links_changed)
|
|
|
|
|
2009-12-08 07:52:26 +05:30
|
|
|
self.__prefix = StringOption(_('Link prefix'), "../../NAVWEB/")
|
|
|
|
self.__prefix.set_help(_("A Prefix on the links to take you to "
|
|
|
|
"Narrated Web Report"))
|
2009-10-07 10:45:34 +05:30
|
|
|
menu.add_option(category_name, "prefix", self.__prefix)
|
|
|
|
|
|
|
|
self.__links_changed()
|
|
|
|
|
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()
|
2009-11-03 00:37:32 +05:30
|
|
|
if 1 <= filter_value <= 4:
|
2008-02-10 09:39:09 +05:30
|
|
|
# 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)
|
|
|
|
|
2009-10-07 10:45:34 +05:30
|
|
|
def __links_changed(self):
|
|
|
|
"""
|
|
|
|
Handle checkbox change.
|
|
|
|
"""
|
|
|
|
if self.__links.get_value():
|
|
|
|
self.__prefix.set_available(True)
|
|
|
|
else:
|
|
|
|
self.__prefix.set_available(False)
|
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
# ---------------------------------------------------------------------------------------
|
|
|
|
# Support Functions for this plugin
|
2009-04-06 09:19:47 +05:30
|
|
|
# ---------------------------------------------------------------------------------------
|
2008-10-08 01:41:46 +05:30
|
|
|
def _get_regular_surname(sex, name):
|
2008-08-05 01:01:38 +05:30
|
|
|
"""
|
2009-02-08 02:11:27 +05:30
|
|
|
Returns a name string built from the components of the Name instance.
|
2008-08-05 01:01:38 +05:30
|
|
|
"""
|
2009-02-27 00:46:02 +05:30
|
|
|
surname = name.get_surname()
|
2010-10-29 01:26:46 +05:30
|
|
|
suffix = name.get_suffix()
|
|
|
|
if suffix:
|
|
|
|
surname = surname + ", " + suffix
|
2008-08-05 01:01:38 +05:30
|
|
|
return surname
|
|
|
|
|
2009-02-10 12:49:56 +05:30
|
|
|
# Simple utility list to convert Gramps day-of-week numbering
|
|
|
|
# to calendar.firstweekday numbering
|
2009-02-28 06:05:30 +05:30
|
|
|
dow_gramps2iso = [ -1, calendar.SUNDAY, calendar.MONDAY, calendar.TUESDAY,
|
|
|
|
calendar.WEDNESDAY, calendar.THURSDAY, calendar.FRIDAY,
|
|
|
|
calendar.SATURDAY]
|
2008-08-08 02:30:05 +05:30
|
|
|
|
2009-02-24 08:22:06 +05:30
|
|
|
def get_marriage_event(db, family):
|
2009-01-27 13:19:47 +05:30
|
|
|
"""
|
2009-12-24 13:25:26 +05:30
|
|
|
marriage_event will either be the marriage event or False
|
2009-01-27 13:19:47 +05:30
|
|
|
"""
|
|
|
|
|
2009-03-17 05:02:47 +05:30
|
|
|
marriage_event = False
|
2009-01-27 13:19:47 +05:30
|
|
|
for event_ref in family.get_event_ref_list():
|
2009-12-24 13:25:26 +05:30
|
|
|
|
2009-01-27 13:19:47 +05:30
|
|
|
event = db.get_event_from_handle(event_ref.ref)
|
2009-12-24 13:25:26 +05:30
|
|
|
if event.type.is_marriage:
|
2009-03-17 05:02:47 +05:30
|
|
|
marriage_event = event
|
2009-12-24 13:25:26 +05:30
|
|
|
elif event.type.is_divorce:
|
|
|
|
continue
|
|
|
|
|
|
|
|
# return the marriage event or False to it caller
|
2009-03-17 05:02:47 +05:30
|
|
|
return marriage_event
|
2009-01-27 13:19:47 +05:30
|
|
|
|
2009-02-08 02:11:27 +05:30
|
|
|
def get_first_day_of_month(year, month):
|
2009-02-11 03:06:23 +05:30
|
|
|
"""
|
2009-02-10 07:08:08 +05:30
|
|
|
Compute the first day to display for this month.
|
|
|
|
It can also be a day in the previous month.
|
|
|
|
"""
|
|
|
|
|
2009-02-14 06:27:34 +05:30
|
|
|
# first day of the month
|
|
|
|
current_date = datetime.date(year, month, 1)
|
2009-02-08 02:11:27 +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.
|
|
|
|
monthinfo = calendar.monthcalendar(year, month)
|
|
|
|
|
|
|
|
current_ord = current_date.toordinal() - monthinfo[0].count(0)
|
|
|
|
return current_date, current_ord, monthinfo
|
|
|
|
|
2009-02-16 14:23:24 +05:30
|
|
|
def _has_webpage_extension(url):
|
2009-02-13 01:36:32 +05:30
|
|
|
"""
|
|
|
|
determine if a filename has an extension or not...
|
|
|
|
|
|
|
|
url = filename to be checked
|
|
|
|
"""
|
2009-11-03 00:37:32 +05:30
|
|
|
return any(url.endswith(ext) for ext in _WEB_EXT)
|
2009-02-13 01:36:32 +05:30
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
# ---------------------------------------------------------------------------------------
|
|
|
|
# Gets individual events for each day
|
|
|
|
# ---------------------------------------------------------------------------------------
|
|
|
|
def get_day_list(event_date, holiday_list, bday_anniv_list):
|
|
|
|
"""
|
|
|
|
Will fill day_list and return it to its caller: calendar_build()
|
|
|
|
|
|
|
|
holiday_list -- list of holidays for event_date
|
|
|
|
bday_anniv_list -- list of birthdays and anniversaries
|
|
|
|
for event_date
|
|
|
|
|
|
|
|
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 day being created...
|
|
|
|
"""
|
|
|
|
|
|
|
|
# initialize day_list
|
|
|
|
day_list = []
|
|
|
|
|
|
|
|
##################################################################
|
|
|
|
# birthday/ anniversary on this day
|
2009-11-03 13:02:45 +05:30
|
|
|
# Date.EMPTY signifies an incomplete date for an event. See add_day_item()
|
2009-03-21 04:43:06 +05:30
|
|
|
bday_anniv_list = [(t, e, d) for t, e, d in bday_anniv_list
|
2010-03-20 06:01:03 +05:30
|
|
|
if d != gen.lib.Date.EMPTY]
|
2009-03-21 04:43:06 +05:30
|
|
|
|
|
|
|
# number of years have to be at least zero
|
|
|
|
bday_anniv_list = [(t, e, d) for t, e, d in bday_anniv_list
|
|
|
|
if (event_date.get_year() - d.get_year()) >= 0]
|
2009-03-30 03:56:36 +05:30
|
|
|
|
2009-12-24 13:25:26 +05:30
|
|
|
# a holiday
|
|
|
|
# zero will force holidays to be first in list
|
|
|
|
nyears = 0
|
|
|
|
|
|
|
|
for text, event, date in holiday_list:
|
|
|
|
day_list.append((nyears, date, text, event))
|
|
|
|
|
2009-03-30 03:56:36 +05:30
|
|
|
# birthday and anniversary list
|
2009-03-21 04:43:06 +05:30
|
|
|
for text, event, date in bday_anniv_list:
|
|
|
|
|
|
|
|
# number of years married, ex: 10
|
2009-03-26 16:47:57 +05:30
|
|
|
nyears = (event_date.get_year() - date.get_year())
|
2009-03-21 04:43:06 +05:30
|
|
|
|
|
|
|
# number of years for birthday, ex: 10 years
|
|
|
|
age_str = event_date - date
|
2009-12-24 13:25:26 +05:30
|
|
|
age_str.format(precision = 1)
|
2009-03-21 04:43:06 +05:30
|
|
|
|
|
|
|
# a birthday
|
|
|
|
if event == 'Birthday':
|
|
|
|
|
2009-10-30 23:31:48 +05:30
|
|
|
txt_str = (text + ', <em>'
|
2009-10-06 15:12:52 +05:30
|
|
|
+ (_('%s old') % str(age_str) if nyears else _('birth'))
|
2009-10-30 23:31:48 +05:30
|
|
|
+ '</em>')
|
2009-03-21 04:43:06 +05:30
|
|
|
|
|
|
|
# an anniversary
|
2009-10-08 11:18:43 +05:30
|
|
|
elif event == "Anniversary":
|
2009-03-21 04:43:06 +05:30
|
|
|
|
|
|
|
if nyears == 0:
|
|
|
|
txt_str = _('%(couple)s, <em>wedding</em>') % {
|
|
|
|
'couple' : text}
|
|
|
|
else:
|
|
|
|
txt_str = (ngettext('%(couple)s, <em>%(years)d'
|
|
|
|
'</em> year anniversary',
|
|
|
|
'%(couple)s, <em>%(years)d'
|
|
|
|
'</em> year anniversary', nyears)
|
|
|
|
% {'couple' : text, 'years' : nyears})
|
2009-09-11 11:54:13 +05:30
|
|
|
txt_str = Html('span', txt_str, class_ = "yearsmarried")
|
2009-03-21 04:43:06 +05:30
|
|
|
|
2009-03-26 16:47:57 +05:30
|
|
|
day_list.append((nyears, date, txt_str, event))
|
|
|
|
|
2009-03-21 04:43:06 +05:30
|
|
|
# sort them based on number of years
|
2009-03-30 03:56:36 +05:30
|
|
|
# holidays will always be on top of event list
|
2009-03-21 04:43:06 +05:30
|
|
|
day_list.sort()
|
|
|
|
|
2009-03-26 16:47:57 +05:30
|
|
|
# return to its caller calendar_build()
|
2009-03-21 04:43:06 +05:30
|
|
|
return day_list
|