Committed same changes for NarrativeWeb and WebCal for Screen Readers and Braille writers.
svn: r15258
This commit is contained in:
parent
13b5c5a524
commit
00b0412fee
File diff suppressed because it is too large
Load Diff
@ -1,9 +1,10 @@
|
||||
# encoding: utf-8
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2007 Thom Sturgill
|
||||
# Copyright (C) 2007-2009 Brian G. Matherly
|
||||
# Copyright (C) 2008-2009 Rob G. Healey <robhealey1@gmail.com>
|
||||
# Copyright (C) 2008-2010 Rob G. Healey <robhealey1@gmail.com>
|
||||
# Copyright (C) 2008 Jason Simanek
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
@ -25,14 +26,9 @@
|
||||
|
||||
"""
|
||||
Web Calendar generator.
|
||||
|
||||
Refactoring. This is an ongoing job until this plugin is in a better shape.
|
||||
"""
|
||||
from __future__ import with_statement
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# python modules
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
import os, codecs, shutil, re
|
||||
import datetime, calendar
|
||||
@ -41,19 +37,15 @@ from gen.ggettext import ngettext
|
||||
from itertools import imap
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# Set up logging
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
import logging
|
||||
log = logging.getLogger(".WebPage")
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# GRAMPS module
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
from gen.lib import date, Date, Name, Person, NameType, EventType
|
||||
import gen.lib
|
||||
import const
|
||||
import constfunc
|
||||
from ReportBase import Report, ReportUtils, MenuReportOptions, CSS_FILES
|
||||
@ -67,7 +59,6 @@ from gui.utils import ProgressMeter
|
||||
from DateHandler import displayer as _dd
|
||||
|
||||
from gen.display.name import displayer as _nd
|
||||
from DateHandler import displayer as _dd
|
||||
|
||||
import libholiday
|
||||
from libhtml import Html
|
||||
@ -76,7 +67,6 @@ from libhtmlconst import _CHARACTER_SETS, _CC, _COPY_OPTIONS
|
||||
# import styled notes from
|
||||
# src/plugins/lib/libhtmlbackend.py
|
||||
from libhtmlbackend import HtmlBackend
|
||||
import Utils
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# constants
|
||||
@ -151,7 +141,7 @@ class WebCalReport(Report):
|
||||
self.email = researcher.email
|
||||
|
||||
# set to today's date
|
||||
self.today = date.Today()
|
||||
self.today = gen.lib.date.Today()
|
||||
|
||||
self.warn_dir = True # Only give warning once.
|
||||
|
||||
@ -280,11 +270,11 @@ class WebCalReport(Report):
|
||||
|
||||
if month > 0:
|
||||
try:
|
||||
event_date = Date(year, month, day)
|
||||
event_date = gen.lib.Date(year, month, day)
|
||||
except ValueError:
|
||||
event_date = Date.EMPTY
|
||||
event_date = gen.lib.Date.EMPTY
|
||||
else:
|
||||
event_date = Date.EMPTY # Incomplete date....
|
||||
event_date = gen.lib.Date.EMPTY # Incomplete date....
|
||||
|
||||
day_list.append((text, event, event_date))
|
||||
month_dict[day] = day_list
|
||||
@ -329,6 +319,11 @@ class WebCalReport(Report):
|
||||
fname = os.path.join(const.DATA_DIR, self.css)
|
||||
self.copy_file(fname, _CALENDARSCREEN, "styles")
|
||||
|
||||
# copy Navigation Menu Layout if Blue or Visually is being used
|
||||
if self.css == "Web_Basic-Blue.css" or "Web_Visually.css":
|
||||
fname = os.path.join(const.DATA_DIR, "Web_Navigation-Horizontal.css")
|
||||
self.copy_file(fname, "Web_Navigation-Menus.css", "styles")
|
||||
|
||||
# copy print stylesheet
|
||||
fname = os.path.join(const.DATA_DIR, "Web_Print-Default.css")
|
||||
self.copy_file(fname, _CALENDARPRINT, "styles")
|
||||
@ -389,7 +384,7 @@ class WebCalReport(Report):
|
||||
# ---------------------------------------------------------------------------------------
|
||||
# Beginning of Calendar Creation
|
||||
# ---------------------------------------------------------------------------------------
|
||||
def write_header(self, nr_up, body_id, title, add_print=True):
|
||||
def write_header(self, nr_up, title, body_id = None, add_print = True):
|
||||
"""
|
||||
This creates the header for the Calendars
|
||||
'nr_up' - number of directory levels up, started from current page, to the
|
||||
@ -410,6 +405,10 @@ class WebCalReport(Report):
|
||||
|
||||
page, head, body = Html.page(title, self.encoding, xmllang)
|
||||
|
||||
# add body id tag if not None
|
||||
if body_id is not None:
|
||||
body.attr = "id = '%(idtag)s'" % { 'idtag' : body_id }
|
||||
|
||||
# GRAMPS favicon
|
||||
fname1 = os.path.join(subdirs, "images", "favicon.ico")
|
||||
|
||||
@ -422,24 +421,25 @@ class WebCalReport(Report):
|
||||
)
|
||||
|
||||
# links for GRAMPS favicon and stylesheets
|
||||
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)
|
||||
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)
|
||||
)
|
||||
|
||||
# add printer stylesheet to webcalendar() and one_day() only
|
||||
if add_print:
|
||||
fname = os.path.join(subdirs, "styles", _CALENDARPRINT)
|
||||
links += Html("link",rel="stylesheet", href=fname,type="text/css", media="print",
|
||||
indent = False)
|
||||
links += Html("link",rel="stylesheet", href=fname,type="text/css", media="print", indent = False)
|
||||
|
||||
# add horizontal menu if css == Blue or Visually because there is no menus
|
||||
if self.css in ["Web_Basic-Blue.css", "Web_Visually.css"]:
|
||||
|
||||
# Link to Navigation Menus stylesheet
|
||||
fname = os.path.join(subdirs, "styles", "Web_Navigation-Menus.css")
|
||||
links.extend( Html("link", href = fname, type = "text/css", media = "screen", rel = "stylesheet") )
|
||||
|
||||
# add meta tags and links to head section
|
||||
head += (meta, links)
|
||||
|
||||
# replace standard body element with custom one
|
||||
body.attr = 'id="%s"' % body_id
|
||||
|
||||
# start header division section
|
||||
header = Html("div", id="header") + (
|
||||
|
||||
@ -503,7 +503,8 @@ class WebCalReport(Report):
|
||||
unordered += Html("li", attr = cs, inline = True) + (
|
||||
|
||||
# create hyperlink
|
||||
Html("a", str(cal_year), href = url, title = "Year %04d" % cal_year, inline = True)
|
||||
Html("a", str(cal_year), href = url, title = _("Sub Navigation Menu Item: "
|
||||
"Year %04d" % cal_year), inline = True)
|
||||
)
|
||||
|
||||
# return yearnav to its caller
|
||||
@ -528,7 +529,9 @@ class WebCalReport(Report):
|
||||
|
||||
# An optional link to a home page
|
||||
navs.append((self.home_link, _('html|Home'), add_home))
|
||||
navs.extend((month, month, True) for month in range(1,13))
|
||||
navs.extend(
|
||||
(month, month, True) for month in range(1,13)
|
||||
)
|
||||
|
||||
# Add a link for year_glance() if requested
|
||||
navs.append(('fullyearlinked', _('Year Glance'), self.fullyear))
|
||||
@ -570,7 +573,7 @@ class WebCalReport(Report):
|
||||
unordered += Html("li", attr = cs, inline = True) + (
|
||||
|
||||
# create hyperlink
|
||||
Html("a", nav_text, href = url, title=url_fname, inline = True)
|
||||
Html("a", nav_text, href = url, title = _("Main Navigation Menu Item: %s" % url_fname), inline = True)
|
||||
)
|
||||
|
||||
# return monthnav to its caller
|
||||
@ -727,7 +730,7 @@ class WebCalReport(Report):
|
||||
bday_anniv_list = self.calendar.get(month, {}).get(thisday.day, [])
|
||||
|
||||
# date is an instance because of subtracting abilities in date.py
|
||||
event_date = Date(thisday.year, thisday.month, thisday.day)
|
||||
event_date = gen.lib.Date(thisday.year, thisday.month, thisday.day)
|
||||
|
||||
# get events for this day
|
||||
day_list = get_day_list(event_date, holiday_list, bday_anniv_list)
|
||||
@ -776,8 +779,8 @@ class WebCalReport(Report):
|
||||
tcell += unordered
|
||||
|
||||
for nyears, date, text, event in day_list:
|
||||
unordered += Html("li", text, inline = False if event == 'Anniversary'
|
||||
else True)
|
||||
unordered += Html("li", text, inline = False
|
||||
if event == 'Anniversary' else True)
|
||||
|
||||
# no events for this day
|
||||
else:
|
||||
@ -839,13 +842,12 @@ class WebCalReport(Report):
|
||||
|
||||
for month in range(1, 13):
|
||||
|
||||
# Name the file, and create it
|
||||
cal_fname = get_full_month_name(month)
|
||||
of = self.create_file(cal_fname, str(year))
|
||||
|
||||
# Add xml, doctype, meta and stylesheets
|
||||
# body has already been added to webcal already once
|
||||
webcal, body = self.write_header(nr_up, 'WebCal', self.title_text)
|
||||
webcal, body = self.write_header(nr_up, self.title_text)
|
||||
|
||||
# create Year Navigation menu
|
||||
if (self.multiyear and ((self.end_year - self.start_year) > 0)):
|
||||
@ -901,7 +903,6 @@ class WebCalReport(Report):
|
||||
# generate progress pass for "Year At A Glance"
|
||||
self.progress.set_pass(_('Creating Year At A Glance calendar'), 12)
|
||||
|
||||
# Name the file, and create it
|
||||
of = self.create_file('fullyearlinked', str(year))
|
||||
|
||||
# page title
|
||||
@ -909,7 +910,7 @@ class WebCalReport(Report):
|
||||
|
||||
# Create page header
|
||||
# body has already been added to yearglance already once
|
||||
yearglance, body = self.write_header(nr_up, 'fullyearlinked', title, False)
|
||||
yearglance, body = self.write_header(nr_up, title, "fullyearlinked", False)
|
||||
|
||||
# create Year Navigation menu
|
||||
if (self.multiyear and ((self.end_year - self.start_year) > 0)):
|
||||
@ -971,14 +972,13 @@ class WebCalReport(Report):
|
||||
year = event_date.get_year()
|
||||
month = event_date.get_month()
|
||||
|
||||
# Name the file, and crate it (see code in calendar_build)
|
||||
od = self.create_file(fname_date, str(year))
|
||||
|
||||
# page title
|
||||
title = _('One Day Within A Year')
|
||||
|
||||
# create page header
|
||||
oneday, body = self.write_header(nr_up, 'OneDay', title)
|
||||
oneday, body = self.write_header(nr_up, title, "OneDay")
|
||||
|
||||
# create Year Navigation menu
|
||||
if (self.multiyear and ((self.end_year - self.start_year) > 0)):
|
||||
@ -1063,19 +1063,19 @@ class WebCalReport(Report):
|
||||
married_name = None
|
||||
names = [primary_name] + person.get_alternate_names()
|
||||
for name in names:
|
||||
if int(name.get_type()) == NameType.MARRIED:
|
||||
if int(name.get_type()) == gen.lib.NameType.MARRIED:
|
||||
married_name = name
|
||||
break
|
||||
|
||||
# Now, decide which to use:
|
||||
if maiden_name is not None:
|
||||
if married_name is not None:
|
||||
name = Name(married_name)
|
||||
name = gen.lib.Name(married_name)
|
||||
else:
|
||||
name = Name(primary_name)
|
||||
name = gen.lib.Name(primary_name)
|
||||
name.set_surname(maiden_name)
|
||||
else:
|
||||
name = Name(primary_name)
|
||||
name = gen.lib.Name(primary_name)
|
||||
name.set_display_as(self.name_format)
|
||||
return _nd.display_name(name)
|
||||
|
||||
@ -1099,14 +1099,13 @@ class WebCalReport(Report):
|
||||
|
||||
family_list = person.get_family_handle_list()
|
||||
birth_ref = person.get_birth_ref()
|
||||
birth_date = Date.EMPTY
|
||||
birth_date = gen.lib.Date.EMPTY
|
||||
if birth_ref:
|
||||
birth_event = db.get_event_from_handle(birth_ref.ref)
|
||||
birth_date = birth_event.get_date_object()
|
||||
|
||||
# determine birthday information???
|
||||
if (self.birthday and birth_date is not Date.EMPTY
|
||||
and birth_date.is_valid()):
|
||||
if (self.birthday and birth_date is not gen.lib.Date.EMPTY and birth_date.is_valid()):
|
||||
|
||||
year = birth_date.get_year() or this_year
|
||||
month = birth_date.get_month()
|
||||
@ -1114,11 +1113,11 @@ class WebCalReport(Report):
|
||||
|
||||
# date to figure if someone is still alive
|
||||
# current year of calendar, month nd day is their birth month and birth day
|
||||
prob_alive_date = Date(this_year, month, day)
|
||||
prob_alive_date = gen.lib.Date(this_year, month, day)
|
||||
|
||||
# add some things to handle maiden name:
|
||||
father_surname = None # husband, actually
|
||||
if person.gender == Person.FEMALE:
|
||||
if person.gender == gen.lib.Person.FEMALE:
|
||||
|
||||
# get husband's last name:
|
||||
if self.maiden_name in ['spouse_first', 'spouse_last']:
|
||||
@ -1134,7 +1133,8 @@ class WebCalReport(Report):
|
||||
if father_handle:
|
||||
father = db.get_person_from_handle(father_handle)
|
||||
if father is not None:
|
||||
father_surname = _get_regular_surname(person.gender, father.primary_name)
|
||||
father_surname = _get_regular_surname(person.gender,
|
||||
father.get_primary_name())
|
||||
short_name = self.get_name(person, father_surname)
|
||||
alive = probably_alive(person, db, prob_alive_date)
|
||||
if (self.alive and alive) or not self.alive:
|
||||
@ -1168,13 +1168,13 @@ class WebCalReport(Report):
|
||||
marriage_event = get_marriage_event(db, fam)
|
||||
if marriage_event:
|
||||
event_date = marriage_event.get_date_object()
|
||||
if event_date is not Date.EMPTY and event_date.is_valid():
|
||||
if event_date is not gen.lib.Date.EMPTY and event_date.is_valid():
|
||||
year = event_date.get_year()
|
||||
month = event_date.get_month()
|
||||
day = event_date.get_day()
|
||||
|
||||
# date to figure if someone is still alive
|
||||
prob_alive_date = Date(this_year, month, day)
|
||||
prob_alive_date = gen.lib.Date(this_year, month, day)
|
||||
|
||||
if self.link_to_narweb:
|
||||
spouse_name = Html("a", spouse_name,
|
||||
@ -1209,7 +1209,8 @@ class WebCalReport(Report):
|
||||
|
||||
# Display date as user set in preferences
|
||||
msg = _('Generated by <a href="http://gramps-project.org">'
|
||||
'Gramps</a> on %(date)s') % {'date' : _dd.display(date.Today())}
|
||||
'Gramps</a> on %(date)s') % {'date' : _dd.display(
|
||||
gen.lib.date.Today())}
|
||||
footer += Html("p", msg, id = 'createdate')
|
||||
|
||||
copy_nr = self.copy
|
||||
@ -1384,7 +1385,7 @@ class WebCalOptions(MenuReportOptions):
|
||||
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'))
|
||||
css.set_help( _('The stylesheet to be used for the web pages'))
|
||||
menu.add_option(category_name, "css", css)
|
||||
|
||||
def __add_content_options(self, menu):
|
||||
@ -1394,7 +1395,7 @@ class WebCalOptions(MenuReportOptions):
|
||||
category_name = _("Content Options")
|
||||
|
||||
# set to today's date for use in menu, etc.
|
||||
today = date.Today()
|
||||
today = gen.lib.date.Today()
|
||||
|
||||
self.__multiyear = BooleanOption(_('Create multiple year calendars'), False)
|
||||
self.__multiyear.set_help(_('Whether to create Multiple year calendars or not.'))
|
||||
@ -1608,7 +1609,7 @@ def _get_regular_surname(sex, name):
|
||||
prefix = name.get_surname_prefix()
|
||||
if prefix:
|
||||
surname = prefix + " " + surname
|
||||
if sex is not Person.FEMALE:
|
||||
if sex is not gen.lib.Person.FEMALE:
|
||||
suffix = name.get_suffix()
|
||||
if suffix:
|
||||
surname = surname + ", " + suffix
|
||||
@ -1700,7 +1701,7 @@ def get_day_list(event_date, holiday_list, bday_anniv_list):
|
||||
# birthday/ anniversary on this day
|
||||
# Date.EMPTY signifies an incomplete date for an event. See add_day_item()
|
||||
bday_anniv_list = [(t, e, d) for t, e, d in bday_anniv_list
|
||||
if d != Date.EMPTY]
|
||||
if d != gen.lib.Date.EMPTY]
|
||||
|
||||
# number of years have to be at least zero
|
||||
bday_anniv_list = [(t, e, d) for t, e, d in bday_anniv_list
|
||||
|
Loading…
x
Reference in New Issue
Block a user