diff --git a/src/plugins/WebCal.py b/src/plugins/WebCal.py index b8970786f..0226bedbc 100644 --- a/src/plugins/WebCal.py +++ b/src/plugins/WebCal.py @@ -200,22 +200,33 @@ class WebCalReport(Report): self.options = options self.html_dir = menu.get_option_by_name('target').get_value() + self.title_text = menu.get_option_by_name('title').get_value() filter_option = menu.get_option_by_name('filter') self.filter = filter_option.get_filter() self.ext = menu.get_option_by_name('ext').get_value() self.copy = menu.get_option_by_name('cright').get_value() self.encoding = menu.get_option_by_name('encoding').get_value() self.css = menu.get_option_by_name('css').get_value() + self.country = menu.get_option_by_name('country').get_value() self.start_dow = menu.get_option_by_name('start_dow').get_value() - self.year = menu.get_option_by_name('year').get_value() + + self.partyear = menu.get_option_by_name('partyear').get_value() + self.multiyear = menu.get_option_by_name('multiyear').get_value() + + # self.start_year, and self.year are the same value + self.year = menu.get_option_by_name('start_year').get_value() + self.start_year = menu.get_option_by_name('start_year').get_value() + self.end_year = menu.get_option_by_name('end_year').get_value() + self.fullyear = menu.get_option_by_name('fullyear').get_value() self.blankyear = menu.get_option_by_name('blankyear').get_value() - self.surname = menu.get_option_by_name('surname').get_value() + + self.maiden_name = menu.get_option_by_name('maiden_name').get_value() + self.alive = menu.get_option_by_name('alive').get_value() self.birthday = menu.get_option_by_name('birthdays').get_value() 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().strip() self.month_notes = [menu.get_option_by_name('note_jan').get_value(), @@ -231,8 +242,26 @@ class WebCalReport(Report): menu.get_option_by_name('note_nov').get_value(), menu.get_option_by_name('note_dec').get_value()] + # identify researcher name and e-mail address + # as Narrated WebSite already does + researcher = get_researcher() + self.author = researcher.name + if self.author: + self.author = self.author.replace(',,,', '') + self.email = researcher.email + + self.mystyle = '' # set mystyle embedded styling to nothing + self.nr_up = -99 # number of directory levels up to get to self.html_dir + # arbitrary number, doesn't matter + + self.start_month = 1 # set to January, and it can change + self.end_month = 12 # set to December, this value never changes + + today = time.localtime() # set to today's date + self.today = datetime.date(today[0], today[1], today[2]) + self.warn_dir = True # Only give warning once. - self.has_arrow_gif = False # Set to True after copying to destination + self.has_arrow_gif = False # Set to True after copying to destination calendar.setfirstweekday(_dow_gramps2iso[self.start_dow]) @@ -266,22 +295,36 @@ class WebCalReport(Report): "web pages.")) self.warn_dir = False - def add_day_item(self, text, year, month, day): + def add_day_item(self, text, year, month, day, event): if day == 0: # This may happen for certain "about" dates. day = 1 # Use first day of the month month_dict = self.calendar.get(month, {}) day_list = month_dict.get(day, []) - day_list.append(text) + if month > 0: + my_date = datetime.date(year, month, day) + else: + my_date = '...' #Incomplete date as in about, circa, etc. + item = [(my_date, text, event)] + day_list.append(item) month_dict[day] = day_list self.calendar[month] = month_dict - def get_holidays(self, 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. + def add_holiday_item(self, text, year, month, day): + if day == 0: + # This may happen for certain "about" dates. + day = 1 # Use first day of the month + month_dict = self.holidays.get(month, {}) + day_list = month_dict.get(day, []) + day_list.append(text) + month_dict[day] = day_list + self.holidays[month] = month_dict - User directory is first choice if it exists, and does not use both holiday files any longer + def get_holidays(self, country = "United States"): + """ + Looks in multiple places for holidays.xml file. + the holidays file will be used first if it exists in user's plugins, otherwise, + the GRAMPS plugins will be checked. No more of having two holidays files being processed. """ holiday_file = 'holidays.xml' @@ -296,118 +339,259 @@ class WebCalReport(Report): self.process_holiday_file(holiday_full_path, country) def process_holiday_file(self, filename, country): - """ This will process a holiday file """ + """ + This will process the holidays file for the selected country. + + All holidays, except Easter, and Daylight Saving start/ stop, will be + processed from the holidays.xml file. Easter and DST will be handled by + specific mathematical formulas within this plugin ... + + "Easter" -- _easter() + "Daylight Saving Time" -- _get_dst_start_stop() + 0 = year, 1 = month, 2 = day + """ - year = self.year parser = Xml2Obj() element = parser.Parse(filename) - mycalendar = Holidays(element, country) - date = datetime.date(year, 1, 1) - while date.year == year: - holidays = mycalendar.check_date(date) + holidays_calendar = Holidays(element, country) + date = datetime.date(self.year, 1, 1) + while date.year == self.year: + event_date = time.strptime('%d/%d/%d' % (date.year, date.month, date.day), '%Y/%m/%d') + holidays = holidays_calendar.check_date(date) for text in holidays: - if text == "Easter": # TODO. Verify if this needs translation, and how - date1 = _easter(year) - self.add_day_item(text, date1[0], date1[1], date1[2]) + if text == "Easter": # TODO. Verify if this needs translation, and how + easter = _easter(self.year) + self.add_holiday_item(_("Easter"), easter[0], easter[1], easter[2]) elif text == "Daylight Saving begins": # TODO. Verify if this needs translation, and how - if Utils.xml_lang() == "en-US": - dst_start, dst_stop = _get_dst_start_stop(year, "us") - else: - dst_start, dst_stop = _getdst_start_stop(year, "eu") - self.add_day_item(text, dst_start[0], dst_start[1], dst_start[2]) - self.add_day_item(_("Daylight Saving ends"), dst_stop[0], dst_stop[1], dst_stop[2]) + if Utils.xml_lang() == "en-US": # DST for United States of America + dst_start, dst_stop = _get_dst_start_stop(self.year) + else: # DST for Europe + dst_start, dst_stop = _get_dst_start_stop(self.year, "eu") + self.add_holiday_item(_("Daylight Saving begins"), \ + dst_start[0], dst_start[1], dst_start[2]) + self.add_holiday_item(_("Daylight Saving ends"), \ + dst_stop[0], dst_stop[1], dst_stop[2]) elif text == "Daylight Saving ends": pass # end is already done above - self.add_day_item(text, date.year, date.month, date.day) + else: # not easter, or Daylight Saving Time + self.add_holiday_item(_(text), event_date[0], event_date[1], event_date[2]) date = date.fromordinal( date.toordinal() + 1) - def copy_css(self): + def copy_calendar_files(self): """ Copies all the necessary files... """ - # Copy the _CALENDARSCREEN css + # Copy the _CALENDARSCREEN stylesheet if self.css != "": - from_file = os.path.join(const.DATA_DIR, self.css) - self.copy_file(from_file, _CALENDARSCREEN, "styles") + fname = os.path.join(const.DATA_DIR, self.css) + self.copy_file(fname, _CALENDARSCREEN, "styles") # copy calendar-print stylesheet - from_file = os.path.join(const.DATA_DIR, "Web_Print-Default.css") - self.copy_file(from_file, _CALENDARPRINT, "styles") + fname = os.path.join(const.DATA_DIR, "Web_Print-Default.css") + self.copy_file(fname, _CALENDARPRINT, "styles") - # Copy GRAMPS favicon to target - from_file = os.path.join(const.IMAGE_DIR, "favicon.ico") - self.copy_file(from_file, "favicon.ico", "images") + # Copy GRAMPS favicon + fname = os.path.join(const.IMAGE_DIR, "favicon.ico") + self.copy_file(fname, "favicon.ico", "images") - # Copy arrow image if "Year At A Glance" is requested, - # and if the file exists + # Copy arrow image if "Year At A Glance" is being created if self.fullyear: - from_file = os.path.join(const.IMAGE_DIR, _ARROW_GIF) - if os.path.exists(from_file): - self.copy_file(from_file, _ARROW_GIF, "images") + fname = os.path.join(const.IMAGE_DIR, _ARROW_GIF) + if os.path.exists(fname): + self.copy_file(fname, _ARROW_GIF, "images") self.has_arrow_gif = True - def display_nav_links(self, of, currentsection, nr_up): + # copy copyright image + if 0 < self.copy < len(_CC): + fname = os.path.join(const.IMAGE_DIR, 'somerights20.gif') + self.copy_file(fname, 'somerights20.gif', 'images') + + def display_month_navs(self, of, currentsection, use_home=False): """ - 'nr_up' - number of directory levels up, started from current page, to the - root of the directory tree (i.e. to self.html_dir). + Will create and display the navigation menu bar + + use_home will produce a link to wherever you specify as a home link + + cal is one of these: + od = one_day(), wc = print_page(), yg = year_glance(), by = blank_year() """ - # Check to see if home_link will be used??? - navs = [ - (self.home_link, _('Home'), self.home_link), - (1, 1, True), - (2, 2, True), - (3, 3, True), - (4, 4, True), - (5, 5, True), - (6, 6, True), - (7, 7, True), - (8, 8, True), - (9, 9, True), - (10, 10, True), - (11, 11, True), - (12, 12, 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
%s | \n' % title) + of.write('%s | \n' % th_txt) of.write('%s | \n' % (dayclass, get_name_for_daycol(day_col))) of.write(' \n') - of.write(' \n') + # begin table body of.write(' \n') # Compute the first day to display for this month. @@ -456,7 +643,7 @@ class WebCalReport(Report): # get last month's last week for previous days in the month if month == 1: - prevmonth = calendar.monthcalendar(year-1, 12) + prevmonth = calendar.monthcalendar(year - 1, 12) else: prevmonth = calendar.monthcalendar(year, month-1) num_weeks = len(prevmonth) @@ -464,7 +651,7 @@ class WebCalReport(Report): # get next month's first week for next days in the month if month == 12: - nextmonth = calendar.monthcalendar(year+1, 1) + nextmonth = calendar.monthcalendar(year + 1, 1) else: nextmonth = calendar.monthcalendar(year, month + 1) firstweek_nextmonth = nextmonth[0] @@ -478,68 +665,76 @@ class WebCalReport(Report): dayclass = get_class_for_daycol(day_col) day = week[day_col] - if day == 0: # a day in the previous or in the next month - if week_row == 0: # day in the previous month + if day == 0: # a day in the previous or next month + if week_row == 0: # a day in the previous month specday = lastweek_prevmonth[day_col] specclass = "previous " + dayclass - elif week_row == nweeks-1: # day in the next month + elif week_row == nweeks-1: # a day in the next month specday = firstweek_nextmonth[day_col] specclass = "next " + dayclass - of.write('\n'
- % (specday, specclass))
- of.write(' %d \n'
- % specday)
+ if specclass[0] == 'p': # previous day of last month
+ of.write(' | \n' % specclass) + + # span class is used here to differentiate between previous/next days versus calendar days + of.write(' %d\n' % specday) of.write(' | \n') else: # normal day number in current month - if cal == "by": - of.write('\n' % (day, dayclass))
- of.write(' %d \n' % day)
- of.write(' | \n')
+ if cal == "by": # blank_year() doesn't need any highlighting or hyperlinks
+ of.write(' \n' % (day, dayclass))
+ of.write(' %d \n' % day)
+ of.write(' | \n')
else:
- of.write(' []:
- specclass = "highlight " + dayclass
+ holiday_list = self.holidays.get(month, {}).get(thisday.day, [])
+ bday_anniv_list = self.calendar.get(month, {}).get(thisday.day, [])
+ if (holiday_list > []) or (bday_anniv_list > []):
+ specclass = 'highlight ' + dayclass
of.write('class="%s">\n' % specclass)
- if cal == "yg": # Year at a Glance
- lng_month = GrampsLocale.long_months[month]
- shrt_month = GrampsLocale.short_months[month]
- of.write(' \n'
- % (lng_month, shrt_month, day, self.ext))
- of.write(' %d'
- ' \n' % day)
- self.indiv_date(month, day, day_list)
- else:
- # WebCal
- of.write(' %d \n' % day)
- of.write('
%d \n' % day)
+
+ # WebCal
+ elif cal == 'wc':
+ of.write(' %d \n' % day)
+
+ # year_glance() and print_page() both need this to itemize the list
+ self.one_day(of, evt_date, cal, holiday_list, bday_anniv_list)
+
+ # no holiday/ bday/ anniversary this day
+ else:
of.write('class="%s">\n' % dayclass)
of.write(' %d \n' % day)
- else:
- # Either a day of previous month, or a day of next month
+
+ # no holiday/ bday/ anniversary this month
+ else:
of.write('class="%s">\n' % dayclass)
of.write(' %d \n' % day)
- of.write(' | \n')
+ # close the day/ column
+ of.write(' \n')
+
+ # change day number
current_ord += 1
+ # close the week/ row
of.write(' \n')
- def write_header(self, of, title, nr_up, mystyle, skip_print=None):
+ def write_header(self, of, title, skip_print=None):
"""
This creates the header for the Calendars including style embedded for special purpose
- 'nr_up' - number of directory levels up, started from current page, to the
+ 'self.nr_up' - number of directory levels up, started from current page, to the
root of the directory tree (i.e. to self.html_dir).
"""
@@ -554,35 +749,33 @@ class WebCalReport(Report):
% self.encoding)
of.write(' \n')
of.write(' \n')
- author = get_researcher().get_name()
- of.write(' \n' % author)
+ of.write(' \n' % self.author)
- subdirs = ['..'] * nr_up
+ subdirs = ['..'] * self.nr_up
# Note. We use '/' here because it is a URL, not a OS dependent pathname
- fname1 = '/'.join(subdirs + ["styles"] + [_CALENDARSCREEN])
- fname2 = '/'.join(subdirs + ["styles"] + [_CALENDARPRINT])
- fname3 = '/'.join(subdirs + ["images"] + ["favicon.ico"])
+ fname1 = '/'.join(subdirs + ['styles'] + [_CALENDARSCREEN])
+ fname2 = '/'.join(subdirs + ['styles'] + [_CALENDARPRINT])
+ fname3 = '/'.join(subdirs + ['images'] + ['favicon.ico'])
- # link to calendar-screen css
- of.write(' \n' % fname1)
+ # link to _CALENDARSCREEN stylesheet
+ of.write(' \n' % fname1)
- # link to calendar-print css
+ # link to _CALENDARPRINT stylesheet
if not skip_print:
- of.write(' \n' % fname2)
+ of.write(' \n' % fname2)
- # create a link to GRAMPS favicon
- of.write(' \n' % fname3)
+ # link to GRAMPS favicon
+ of.write(' \n' % fname3)
- # Add calendar specific embedded style
- of.write(mystyle)
+ # Add calendar specific embedded style if required
+ if self.mystyle: # no extra embedded styling necessary
+ of.write(self.mystyle)
of.write('\n')
- return author
-
- def write_footer(self, of, nr_up):
+ def write_footer(self, of):
"""
Writes the footer section of the pages
- 'nr_up' - number of directory levels up, started from current page, to the
+ 'self.nr_up' - number of directory levels up, started from current page, to the
root of the directory tree (i.e. to self.html_dir).
"""
@@ -593,24 +786,18 @@ class WebCalReport(Report):
msg = _('Generated by '
'GRAMPS on %(date)s') % {'date' : value}
- author = get_researcher().get_name()
- if author:
- author = author.replace(',,,', '')
of.write('
---|