From 8c2dc12d62952bb0e8e14448e9cf63fc4fc6c53c Mon Sep 17 00:00:00 2001 From: Kees Bakker Date: Tue, 29 Jul 2008 21:23:44 +0000 Subject: [PATCH] Move some functions outside the class. Eliminate return value of six_weeks() and calender_build(). _easter() now gets the year as argument. Note. There is still an off-by-one error with the days. * src/plugins/WebCal.py svn: r10947 --- src/plugins/WebCal.py | 163 ++++++++++++++++++++---------------------- 1 file changed, 79 insertions(+), 84 deletions(-) diff --git a/src/plugins/WebCal.py b/src/plugins/WebCal.py index feb4838d4..391d43285 100644 --- a/src/plugins/WebCal.py +++ b/src/plugins/WebCal.py @@ -76,7 +76,6 @@ log = logging.getLogger(".WebPage") #------------------------------------------------------------------------ import gen.lib import const -import BaseDoc from GrampsCfg import get_researcher from PluginUtils import PluginManager from ReportBase import (Report, ReportUtils, MenuReportOptions, CATEGORY_WEB, @@ -262,31 +261,6 @@ class WebCalReport(Report): "web pages.")) self.warn_dir = False - # code snippets for Easter and Daylight saving start/ stop - # are borrowed from Calendar.py - - def easter(self): - """ - 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 - i = c - c / 4 - (c - k) / 3 + 19 * n + 15 - i = i - 30 * (i / 30) - i = i - (i / 28) * (1 - (i / 28) * (29 / (i + 1)) - * ((21 - n) / 11)) - j = year + year / 4 + i + 2 - c + c / 4 - j = j - 7 * (j / 7) - l = i - j - month = 3 + (l + 40) / 44 - day = l + 28 - 31 * (month / 4) - return (year, month, day) - def dst(self, area="us"): """ Return Daylight Saving Time start/stop in a given area ("us", "eu"). @@ -305,35 +279,6 @@ class WebCalReport(Report): stop = (year, 10, (31 - (math.floor(year * 5 / 4) + 1) % 7)) # Oct return (start, stop) - def get_short_name(self, person, maiden_name = None): - """ Return person's name, unless maiden_name given, unless married_name listed. """ - # Get all of a person's names: - primary_name = person.get_primary_name() - married_name = None - names = [primary_name] + person.get_alternate_names() - for n in names: - if int(n.get_type()) == gen.lib.NameType.MARRIED: - married_name = n - # Now, decide which to use: - if maiden_name is not None: - if married_name is not None: - first_name, family_name = married_name.get_first_name(), married_name.get_surname() - call_name = married_name.get_call_name() - else: - first_name, family_name = primary_name.get_first_name(), maiden_name - call_name = primary_name.get_call_name() - else: - first_name, family_name = primary_name.get_first_name(), primary_name.get_surname() - call_name = primary_name.get_call_name() - # If they have a nickname use it - if call_name is not None and call_name.strip() != "": - first_name = call_name.strip() - else: # else just get the first name: - first_name = first_name.strip() - if " " in first_name: - first_name, rest = first_name.split(" ", 1) # just one split max - return ("%s %s" % (first_name, family_name)).strip() - def add_day_item(self, text, year, month, day): month_dict = self.calendar.get(month, {}) day_list = month_dict.get(day, []) @@ -349,7 +294,6 @@ 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) @@ -373,7 +317,7 @@ class WebCalReport(Report): holidays = mycalendar.check_date( date ) for text in holidays: if text == "Easter": - date1 = self.easter() + date1 = _easter(year) self.add_day_item(text, date1[0], date1[1], date1[2]) elif text == "Daylight Saving begins": if Utils.xml_lang() == "en-US": @@ -425,7 +369,7 @@ class WebCalReport(Report): ('June', _('Jun'), True), ('July', _('Jul'), True), ('August', _('Aug'), True), - ('September', _('Sep'), True), + ('September', _('Sep'), True), ('October', _('Oct'), True), ('November', _('Nov'), True), ('December', _('Dec'), True), @@ -442,17 +386,14 @@ class WebCalReport(Report): else: url = _subdirs("wc", new_dir, url_fname) url += self.ext - self.display_nav_link(of, url, 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 + # Figure out if we need
  • or just plain
  • + cs = False + if nav_text == currentsection: + cs = True - cs = cs and ' id="CurrentSection"' or '' - of.write(' %s
  • \n' - % (cs, url, title)) + cs = cs and ' id="CurrentSection"' or '' + of.write(' %s\n' % (cs, url, nav_text)) def calendar_build(self, of, cal, month): """ @@ -553,8 +494,8 @@ class WebCalReport(Report): of.write(' [])): + list_ = self.calendar.get(month, {}).get(thisday.day, []) + if list_ > []: specclass = "highlight " + dayclass of.write('class="%s">\n' % specclass) if cal == "yg": # Year at a Glance @@ -565,13 +506,13 @@ class WebCalReport(Report): of.write('
    %d' '
    \n' % day) self.indiv_date(month, day, list_) - else: # WebCal + else: + # WebCal of.write('
    %d' '
    \n' % day) of.write('