diff --git a/src/plugins/WebCal.py b/src/plugins/WebCal.py index feb4838d4..e2422442b 100644 --- a/src/plugins/WebCal.py +++ b/src/plugins/WebCal.py @@ -216,6 +216,7 @@ class WebCalReport(Report): self.anniv = menu.get_option_by_name('anniversaries').get_value() self.title_text = menu.get_option_by_name('title').get_value() self.home_link = menu.get_option_by_name('home_link').get_value() + self.use_home = self.home_link self.month_notes = [menu.get_option_by_name('note_jan').get_value(), menu.get_option_by_name('note_feb').get_value(), @@ -265,14 +266,14 @@ class WebCalReport(Report): # code snippets for Easter and Daylight saving start/ stop # are borrowed from Calendar.py - def easter(self): + def easter(self, year): """ Computes the year/month/day of easter. Based on work by J.-M. Oudin (1940) and is reprinted in the "Explanatory Supplement to the Astronomical Almanac", ed. P. K. Seidelmann (1992). Note: Ash Wednesday is 46 days before Easter Sunday. """ - year = self.year + c = year / 100 n = year - 19 * (year / 19) k = (c - 17) / 25 @@ -287,12 +288,12 @@ class WebCalReport(Report): day = l + 28 - 31 * (month / 4) return (year, month, day) - def dst(self, area="us"): + def dst(self, year, area="us"): """ Return Daylight Saving Time start/stop in a given area ("us", "eu"). US calculation valid 1976-2099; EU 1996-2099 """ - year = self.year + if area == "us": if year > 2006: start = (year, 3, 14 - (math.floor(1 + year * 5 / 4) % 7)) # March @@ -341,7 +342,7 @@ class WebCalReport(Report): month_dict[day] = day_list self.calendar[month] = month_dict - def get_holidays(self, country = "United States"): + def get_holidays(self, year, country = "United States"): """ Looks in multiple places for holidays.xml files the holidays file will be used first if it exists in user's plugins, else the GRAMPS plugins will be checked. No more of having duel holidays files being read. @@ -349,22 +350,20 @@ class WebCalReport(Report): User directory is first choice if it exists, and does not use both holiday files any longer """ - year = self.year holiday_file = 'holidays.xml' holiday_full_path = "" fname1 = os.path.join(const.USER_PLUGINS, holiday_file) fname2 = os.path.join(const.PLUGINS_DIR, holiday_file) - if os.path.exists(fname1): + if os.path.isfile(fname1): holiday_full_path = fname1 - elif os.path.exists(fname2): + elif os.path.isfile(fname2): holiday_full_path = fname2 if holiday_full_path != "": - self.process_holiday_file(holiday_full_path, country) + self.process_holiday_file(self.year, holiday_full_path, country) - def process_holiday_file(self, filename, country): + def process_holiday_file(self, year, filename, country): """ This will process a holiday file """ - year = self.year parser = Xml2Obj() element = parser.Parse(filename) mycalendar = Holidays(element, country) @@ -373,13 +372,13 @@ class WebCalReport(Report): holidays = mycalendar.check_date( date ) for text in holidays: if text == "Easter": - date1 = self.easter() + date1 = self.easter(self.year) self.add_day_item(text, date1[0], date1[1], date1[2]) elif text == "Daylight Saving begins": if Utils.xml_lang() == "en-US": - date2 = self.dst("us") + date2 = self.dst(self.year, "us") else: - date2 = self.dst("eu") + date2 = self.dst(self.year, "eu") dst_start = date2[0] dst_stop = date2[1] self.add_day_item(text, dst_start[0], dst_start[1], dst_start[2]) @@ -454,13 +453,11 @@ class WebCalReport(Report): of.write(' %s\n' % (cs, url, title)) - def calendar_build(self, of, cal, month): + def calendar_build(self, of, cal, year, month): """ This does the work of building the calendar """ - year = self.year - # Begin calendar head title = GrampsLocale.long_months[month] of.write('\n' % title) @@ -540,7 +537,7 @@ class WebCalReport(Report): specclass = "next " + dayclass of.write(' \n' % (specday, specclass)) - of.write('
%d
\n' + of.write(' %d\n' % specday) of.write(' \n') else: # day number @@ -564,18 +561,12 @@ class WebCalReport(Report): % (lng_month, shrt_month, day, self.ext)) of.write('
%d' '
\n' % day) - self.indiv_date(month, day, list_) + self.indiv_date(self.year, month, day, list_) else: # WebCal of.write('
%d' '
\n' % day) of.write(' \n') + self.write_events(of, list_) else: of.write('class="%s">\n' % dayclass) of.write('
%d
\n' @@ -588,11 +579,9 @@ class WebCalReport(Report): of.write(' \n') # Complete six weeks for proper styling - of = self.six_weeks(of, nweeks) + self.six_weeks(of, nweeks) - return of - - def write_header(self, of, title, cal, mystyle): + def write_header(self, of, title, up, mystyle): """ This creates the header for the Calendars iincluding style embedded for special purpose """ @@ -612,27 +601,23 @@ class WebCalReport(Report): author = get_researcher().get_name() of.write(' \n' % author) - if ((cal == "yg") or (cal == "by")): # year glance and blank_year - # have same directory levels - fname1 = _subdirs("yg", "styles", _CALENDARSCREEN) - fname2 = _subdirs("yg", "styles", _CALENDARPRINT) - fname3 = _subdirs("yg", "images", "favicon.ico") - elif cal == "ip": - fname1 = _subdirs("ip", "styles", _CALENDARSCREEN) - fname2 = _subdirs("ip", "styles", _CALENDARPRINT) - fname3 = _subdirs("ip", "images", "favicon.ico") + if up: # year_glance(), print_page(), and blank_year() + # have same directory levels + fname1 = _subdirs(True, "styles", _CALENDARSCREEN) + fname2 = _subdirs(True, "styles", _CALENDARPRINT) + fname3 = _subdirs(True, "images", "favicon.ico") else: - fname1 = _subdirs("wc", "styles", _CALENDARSCREEN) - fname2 = _subdirs("wc", "styles", _CALENDARPRINT) - fname3 = _subdirs("wc", "images", "favicon.ico") + fname1 = _subdirs(False, "styles", _CALENDARSCREEN) + fname2 = _subdirs(False, "styles", _CALENDARPRINT) + fname3 = _subdirs(False, "images", "favicon.ico") # link to calendar-screen css - of.write(' \n' % fname1) + of.write(' \n' % fname1) # link to calendar-print css - if not cal == "yg": - of.write(' \n' - % fname2) + of.write(' \n' % fname2) # create a link to GRAMPS favicon of.write(' \n' % fname3) @@ -641,9 +626,52 @@ class WebCalReport(Report): of.write(mystyle) of.write('\n') - return (of, author) + def display_nav_links(self, of, _currentsection, up): - def write_footer(self, of, cal): + # Check to see if home_link will be used??? + navs = [ + (self.home_link, _('Home'), self.use_home), + ('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) + ] + for url_fname, nav_text, cond in navs: + if cond: + new_dir = str(self.year) + if up: + fname = _subdirs(True, new_dir, url_fname) + else: + fname = _subdirs(False, new_dir, url_fname) + use_ext = True + for etype in ['.html', '.htm', '.shtml', '.php', '.php3', '.cgi']: + if etype in fname: + use_ext = False + if use_ext: + fname += self.ext + self.display_nav_link(of, fname, nav_text, _currentsection) + + def display_nav_link(self, of, url, title, currentsection): + # Figure out if we need
  • of just plain
  • + cs = False + if title == currentsection: + cs = True + + cs = cs and ' id="CurrentSection"' or '' + of.write(' %s
  • \n' + % (cs, url, title)) + + def write_footer(self, of, up): """ Writes the footer section of the pages """ @@ -662,22 +690,16 @@ class WebCalReport(Report): of.write('

    %s

    \n' % msg) # copyright license - if cal == "yg" or cal == "by": - to_urldir = os.path.join("yg", "images") - to_dir = os.path.join("yg", "images") - elif cal == "ip": - to_urldir = os.path.join("ip", "images") - to_dir = os.path.join("ip", "images") + if up: + fname = _subdirs(True, "images", "somerights20.gif") else: - to_urldir = os.path.join("wc", "images") - to_dir = os.path.join("wc", "images") + fname = _subdirs(False, "images", "somerights20.gif") if self.copy > 0 and self.copy < len(_CC): text = _CC[self.copy] - fname = os.path.join(to_urldir, "somerights20.gif") text = text % {'gif_fname' : fname} from_file = os.path.join(const.IMAGE_DIR, "somerights20.gif") - self.copy_file(from_file, "somerights20.gif", to_dir) + self.copy_file(from_file, "somerights20.gif", "images") else: text = "© %s %s" % (time.localtime()[0], author) of.write(' \n' % text) @@ -688,6 +710,46 @@ class WebCalReport(Report): of.write('\n') of.write('\n') + def write_events(self, of, list_): + """ + Display Events list + """ + + for p in list_: + lines = p.count("\n") + 1 # lines in the text + for line in p.split("\n"): + of.write('
  • ') + of.write(line) + of.write('
  • \n') + of.write(' \n') + + def create_dirs(self, year): + """ + Will create all directories for WebCal(), year_glance(), blank_year() + """ + + # create styles directory + new_dir = self.html_dir + "/styles" + if not os.path.isdir(new_dir): + os.makedirs(new_dir) + + # create images directory + new_dir = self.html_dir + "/images" + if not os.path.isdir(new_dir): + os.makedirs(new_dir) + + # create year/monthly directories + dest_dir = self.html_dir + '%d/%s' % (year, GrampsLocale.long_months[1]) + if not os.path.isdir(dest_dir): + os.makedirs(dest_dir) + + # start month at February since January is already created by above directory tree + for month in range(2, 13): + lng_month = GrampsLocale.long_months[month] + new_dir = self.html_dir + '/%d/%s' % (year, lng_month) + if not os.path.isdir(new_dir): + os.mkdir(new_dir) + 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') @@ -696,96 +758,22 @@ class WebCalReport(Report): def close_file(self, of): of.close() - def indiv_date(self, month, day_num, list_): + def indiv_date(self, year, month, day, list_): """ This method creates the indiv pages for "Year At A Glance" """ - # 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") + of = self.calendar_topper('ip', year, month, day) - # Create names for long and short month names - lng_month = GrampsLocale.long_months[month] - shrt_month = GrampsLocale.short_months[month] + of.write('

    %s %d, %d

    \n' + % (GrampsLocale.long_months[month], day, year)) - new_dir = self.html_dir + "/%d/%s" % (year, lng_month) - if not os.path.isdir(new_dir): - os.mkdir(new_dir) + of.write('