From b2b0573d3699c45052a86f8a88260612ff128275 Mon Sep 17 00:00:00 2001 From: "Rob G. Healey" Date: Mon, 26 Jan 2009 22:57:25 +0000 Subject: [PATCH] WebCal.py and NarrativeWeb.py; were sent by mistake. Watch as they are coming... Reverted back to r11481 and r11711 respectively. svn: r11740 --- src/plugins/WebCal.py | 505 +++++++++++++++++++++++------------------- 1 file changed, 271 insertions(+), 234 deletions(-) diff --git a/src/plugins/WebCal.py b/src/plugins/WebCal.py index 9fe5cfd4f..4c07dcd76 100644 --- a/src/plugins/WebCal.py +++ b/src/plugins/WebCal.py @@ -42,6 +42,7 @@ dst start/stop from Calendar.py, etc. 2008 Kees Bakker Refactoring. This is an ongoing job until this plugin is in a better shape. TODO list: + - change filename for one_day pages to yyyy/mm/dd.html (just numbers) - progress bar, rethink its usage - in year navigation, use month in link, or 'fullyear' - untangle calendar_build, it's too complex the way it is @@ -226,6 +227,7 @@ class WebCalReport(Report): 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.maiden_name = menu.get_option_by_name('maiden_name').get_value() @@ -262,6 +264,7 @@ class WebCalReport(Report): self.today = datetime.date(today[0], today[1], today[2]) self.warn_dir = True # Only give warning once. + self.imgs = [] # self.calendar is a dict; key is the month number # Each entry in the dict is also a dict; key is the day number. @@ -310,7 +313,7 @@ class WebCalReport(Report): if month > 0: try: - my_date = _make_date(year, month, day) + my_date = datetime.date(year, month, day) except ValueError: my_date = '...' else: @@ -394,11 +397,7 @@ class WebCalReport(Report): """ Copies all the necessary files """ - - # initialize imgs to fill - imgs = [] - - # Copy the screen stylesheet + # Copy the normal stylesheet if self.css != "": fname = os.path.join(const.DATA_DIR, self.css) self.copy_file(fname, self.css, "styles") @@ -407,22 +406,16 @@ class WebCalReport(Report): fname = os.path.join(const.DATA_DIR, "Web_Print-Default.css") self.copy_file(fname, "Web_Print-Default.css", "styles") - if self.css == "Web_Mainz.css": - # Copy Mainz Style Images - imgs += ["Web_Mainz_Bkgd.png", - "Web_Mainz_Header.png", - "Web_Mainz_Mid.png", - "Web_Mainz_MidLight.png", - ] - # Copy GRAMPS favicon - imgs += ["favicon.ico"] + fname = os.path.join(const.IMAGE_DIR, "favicon.ico") + self.copy_file(fname, "favicon.ico", "images") # copy copyright image if 0 < self.copy < len(_CC): - imgs += ["somerights20.gif"] + fname = os.path.join(const.IMAGE_DIR, 'somerights20.gif') + self.copy_file(fname, 'somerights20.gif', 'images') - for f in imgs: + for f in self.imgs: from_path = os.path.join(const.IMAGE_DIR, f) self.copy_file(from_path, f, "images") @@ -448,6 +441,9 @@ class WebCalReport(Report): # Add a link for year_glance() if requested navs.append(('fullyear', _('Year Glance'), self.fullyear)) + # add a link to blank_year() if requested + navs.append(('blankyear', _('Blank Calendar'), self.blankyear)) + of.write('\n\n') + # generate progress pass for "Year At A Glance" + self.progress.set_pass(_('Creating Year At A Glance calendars'), self.end_month - self.start_month) + for month in range(self.start_month, self.end_month + 1): # build the calendar @@ -938,7 +1034,7 @@ class WebCalReport(Report): of.write('\t\n') of.write('\n\n') - # increment progress bar + # increase progress bar self.progress.step() # write footer section, and close file @@ -954,12 +1050,20 @@ class WebCalReport(Report): """ # open progress meter bar - self.progress = Utils.ProgressMeter(_("Web Calendar Report"), '') + self.progress = Utils.ProgressMeter(_("Generate XHTML Calendars"), '') # get data from database for birthdays/ anniversaries # TODO. Verify that we collect correct info based on start_year self.collect_data(self.start_year) + if self.css == "Web_Mainz.css": + # Copy Mainz Style Images + self.imgs += ["Web_Mainz_Bkgd.png", + "Web_Mainz_Header.png", + "Web_Mainz_Mid.png", + "Web_Mainz_MidLight.png", + ] + # Copy all files for the calendars being created self.copy_calendar_files() @@ -992,6 +1096,10 @@ class WebCalReport(Report): # create "WebCal" calendar pages self.normal_cal(cal_year) + # create "Blank Year" calendar page + if self.blankyear: + self.blank_year(cal_year) + # create "Year At A Glance" and "One Day" calendar pages if self.fullyear: self.year_glance(cal_year) @@ -1019,6 +1127,10 @@ class WebCalReport(Report): # create "WebCal" calendar pages self.normal_cal(cal_year) + # create "Blank Year" calendar page + if self.blankyear: + self.blank_year(cal_year) + # create "Year At A Glance" if self.fullyear: self.year_glance(cal_year) @@ -1031,9 +1143,6 @@ class WebCalReport(Report): This method provides information and header/ footer to the calendar month """ - # define progress bar pass - self.progress.set_pass(_('Creating Calendars ...'), 12) - # do some error correcting if needed if self.multiyear: if self.end_year < self.start_year: @@ -1042,6 +1151,9 @@ class WebCalReport(Report): nr_up = 1 # Number of directory levels up to get to self.html_dir / root + # generate progress pass for "WebCal" + self.progress.set_pass(_('Creating WebCal calendars'), self.end_month - self.start_month) + for month in range(self.start_month, self.end_month + 1): # Name the file, and create it @@ -1095,16 +1207,18 @@ class WebCalReport(Report): if birth_ref: birth_event = self.database.get_event_from_handle(birth_ref.ref) birth_date = birth_event.get_date_object() + death_ref = person.get_death_ref() + death_date = None + if death_ref: + death_event = self.database.get_event_from_handle(death_ref.ref) + death_date = death_event.get_date_object() - # determine birthday information??? - if self.birthday and birth_date is not None: - - # determine if birthdadate is a valid date??? - complete_date = False - if birth_date.is_valid(): - complete_date = True - if complete_date: + # if person is dead, STOP! Nothing further to do + if death_date == None: + living = probably_alive(person, self.database, _make_date(this_year, 1, 1), 0) + # add birthday if requested + if self.birthday and birth_date != None and ((self.alive and living) or not self.alive): year = birth_date.get_year() month = birth_date.get_month() day = birth_date.get_day() @@ -1129,50 +1243,48 @@ class WebCalReport(Report): father_name = father.get_primary_name() father_lastname = _get_regular_surname(sex, father_name) short_name = _get_short_name(person, father_lastname) - alive = probably_alive(person, self.database, _make_date(this_year, month, day)) + # Huh? Why translate this? text = _('%(short_name)s') % {'short_name' : short_name} - if ((self.alive and alive) or not self.alive): - self.add_day_item(text, year, month, day, 'Birthday') + self.add_day_item(text, year, month, day, 'birthday') - # add anniversary if requested - if self.anniv: - for fhandle in family_list: - fam = self.database.get_family_from_handle(fhandle) - father_handle = fam.get_father_handle() - mother_handle = fam.get_mother_handle() - if father_handle == person.get_handle(): - spouse_handle = mother_handle - else: - continue # with next person if this was the marriage event - if spouse_handle: - spouse = self.database.get_person_from_handle(spouse_handle) - if spouse: - spouse_name = _get_short_name(spouse) - short_name = _get_short_name(person) + # add anniversary if requested + if self.anniv and ((self.alive and living) or not self.alive): + for fhandle in family_list: + fam = self.database.get_family_from_handle(fhandle) + father_handle = fam.get_father_handle() + mother_handle = fam.get_mother_handle() + if father_handle == person.get_handle(): + spouse_handle = mother_handle + else: + continue # with next person if this was the marriage event + if spouse_handle: + spouse = self.database.get_person_from_handle(spouse_handle) + if spouse: + death_ref = spouse.get_death_ref() + death_date = None + if death_ref: + death_event = self.database.get_event_from_handle(death_ref.ref) + death_date = death_event.get_date_object() - are_married = get_marrital_status(fam, self.database) - if are_married is not None: - for event_ref in fam.get_event_ref_list(): - event = self.database.get_event_from_handle(event_ref.ref) - event_obj = event.get_date_object() - year = event_obj.get_year() - month = event_obj.get_month() - day = event_obj.get_day() - - # determine if anniversary date is a valid date??? - complete_date = False - if event_obj.get_valid(): - complete_date = True - if complete_date: - - text = _('%(spouse)s and %(person)s') % { - 'spouse' : spouse_name, - 'person' : short_name} - - alive1 = probably_alive(person, self.database, _make_date(this_year, month, day)) - alive2 = probably_alive(spouse, self.database, _make_date(this_year, month, day)) - if ((self.alive and alive1 and alive2) or not self.alive): - self.add_day_item(text, year, month, day, 'Anniversary') + # if spouse is dead, STOP! Nothing more to do! + if death_date == None: + spouse_name = _get_short_name(spouse) + short_name = _get_short_name(person) + if self.alive: + if not probably_alive(spouse, self.database, _make_date(this_year, 1, 1), 0): + continue + are_married = _get_marrital_status(fam, self.database) + if are_married is not None: + for event_ref in fam.get_event_ref_list(): + event = self.database.get_event_from_handle(event_ref.ref) + event_obj = event.get_date_object() + year = event_obj.get_year() + month = event_obj.get_month() + day = event_obj.get_day() + text = _('%(spouse)s and %(person)s') % { + 'spouse' : spouse_name, + 'person' : short_name} + self.add_day_item(text, year, month, day, 'anniversary') #------------------------------------------------------------------------ # @@ -1287,6 +1399,10 @@ class WebCalOptions(MenuReportOptions): fullyear.set_help(_('Whether to create A one-page mini calendar with dates highlighted')) menu.add_option(category_name, 'fullyear', fullyear) + blankyear = BooleanOption(_('Create "Printable Blank" Calendar(s)'), False) + blankyear.set_help(_('Whether to create A Full Year Printable calendar')) + menu.add_option(category_name, 'blankyear', blankyear) + country = EnumeratedListOption(_('Country for holidays'), 0 ) for index, item in enumerate(_COUNTRIES): country.add_item(index, item) @@ -1782,6 +1898,12 @@ def _get_marrital_status(family, db): are_married = None return are_married +def _has_webpage_extension(fname): + for ext in ('.html', '.htm' '.shtml', '.cgi', '.php', '.php3'): + if fname.endswith(ext): + return True + return False + # Simple utility list to convert Gramps day-of-week numbering to calendar.firstweekday numbering _dow_gramps2iso = [ -1, calendar.SUNDAY, calendar.MONDAY, calendar.TUESDAY, calendar.WEDNESDAY, calendar.THURSDAY, calendar.FRIDAY, calendar.SATURDAY ] @@ -1801,91 +1923,6 @@ def _get_long_month_name(month): def _get_short_month_name(month): return _shrt_month[month] -def fill_day_list(event_date, holiday_list, bday_anniv_list): - """ - Will fill day_list and return it to its caller one_day() - - holiday_list, or bday_anniv_list -- will always have something in it... - - event_date -- date for this day_list - - 'day_list' - a combination of both dictionaries to be able to create one day - nyears, date, text, event --- are necessary for figuring the age or years married - for each year being created... - """ - - # initialize day_list - day_list = [] - - # holiday on this day - if holiday_list > []: - - # will force holidays to be first in the list - nyears = 0 - - for p in holiday_list: - for line in p.splitlines(): - day_list.append((nyears, event_date, line, _('Holiday'))) - - # birthday/ anniversary on this day - if bday_anniv_list > []: - for date, text, event in bday_anniv_list: - - # '...' signifies an incomplete date for an event. See add_day_item() - txt_str = None - if date != '...': - years = event_date.year - date.get_year() - - # a birthday - if event == 'Birthday': - - if years is 1: - txt_str = _('%(person)s, %(age)d year old') % { - 'person' : text, - 'age' : years} - elif years > 1: - txt_str = _('%(person)s, %(age)d years old') % { - 'person' : text, - 'age' : years} - - # an anniversary - elif event == 'Anniversary': - - txt_str = _('%(couple)s, %(years)d year anniversary') % { - 'couple' : text, - 'years' : years} - txt_str = '%s' % txt_str - - if txt_str is not None: - day_list.append((years, date, txt_str, event)) - - # if there is more than one event on any given date, sort them based on years - # for birthdays and anniversaries. - # holidays will always appear first in the list. - if len(day_list) > 1: - day_list.sort() - - return day_list - -def get_marrital_status(family, db): - """ - Returns the marital status of two people, a couple - - are_married will either be the marriage event or None if not married anymore - """ - - are_married = None - for event_ref in family.get_event_ref_list(): - event = db.get_event_from_handle(event_ref.ref) - if event.type in [gen.lib.EventType.MARRIAGE, - gen.lib.EventType.MARR_ALT]: - are_married = event - elif event.type in [gen.lib.EventType.DIVORCE, - gen.lib.EventType.ANNULMENT, - gen.lib.EventType.DIV_FILING]: - are_married = None - return are_married - #------------------------------------------------------------------------- # #