From 5292cd0ed913ae111fb18b118f5211ee6898c38a Mon Sep 17 00:00:00 2001 From: Kees Bakker Date: Thu, 31 Jul 2008 20:42:05 +0000 Subject: [PATCH] Fix the navigation links in WebCal * src/plugins/WebCal.py svn: r10949 --- src/plugins/WebCal.py | 142 ++++++++++++++++++++++-------------------- 1 file changed, 74 insertions(+), 68 deletions(-) diff --git a/src/plugins/WebCal.py b/src/plugins/WebCal.py index d4157aa22..2c5729b26 100644 --- a/src/plugins/WebCal.py +++ b/src/plugins/WebCal.py @@ -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), - ('fullyear', _('Year Glance'), self.fullyear), - ('blankyear', _('Blank Calendar'), self.blankyear) + (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
  • or just plain
  • + 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
  • or just plain
  • - cs = '' - if nav_text == currentsection: - cs = ' id="CurrentSection"' + if not _has_webpage_extension(url): + url += self.ext of.write(' %s
  • \n' % (cs, url, nav_text)) @@ -624,7 +629,7 @@ class WebCalReport(Report): value = _dd.display(value) msg = _('Generated by ' - 'GRAMPS on %(date)s') % { 'date' : value } + 'GRAMPS on %(date)s') % {'date' : value} author = get_researcher().get_name() if author: @@ -659,9 +664,19 @@ class WebCalReport(Report): of.write('\n') of.write('\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 = """