Change HTML5 support so that pages pass the w3c validator tests

svn: r18743
This commit is contained in:
Gerald Britton 2012-01-14 20:27:24 +00:00
parent f1daa8d018
commit 6831989736
3 changed files with 64 additions and 48 deletions

View File

@ -1,5 +1,5 @@
# This is the src level Makefile for Gramps # This is the src level Makefile for Gramps
# $Id: Makefile.am 16464 2011-01-24 21:50:06Z bmcage $ # $Id$
SUBDIRS = \ SUBDIRS = \
cli \ cli \

View File

@ -181,7 +181,7 @@ class Html(list):
) )
# #
@staticmethod @staticmethod
def head(title=None, encoding='utf-8', *args, **keywargs): def head(title=None, encoding='utf-8', html5=True, *args, **keywargs):
""" """
Build and return a properly-formated <head> object Build and return a properly-formated <head> object
@ -190,20 +190,26 @@ class Html(list):
title tag is written title tag is written
:type encoding: string :type encoding: string
:param encoding: encoding to be used. Default = 'utf-8' :param encoding: encoding to be used. Default = 'utf-8'
:param html5: generate html5 syntax. Default = True. Set to False
if pre-html5 syntax required
:rtype: reference to new Html instance :rtype: reference to new Html instance
:returns: reference to the newly-created Html instances for <head> object :returns: reference to the newly-created Html instances for <head> object
""" """
meta1 = 'http-equiv="content-type" content="text/html;charset=%s"'
meta2 = 'http-equiv="Content-Style-Type" content="text/css"'
head = Html('head', *args, **keywargs) head = Html('head', *args, **keywargs)
if title is not None: if title is not None:
head += (Html('title', title, inline=True, indent=True)) head += (Html('title', title, inline=True, indent=True))
if html5:
head += Html('meta', charset="utf-8", indent=True)
else:
meta1 = 'http-equiv="content-type" content="text/html;charset=%s"'
meta2 = 'http-equiv="Content-Style-Type" content="text/css"'
head += Html('meta', attr=meta1 % encoding, indent=True) head += Html('meta', attr=meta1 % encoding, indent=True)
head += Html('meta', attr=meta2, indent=True) head += Html('meta', attr=meta2, indent=True)
return head return head
# #
@staticmethod @staticmethod
def page(title=None, encoding='utf-8', lang='en', *args, **keywargs): def page(title=None, encoding='utf-8', lang='en', html5=True, *args, **keywargs):
""" """
This function prepares a new Html class based page and returns This function prepares a new Html class based page and returns
@ -213,17 +219,23 @@ class Html(list):
:param encoding: encoding to be used. Default = 'utf-8' :param encoding: encoding to be used. Default = 'utf-8'
:type lang: string :type lang: string
:param lang: language to be used. Defaul = 'en' :param lang: language to be used. Defaul = 'en'
:param html5: generate html5 syntax. Default = True. Set to False
if pre-html5 syntax required
:rtype: three object references :rtype: three object references
:returns: references to the newly-created Html instances for :returns: references to the newly-created Html instances for
page, head and body page, head and body
""" """
page = Html.html(lang=lang, *args, **keywargs) page = Html.html(lang=lang, *args, **keywargs)
if html5:
page.addDOCTYPE(external_id=_HTML5)
else:
page.addXML(encoding=encoding) page.addXML(encoding=encoding)
page.addDOCTYPE() page.addDOCTYPE(external_id=_XHTML10_STRICT)
# #
head = Html.head(title=title, head = Html.head(title=title,
encoding=encoding, encoding=encoding,
lang=lang, lang=lang,
html5=html5,
indent=False, indent=False,
*args, **keywargs *args, **keywargs
) )
@ -429,7 +441,7 @@ class Html(list):
) )
self[0:0] = [xmldecl] self[0:0] = [xmldecl]
# #
def addDOCTYPE(self, name='HTML', public='', def addDOCTYPE(self, name='html', public='PUBLIC',
external_id=_HTML5, *args): external_id=_HTML5, *args):
""" """
Add a DOCTYPE statement to the start of the list Add a DOCTYPE statement to the start of the list
@ -446,7 +458,7 @@ class Html(list):
doctype = ( doctype = (
'<!DOCTYPE %s %s %s%s' % ( '<!DOCTYPE %s %s %s%s' % (
name, name,
public, ('' if external_id ==_HTML5 else public),
external_id, external_id,
' %s'*len(args) % args ' %s'*len(args) % args
) )

View File

@ -99,7 +99,8 @@ class WebCalReport(Report):
""" """
def __init__(self, database, options, user): def __init__(self, database, options, user):
Report.__init__(self, database, options, user) Report.__init__(self, database, options, user)
mgobn = lambda name:options.menu.get_option_by_name(name).get_value() get_option_by_name = options.menu.get_option_by_name
mgobn = lambda name:get_option_by_name(name).get_value()
self._user = user self._user = user
# class to do conversion of styled notes to html markup # class to do conversion of styled notes to html markup
@ -1284,26 +1285,27 @@ class WebCalOptions(MenuReportOptions):
Options on the "Report Options" tab. Options on the "Report Options" tab.
""" """
category_name = _("Report Options") category_name = _("Report Options")
add_option = partial(menu.add_option, category_name)
target = DestinationOption( _("Destination"), target = DestinationOption( _("Destination"),
os.path.join(const.USER_HOME, "WEBCAL")) os.path.join(const.USER_HOME, "WEBCAL"))
target.set_help( _("The destination directory for the web files")) target.set_help( _("The destination directory for the web files"))
target.set_directory_entry(True) target.set_directory_entry(True)
menu.add_option(category_name, "target", target) add_option("target", target)
title = StringOption(_('Calendar Title'), _('My Family Calendar')) title = StringOption(_('Calendar Title'), _('My Family Calendar'))
title.set_help(_("The title of the calendar")) title.set_help(_("The title of the calendar"))
menu.add_option(category_name, "title", title) add_option("title", title)
self.__filter = FilterOption(_("Filter"), 0) self.__filter = FilterOption(_("Filter"), 0)
self.__filter.set_help( self.__filter.set_help(
_("Select filter to restrict people that appear on calendar")) _("Select filter to restrict people that appear on calendar"))
menu.add_option(category_name, "filter", self.__filter) add_option("filter", self.__filter)
self.__filter.connect('value-changed', self.__filter_changed) self.__filter.connect('value-changed', self.__filter_changed)
self.__pid = PersonOption(_("Filter Person")) self.__pid = PersonOption(_("Filter Person"))
self.__pid.set_help(_("The center person for the filter")) self.__pid.set_help(_("The center person for the filter"))
menu.add_option(category_name, "pid", self.__pid) add_option("pid", self.__pid)
self.__pid.connect('value-changed', self.__update_filters) self.__pid.connect('value-changed', self.__update_filters)
self.__update_filters() self.__update_filters()
@ -1322,19 +1324,19 @@ class WebCalOptions(MenuReportOptions):
for num, name, fmt_str, act in fmt_list: for num, name, fmt_str, act in fmt_list:
name_format.add_item(num, name) name_format.add_item(num, name)
name_format.set_help(_("Select the format to display names")) name_format.set_help(_("Select the format to display names"))
menu.add_option(category_name, "name_format", name_format) add_option("name_format", name_format)
ext = EnumeratedListOption(_("File extension"), ".html" ) ext = EnumeratedListOption(_("File extension"), ".html" )
for etype in _WEB_EXT: for etype in _WEB_EXT:
ext.add_item(etype, etype) ext.add_item(etype, etype)
ext.set_help( _("The extension to be used for the web files")) ext.set_help( _("The extension to be used for the web files"))
menu.add_option(category_name, "ext", ext) add_option("ext", ext)
cright = EnumeratedListOption(_('Copyright'), 0 ) cright = EnumeratedListOption(_('Copyright'), 0 )
for index, copt in enumerate(_COPY_OPTIONS): for index, copt in enumerate(_COPY_OPTIONS):
cright.add_item(index, copt) cright.add_item(index, copt)
cright.set_help( _("The copyright to be used for the web files")) cright.set_help( _("The copyright to be used for the web files"))
menu.add_option(category_name, "cright", cright) add_option("cright", cright)
css_list = sorted([(CSS[key]["translation"], CSS[key]["id"]) css_list = sorted([(CSS[key]["translation"], CSS[key]["id"])
for key in CSS.keys() for key in CSS.keys()
@ -1343,33 +1345,34 @@ class WebCalOptions(MenuReportOptions):
for css_item in css_list: for css_item in css_list:
css.add_item(css_item[1], css_item[0]) css.add_item(css_item[1], css_item[0])
css.set_help( _('The stylesheet to be used for the web pages')) css.set_help( _('The stylesheet to be used for the web pages'))
menu.add_option(category_name, "css", css) add_option("css", css)
def __add_content_options(self, menu): def __add_content_options(self, menu):
""" """
Options on the "Content Options" tab. Options on the "Content Options" tab.
""" """
category_name = _("Content Options") category_name = _("Content Options")
add_option = partial(menu.add_option, category_name)
# set to today's date for use in menu, etc. # set to today's date for use in menu, etc.
today = gen.lib.date.Today() today = gen.lib.date.Today()
self.__multiyear = BooleanOption(_('Create multiple year calendars'), False) self.__multiyear = BooleanOption(_('Create multiple year calendars'), False)
self.__multiyear.set_help(_('Whether to create Multiple year calendars or not.')) self.__multiyear.set_help(_('Whether to create Multiple year calendars or not.'))
menu.add_option(category_name, 'multiyear', self.__multiyear) add_option('multiyear', self.__multiyear)
self.__multiyear.connect('value-changed', self.__multiyear_changed) self.__multiyear.connect('value-changed', self.__multiyear_changed)
self.__start_year = NumberOption(_('Start Year for the Calendar(s)'), today.get_year(), self.__start_year = NumberOption(_('Start Year for the Calendar(s)'), today.get_year(),
1900, 3000) 1900, 3000)
self.__start_year.set_help(_('Enter the starting year for the calendars ' self.__start_year.set_help(_('Enter the starting year for the calendars '
'between 1900 - 3000')) 'between 1900 - 3000'))
menu.add_option(category_name, 'start_year', self.__start_year) add_option('start_year', self.__start_year)
self.__end_year = NumberOption(_('End Year for the Calendar(s)'), today.get_year(), self.__end_year = NumberOption(_('End Year for the Calendar(s)'), today.get_year(),
1900, 3000) 1900, 3000)
self.__end_year.set_help(_('Enter the ending year for the calendars ' self.__end_year.set_help(_('Enter the ending year for the calendars '
'between 1900 - 3000.')) 'between 1900 - 3000.'))
menu.add_option(category_name, 'end_year', self.__end_year) add_option('end_year', self.__end_year)
self.__multiyear_changed() self.__multiyear_changed()
@ -1386,7 +1389,7 @@ class WebCalOptions(MenuReportOptions):
count += 1 count += 1
country.set_help(_("Holidays will be included for the selected " country.set_help(_("Holidays will be included for the selected "
"country")) "country"))
menu.add_option(category_name, "country", country) add_option("country", country)
maiden_name = EnumeratedListOption(_("Birthday surname"), "own") maiden_name = EnumeratedListOption(_("Birthday surname"), "own")
maiden_name.add_item('spouse_first', _("Wives use husband's surname " maiden_name.add_item('spouse_first', _("Wives use husband's surname "
@ -1395,120 +1398,121 @@ class WebCalOptions(MenuReportOptions):
"(from last family listed)")) "(from last family listed)"))
maiden_name.add_item("own", _("Wives use their own surname")) maiden_name.add_item("own", _("Wives use their own surname"))
maiden_name.set_help(_("Select married women's displayed surname")) maiden_name.set_help(_("Select married women's displayed surname"))
menu.add_option(category_name, "maiden_name", maiden_name) add_option("maiden_name", maiden_name)
# Default selection ???? # Default selection ????
start_dow = EnumeratedListOption(_("First day of week"), 1) start_dow = EnumeratedListOption(_("First day of week"), 1)
for count in range(1, 8): for count in range(1, 8):
start_dow.add_item(count, GrampsLocale.long_days[count].capitalize()) start_dow.add_item(count, GrampsLocale.long_days[count].capitalize())
start_dow.set_help(_("Select the first day of the week for the calendar")) start_dow.set_help(_("Select the first day of the week for the calendar"))
menu.add_option(category_name, "start_dow", start_dow) add_option("start_dow", start_dow)
home_link = StringOption(_('Home link'), '../../NAVWEB/index.html') home_link = StringOption(_('Home link'), '../../NAVWEB/index.html')
home_link.set_help(_("The link to be included to direct the user to " home_link.set_help(_("The link to be included to direct the user to "
"the main page of the web site")) "the main page of the web site"))
menu.add_option(category_name, "home_link", home_link) add_option("home_link", home_link)
alive = BooleanOption(_("Include only living people"), True) alive = BooleanOption(_("Include only living people"), True)
alive.set_help(_("Include only living people in the calendar")) alive.set_help(_("Include only living people in the calendar"))
menu.add_option(category_name, "alive", alive) add_option("alive", alive)
birthdays = BooleanOption(_("Include birthdays"), True) birthdays = BooleanOption(_("Include birthdays"), True)
birthdays.set_help(_("Include birthdays in the calendar")) birthdays.set_help(_("Include birthdays in the calendar"))
menu.add_option(category_name, "birthdays", birthdays) add_option("birthdays", birthdays)
anniversaries = BooleanOption(_("Include anniversaries"), True) anniversaries = BooleanOption(_("Include anniversaries"), True)
anniversaries.set_help(_("Include anniversaries in the calendar")) anniversaries.set_help(_("Include anniversaries in the calendar"))
menu.add_option(category_name, "anniversaries", anniversaries) add_option("anniversaries", anniversaries)
def __add_notes_options(self, menu): def __add_notes_options(self, menu):
""" """
Options on the "Months Notes" tabs. Options on the "Months Notes" tabs.
""" """
category_name = _("Jan - Jun Notes") category_name = _("Jan - Jun Notes")
add_option = partial(menu.add_option, category_name)
note_jan = NoteOption(_('January Note')) note_jan = NoteOption(_('January Note'))
note_jan.set_help(_("The note for the month of January")) note_jan.set_help(_("The note for the month of January"))
menu.add_option(category_name, "note_jan", note_jan) add_option("note_jan", note_jan)
note_feb = NoteOption(_('February Note')) note_feb = NoteOption(_('February Note'))
note_feb.set_help(_("The note for the month of February")) note_feb.set_help(_("The note for the month of February"))
menu.add_option(category_name, "note_feb", note_feb) add_option("note_feb", note_feb)
note_mar = NoteOption(_('March Note')) note_mar = NoteOption(_('March Note'))
note_mar.set_help(_("The note for the month of March")) note_mar.set_help(_("The note for the month of March"))
menu.add_option(category_name, "note_mar", note_mar) add_option("note_mar", note_mar)
note_apr = NoteOption(_('April Note')) note_apr = NoteOption(_('April Note'))
note_apr.set_help(_("The note for the month of April")) note_apr.set_help(_("The note for the month of April"))
menu.add_option(category_name, "note_apr", note_apr) add_option("note_apr", note_apr)
note_may = NoteOption(_('May Note')) note_may = NoteOption(_('May Note'))
note_may.set_help(_("The note for the month of May")) note_may.set_help(_("The note for the month of May"))
menu.add_option(category_name, "note_may", note_may) add_option("note_may", note_may)
note_jun = NoteOption(_('June Note')) note_jun = NoteOption(_('June Note'))
note_jun.set_help(_("The note for the month of June")) note_jun.set_help(_("The note for the month of June"))
menu.add_option(category_name, "note_jun", note_jun) add_option("note_jun", note_jun)
category_name = _("Jul - Dec Notes") category_name = _("Jul - Dec Notes")
note_jul = NoteOption(_('July Note')) note_jul = NoteOption(_('July Note'))
note_jul.set_help(_("The note for the month of July")) note_jul.set_help(_("The note for the month of July"))
menu.add_option(category_name, "note_jul", note_jul) add_option("note_jul", note_jul)
note_aug = NoteOption(_('August Note')) note_aug = NoteOption(_('August Note'))
note_aug.set_help(_("The note for the month of August")) note_aug.set_help(_("The note for the month of August"))
menu.add_option(category_name, "note_aug", note_aug) add_option("note_aug", note_aug)
note_sep = NoteOption(_('September Note')) note_sep = NoteOption(_('September Note'))
note_sep.set_help(_("The note for the month of September")) note_sep.set_help(_("The note for the month of September"))
menu.add_option(category_name, "note_sep", note_sep) add_option("note_sep", note_sep)
note_oct = NoteOption(_('October Note')) note_oct = NoteOption(_('October Note'))
note_oct.set_help(_("The note for the month of October")) note_oct.set_help(_("The note for the month of October"))
menu.add_option(category_name, "note_oct", note_oct) add_option("note_oct", note_oct)
note_nov = NoteOption(_('November Note')) note_nov = NoteOption(_('November Note'))
note_nov.set_help(_("The note for the month of November")) note_nov.set_help(_("The note for the month of November"))
menu.add_option(category_name, "note_nov", note_nov) add_option("note_nov", note_nov)
note_dec = NoteOption(_('December Note')) note_dec = NoteOption(_('December Note'))
note_dec.set_help(_("The note for the month of December")) note_dec.set_help(_("The note for the month of December"))
menu.add_option(category_name, "note_dec", note_dec) add_option("note_dec", note_dec)
def __add_advanced_options(self, menu): def __add_advanced_options(self, menu):
""" """
Options for the advanced menu Options for the advanced menu
""" """
category_name = _('Advanced Options') category_name = _('Advanced Options')
add_option = partial(menu.add_option, category_name)
encoding = EnumeratedListOption(_('Character set encoding'), _CHARACTER_SETS[0][1]) encoding = EnumeratedListOption(_('Character set encoding'), _CHARACTER_SETS[0][1])
for eopt in _CHARACTER_SETS: for eopt in _CHARACTER_SETS:
encoding.add_item(eopt[1], eopt[0]) encoding.add_item(eopt[1], eopt[0])
encoding.set_help( _('The encoding to be used for the web files')) encoding.set_help( _('The encoding to be used for the web files'))
menu.add_option(category_name, "encoding", encoding) add_option("encoding", encoding)
fullyear = BooleanOption(_('Create "Year At A Glance" Calendar'), False) fullyear = BooleanOption(_('Create "Year At A Glance" Calendar'), False)
fullyear.set_help(_('Whether to create A one-page mini calendar ' fullyear.set_help(_('Whether to create A one-page mini calendar '
'with dates highlighted')) 'with dates highlighted'))
menu.add_option(category_name, 'fullyear', fullyear) add_option('fullyear', fullyear)
makeoneday = BooleanOption(_('Create one day event pages for' makeoneday = BooleanOption(_('Create one day event pages for'
' Year At A Glance calendar'), False) ' Year At A Glance calendar'), False)
makeoneday.set_help(_('Whether to create one day pages or not')) makeoneday.set_help(_('Whether to create one day pages or not'))
menu.add_option(category_name, 'makeoneday', makeoneday) add_option('makeoneday', makeoneday)
self.__links = BooleanOption(_('Link to Narrated Web Report'), False) self.__links = BooleanOption(_('Link to Narrated Web Report'), False)
self.__links.set_help(_('Whether to link data to web report or not')) self.__links.set_help(_('Whether to link data to web report or not'))
menu.add_option(category_name, 'link_to_narweb', self.__links) add_option('link_to_narweb', self.__links)
self.__links.connect('value-changed', self.__links_changed) self.__links.connect('value-changed', self.__links_changed)
self.__prefix = StringOption(_('Link prefix'), "../../NAVWEB/") self.__prefix = StringOption(_('Link prefix'), "../../NAVWEB/")
self.__prefix.set_help(_("A Prefix on the links to take you to " self.__prefix.set_help(_("A Prefix on the links to take you to "
"Narrated Web Report")) "Narrated Web Report"))
menu.add_option(category_name, "prefix", self.__prefix) add_option("prefix", self.__prefix)
self.__links_changed() self.__links_changed()