Fix the navigation links in WebCal

* src/plugins/WebCal.py


svn: r10949
This commit is contained in:
Kees Bakker 2008-07-31 20:42:05 +00:00
parent 126b06ef81
commit 5292cd0ed9

View File

@ -376,37 +376,42 @@ class WebCalReport(Report):
# Check to see if home_link will be used???
navs = [
(self.home_link,_('Home'), self.home_link),
('January', _('Jan'), True),
('February', _('Feb'), True),
('March', _('Mar'), True),
('April', _('Apr'), True),
('May', _('May'), True),
('June', _('Jun'), True),
('July', _('Jul'), True),
('August', _('Aug'), True),
('September', _('Sep'), True),
('October', _('Oct'), True),
('November', _('Nov'), True),
('December', _('Dec'), True),
(self.home_link, _('Home'), self.home_link),
(1, _('Jan'), True),
(2, _('Feb'), True),
(3, _('Mar'), True),
(4, _('Apr'), True),
(5, _('May'), True),
(6, _('Jun'), True),
(7, _('Jul'), True),
(8, _('Aug'), True),
(9, _('Sep'), True),
(10, _('Oct'), True),
(11, _('Nov'), True),
(12, _('Dec'), True),
('fullyear', _('Year Glance'), self.fullyear),
('blankyear', _('Blank Calendar'), self.blankyear)
]
for url_fname, nav_text, cond in navs:
if cond:
# Figure out if we need <li id="CurrentSection"> or just plain <li>
cs = ''
if url_fname == currentsection:
cs = ' id="CurrentSection"'
if type(url_fname) == int:
url_fname = GrampsLocale.long_months[url_fname]
new_dir = str(self.year)
url = _('unknown')
if ((cal == "yg") or (cal == "by")):
url = _subdirs("yg", new_dir, url_fname)
elif cal == "ip":
url = _subdirs("ip", new_dir, url_fname)
else:
url = _subdirs("wc", new_dir, url_fname)
url += self.ext
# Figure out if we need <li id="CurrentSection"> or just plain <li>
cs = ''
if nav_text == currentsection:
cs = ' id="CurrentSection"'
if not _has_webpage_extension(url):
url += self.ext
of.write(' <li%s><a href="%s">%s</a></li>\n' % (cs, url, nav_text))
@ -624,7 +629,7 @@ class WebCalReport(Report):
value = _dd.display(value)
msg = _('Generated by <a href="http://gramps-project.org" target="_blank">'
'GRAMPS</a> on %(date)s') % { 'date' : value }
'GRAMPS</a> on %(date)s') % {'date' : value}
author = get_researcher().get_name()
if author:
@ -659,9 +664,19 @@ class WebCalReport(Report):
of.write('</body>\n')
of.write('</html>\n')
def create_file(self, name):
page_name = os.path.join(self.html_dir, name)
of = codecs.EncodedFile(open(page_name, "w"), 'utf-8', self.encoding, 'xmlcharrefreplace')
def create_file(self, fname, subdir=None):
"""
Create a file in the html_dir tree.
If the directory does not exist, create it.
"""
if subdir:
subdir = os.path.join(self.html_dir, subdir)
else:
subdir = self.html_dir
if not os.path.isdir(subdir):
os.makedirs(subdir)
fname = os.path.join(subdir, fname)
of = codecs.EncodedFile(open(fname, "w"), 'utf-8', self.encoding, 'xmlcharrefreplace')
return of
def close_file(self, of):
@ -673,23 +688,19 @@ class WebCalReport(Report):
'dat_list' - lines of text to display at this day
"""
# TODO. Cleanup the "/" for URLs versus file names.
year = self.year
dest_dir = self.html_dir + "/images"
arrow = os.path.join(dest_dir, "arrow102.gif")
# Create names for long and short month names
# Create names for long and short month names, in LOcale
lng_month = GrampsLocale.long_months[month]
shrt_month = GrampsLocale.short_months[month]
new_dir = self.html_dir + "/%d/%s" % (year, lng_month)
if not os.path.isdir(new_dir):
os.mkdir(new_dir)
# Name the file, and create it
cal_file = '%d/%s/%s%d%s' % (year, lng_month, shrt_month, day_num, self.ext)
of = self.create_file(cal_file)
# TODO. Do we want locale month name here?
cal_fname = '%s%d%s' % (shrt_month, day_num, self.ext)
cal_fname = os.path.join(lng_month, cal_fname)
of = self.create_file(cal_fname, "%d" % year)
arrow = os.path.join(self.html_dir, "images", "arrow102.gif")
mystyle = """
<style type="text/css">
<!--
@ -717,12 +728,14 @@ class WebCalReport(Report):
author = self.write_header(of, title, "ip", mystyle)
of.write('<body id="events-%s%d">\n' % (shrt_month, day_num))
of.write(' <div id="header">\n')
if author:
of.write(' <div id="GRAMPSinfo">\n')
msg = 'Created for %s' % author
msg = _('Created for %(author)s') % {'author' : author}
of.write(' %s</div>\n' % msg)
of.write(' <h1 id="SiteTitle">A Peak into One Day</h1>\n')
msg = _('A Peak into One Day')
of.write(' <h1 id="SiteTitle">%s</h1>\n' % msg)
of.write(' </div>\n')
# Create navigation menu
@ -733,8 +746,7 @@ class WebCalReport(Report):
of.write(' <li>')
of.write('<a href="%s">HOME</a></li>\n' % self.home_link)
title = GrampsLocale.short_months[month]
self.display_nav_links(of, title, "ip")
self.display_nav_links(of, None, "ip")
of.write(' </ul>\n')
of.write(' </div>\n')
@ -782,14 +794,10 @@ class WebCalReport(Report):
"""
year = self.year
# if year dir doesn't exist, create it
new_dir = self.html_dir + "/%d" % year
if not os.path.isdir(new_dir):
os.mkdir(new_dir)
# Name the file, and create it
cal_file = '%d/blankyear%s' % (year, self.ext)
of = self.create_file(cal_file)
cal_fname = 'blankyear%s' % self.ext
of = self.create_file(cal_fname, "%d" % year)
# Add specific styles for "Printable Full-Year Calendar" page
mystyle = """
@ -819,7 +827,7 @@ class WebCalReport(Report):
of.write(' <div id="header">\n')
if author:
of.write(' <div id="GRAMPSinfo">\n')
msg = 'Created for %s' % author
msg = _('Created for %(author)s') % {'author' : author}
of.write(' %s</div>\n' % msg)
of.write(' <h1 id="SiteTitle">%d</h1>\n' % year)
of.write(' </div>\n')
@ -832,7 +840,7 @@ class WebCalReport(Report):
of.write(' <li>')
of.write('<a href="%s">HOME</a></li>\n' % self.home_link)
self.display_nav_links(of, 'Blank Calendar', "by")
self.display_nav_links(of, 'blankyear', "by")
of.write(' </ul>\n')
of.write(' </div>\n')
@ -860,14 +868,10 @@ class WebCalReport(Report):
"""
year = self.year
# if year dir doesn't exist, create it
new_dir = self.html_dir + "/%d/" % year
if not os.path.isdir(new_dir):
os.mkdir(new_dir)
# Name the file, and create it
cal_file = '%d/fullyear%s' % (year, self.ext)
of = self.create_file(cal_file)
cal_fname = 'fullyear%s' % (self.ext)
of = self.create_file(cal_fname, "%d" % year)
# Add specific styles for "Year At A Glance" page
mystyle = """
@ -917,9 +921,9 @@ class WebCalReport(Report):
of.write(' <div id="header">\n')
if author:
of.write(' <div id="GRAMPSinfo">\n')
msg = 'Created for %s' % author
msg = _('Created for %(author)s') % {'author' : author}
of.write(' %s</div>\n' % msg)
of.write(' <h1 id="SiteTitle">%s\n' % title)
of.write(' <h1 id="SiteTitle">%s</h1>\n' % title)
of.write(' </div>\n')
# Create navigation menu
@ -930,15 +934,15 @@ class WebCalReport(Report):
of.write(' <li>')
of.write('<a href="%s">HOME</a></li>\n' % self.home_link)
self.display_nav_links(of, 'Year Glance', "yg")
self.display_nav_links(of, 'fullyear', "yg")
of.write(' </ul>\n')
of.write(' </div>\n') # End Navigation Menu
of.write(' <p id="description">\n')
of.write(' This calendar is meant to give you access to all your data at a glance '
of.write(_(' This calendar is meant to give you access to all your data at a glance '
'compressed into one page. Clicking on a <b>red square</b> will take you to a '
'page that shows all the events for that date!\n')
'page that shows all the events for that date!\n'))
of.write(' </p>\n\n')
# Create progress bar for it
@ -1027,14 +1031,11 @@ class WebCalReport(Report):
"""
year = self.year
# if year dir doesn't exist, create it
new_dir = self.html_dir + "/%d" % year
if not os.path.isdir(new_dir):
os.mkdir(new_dir)
# Name the file, and create it
cal_file = "%d/%s%s" % (year, GrampsLocale.long_months[month], self.ext)
of = self.create_file(cal_file)
# TODO. Do we want locale month name here?
cal_fname = "%s%s" % (GrampsLocale.long_months[month], self.ext)
of = self.create_file(cal_fname, "%d" % year)
# Add specific styles to calendar head
mystyle = """
@ -1058,7 +1059,7 @@ class WebCalReport(Report):
of.write(' <div id="header">\n')
if author:
of.write(' <div id="GRAMPSinfo">\n')
msg = 'Created for %s' % author
msg = _('Created for %(author)s') % {'author' : author}
of.write(' %s</div>\n' % msg)
of.write(' <h1 id="SiteTitle">%s</h1>\n' % self.title_text)
of.write(' <h1>%d</h1>\n' % year)
@ -1072,8 +1073,7 @@ class WebCalReport(Report):
of.write(' <li>')
of.write('<a href="%s">HOME</a></li>\n' % self.home_link)
highlight = GrampsLocale.short_months[month]
self.display_nav_links(of, highlight, "wc")
self.display_nav_links(of, month, "wc")
of.write(' </ul>\n\n')
of.write(' </div>\n') # End Navigation Menu
@ -1142,9 +1142,9 @@ class WebCalReport(Report):
text = ""
elif age == 1: # person is 1, and therefore display it correctly
# TODO. Make this translatable
text = '%s, <em>%d</em> year old' % (short_name, age)
text = _('%(short_name)s, <em>%(age)d</em> year old') % {'short_name' : short_name, 'age' : age}
else:
text = '%s, <em>%d</em> years old' % (short_name, age)
text = _('%(short_name)s, <em>%(age)d</em> years old') % {'short_name' : short_name, 'age' : age}
self.add_day_item(text, year, month, day)
if self.anniv and ((self.alive and living) or not self.alive):
@ -1727,6 +1727,12 @@ def _get_short_name(person, maiden_name = None):
return ("%s %s" % (first_name, family_name)).strip()
def _has_webpage_extension(fname):
for ext in ('.html', '.htm' '.shtml', '.cgi', '.php', '.php3'):
if fname.endswith(ext):
return True
return False
#-------------------------------------------------------------------------
#
#