revert last change of Rob for Braille, breaks 3.2

svn: r15263
This commit is contained in:
Benny Malengier 2010-04-22 07:30:53 +00:00
parent 4550baab10
commit 8cea9a51eb
2 changed files with 471 additions and 416 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,10 @@
# encoding: utf-8
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2007 Thom Sturgill
# Copyright (C) 2007 Thom Sturgill
# Copyright (C) 2007-2009 Brian G. Matherly
# Copyright (C) 2008-2010 Rob G. Healey <robhealey1@gmail.com>
# Copyright (C) 2008 Jason Simanek
# Copyright (C) 2008-2009 Rob G. Healey <robhealey1@gmail.com>
# Copyright (C) 2008 Jason Simanek
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -26,9 +25,14 @@
"""
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
@ -37,15 +41,19 @@ from gen.ggettext import ngettext
from itertools import imap
#------------------------------------------------------------------------
#
# Set up logging
#
#------------------------------------------------------------------------
import logging
log = logging.getLogger(".WebPage")
#------------------------------------------------------------------------
#
# GRAMPS module
#
#------------------------------------------------------------------------
import gen.lib
from gen.lib import date, Date, Name, Person, NameType, EventType
import const
import constfunc
from ReportBase import Report, ReportUtils, MenuReportOptions, CSS_FILES
@ -59,6 +67,7 @@ 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
@ -67,6 +76,7 @@ from libhtmlconst import _CHARACTER_SETS, _CC, _COPY_OPTIONS
# import styled notes from
# src/plugins/lib/libhtmlbackend.py
from libhtmlbackend import HtmlBackend
import Utils
#------------------------------------------------------------------------
#
# constants
@ -141,7 +151,7 @@ class WebCalReport(Report):
self.email = researcher.email
# set to today's date
self.today = gen.lib.date.Today()
self.today = date.Today()
self.warn_dir = True # Only give warning once.
@ -270,11 +280,11 @@ class WebCalReport(Report):
if month > 0:
try:
event_date = gen.lib.Date(year, month, day)
event_date = Date(year, month, day)
except ValueError:
event_date = gen.lib.Date.EMPTY
event_date = Date.EMPTY
else:
event_date = gen.lib.Date.EMPTY # Incomplete date....
event_date = Date.EMPTY # Incomplete date....
day_list.append((text, event, event_date))
month_dict[day] = day_list
@ -319,11 +329,6 @@ 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")
@ -384,7 +389,7 @@ class WebCalReport(Report):
# ---------------------------------------------------------------------------------------
# Beginning of Calendar Creation
# ---------------------------------------------------------------------------------------
def write_header(self, nr_up, title, body_id = None, add_print = True):
def write_header(self, nr_up, body_id, title, add_print=True):
"""
This creates the header for the Calendars
'nr_up' - number of directory levels up, started from current page, to the
@ -405,10 +410,6 @@ 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")
@ -421,25 +422,24 @@ 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)
# 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") )
links += Html("link",rel="stylesheet", href=fname,type="text/css", media="print",
indent = False)
# 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") + (
@ -500,11 +500,10 @@ class WebCalReport(Report):
# Figure out if we need <li class="CurrentSection"> or just plain <li>
cs = str(cal_year) == currentsection and 'class="CurrentSection"' or ''
unordered += Html("li", attr = cs, inline = True) + (
unordered += Html("li", attr=cs, inline = True) + (
# create hyperlink
Html("a", str(cal_year), href = url, title = _("Sub Navigation Menu Item: "
"Year %04d" % cal_year), inline = True)
Html("a", str(cal_year), href = url, title = "Year %04d" % cal_year, inline = True)
)
# return yearnav to its caller
@ -529,9 +528,7 @@ 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))
@ -573,7 +570,7 @@ class WebCalReport(Report):
unordered += Html("li", attr = cs, inline = True) + (
# create hyperlink
Html("a", nav_text, href = url, title = _("Main Navigation Menu Item: %s" % url_fname), inline = True)
Html("a", nav_text, href = url, title=url_fname, inline = True)
)
# return monthnav to its caller
@ -730,7 +727,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 = gen.lib.Date(thisday.year, thisday.month, thisday.day)
event_date = Date(thisday.year, thisday.month, thisday.day)
# get events for this day
day_list = get_day_list(event_date, holiday_list, bday_anniv_list)
@ -779,8 +776,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:
@ -842,12 +839,13 @@ 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, self.title_text)
webcal, body = self.write_header(nr_up, 'WebCal', self.title_text)
# create Year Navigation menu
if (self.multiyear and ((self.end_year - self.start_year) > 0)):
@ -903,6 +901,7 @@ 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
@ -910,7 +909,7 @@ class WebCalReport(Report):
# Create page header
# body has already been added to yearglance already once
yearglance, body = self.write_header(nr_up, title, "fullyearlinked", False)
yearglance, body = self.write_header(nr_up, 'fullyearlinked', title, False)
# create Year Navigation menu
if (self.multiyear and ((self.end_year - self.start_year) > 0)):
@ -972,13 +971,14 @@ 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, title, "OneDay")
oneday, body = self.write_header(nr_up, 'OneDay', title)
# 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()) == gen.lib.NameType.MARRIED:
if int(name.get_type()) == NameType.MARRIED:
married_name = name
break
# Now, decide which to use:
if maiden_name is not None:
if married_name is not None:
name = gen.lib.Name(married_name)
name = Name(married_name)
else:
name = gen.lib.Name(primary_name)
name = Name(primary_name)
name.set_surname(maiden_name)
else:
name = gen.lib.Name(primary_name)
name = Name(primary_name)
name.set_display_as(self.name_format)
return _nd.display_name(name)
@ -1099,13 +1099,14 @@ class WebCalReport(Report):
family_list = person.get_family_handle_list()
birth_ref = person.get_birth_ref()
birth_date = gen.lib.Date.EMPTY
birth_date = 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 gen.lib.Date.EMPTY and birth_date.is_valid()):
if (self.birthday and birth_date is not Date.EMPTY
and birth_date.is_valid()):
year = birth_date.get_year() or this_year
month = birth_date.get_month()
@ -1113,11 +1114,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 = gen.lib.Date(this_year, month, day)
prob_alive_date = Date(this_year, month, day)
# add some things to handle maiden name:
father_surname = None # husband, actually
if person.gender == gen.lib.Person.FEMALE:
if person.gender == Person.FEMALE:
# get husband's last name:
if self.maiden_name in ['spouse_first', 'spouse_last']:
@ -1133,8 +1134,7 @@ 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.get_primary_name())
father_surname = _get_regular_surname(person.gender, father.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 gen.lib.Date.EMPTY and event_date.is_valid():
if event_date is not 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 = gen.lib.Date(this_year, month, day)
prob_alive_date = Date(this_year, month, day)
if self.link_to_narweb:
spouse_name = Html("a", spouse_name,
@ -1209,8 +1209,7 @@ 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(
gen.lib.date.Today())}
'Gramps</a> on %(date)s') % {'date' : _dd.display(date.Today())}
footer += Html("p", msg, id = 'createdate')
copy_nr = self.copy
@ -1385,7 +1384,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 stylesheet to be used for the web pages'))
css.set_help( _('The Style Sheet to be used for the web page'))
menu.add_option(category_name, "css", css)
def __add_content_options(self, menu):
@ -1395,7 +1394,7 @@ class WebCalOptions(MenuReportOptions):
category_name = _("Content Options")
# set to today's date for use in menu, etc.
today = gen.lib.date.Today()
today = date.Today()
self.__multiyear = BooleanOption(_('Create multiple year calendars'), False)
self.__multiyear.set_help(_('Whether to create Multiple year calendars or not.'))
@ -1609,7 +1608,7 @@ def _get_regular_surname(sex, name):
prefix = name.get_surname_prefix()
if prefix:
surname = prefix + " " + surname
if sex is not gen.lib.Person.FEMALE:
if sex is not Person.FEMALE:
suffix = name.get_suffix()
if suffix:
surname = surname + ", " + suffix
@ -1701,7 +1700,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 != gen.lib.Date.EMPTY]
if d != 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