From c8fa3637089d3088055a6c6086b7dda7f212b4c1 Mon Sep 17 00:00:00 2001 From: "Rob G. Healey" Date: Sun, 21 Jun 2009 03:25:28 +0000 Subject: [PATCH] Large sized cleanup of NarrativeWeb, and some minor work on Web_Visually.css. There is still more work to be done on NarrativeWeb, but this commit was getting too big already. svn: r12689 --- src/data/Web_Visually.css | 1 - src/plugins/webreport/NarrativeWeb.py | 1249 +++++++++++++------------ 2 files changed, 658 insertions(+), 592 deletions(-) diff --git a/src/data/Web_Visually.css b/src/data/Web_Visually.css index 339bff477..43aa0a30c 100644 --- a/src/data/Web_Visually.css +++ b/src/data/Web_Visually.css @@ -221,7 +221,6 @@ p#user_header { color:#6AF364; margin:0; padding:.2em 0 .6em 20px; - background-color:#542; } /* Footer diff --git a/src/plugins/webreport/NarrativeWeb.py b/src/plugins/webreport/NarrativeWeb.py index c84c2c7f8..d5b039183 100644 --- a/src/plugins/webreport/NarrativeWeb.py +++ b/src/plugins/webreport/NarrativeWeb.py @@ -118,10 +118,14 @@ fullclear = Html('div', class_='fullclear', inline=True) _NARRATIVESCREEN = 'narrative-screen.css' _NARRATIVEPRINT = 'narrative-print.css' -# variables for alphabet_navigation +# variables for alphabet_navigation() _PERSON = 0 _PLACE = 1 +# sort_birth_order() +_FAMILY = 0 +_PARENTS = 1 + # Web page filename extensions _WEB_EXT = ['.html', '.htm', '.shtml', '.php', '.php3', '.cgi'] @@ -341,6 +345,7 @@ class BasePage(object): note_text = note.get() if note_text: user_footer = Html('div', id='user_footer') + footer += user_footer # styled notes htmlnotetext = self.styled_note(note.get_styledtext(), @@ -350,7 +355,6 @@ class BasePage(object): else: text = Html('p', note_text) user_footer += text - footer += user_footer value = _dd.display(date.Today()) msg = _('Generated by ' @@ -363,13 +367,12 @@ class BasePage(object): home_person = db.get_default_person() if home_person: home_person_url = self.report.build_url_fname_html(home_person.handle, 'ppl', self.up) - home_person_name = home_person.get_primary_name().get_regular_name() - msg += _('Created for %s') % ( - home_person_url, home_person_name - ) + home_person_name = self.get_name(home_person) + msg += _(' Created for %s') % ( + home_person_url, home_person_name) # create date - createdate = Html('p', msg, id='createdate') + footer += Html('p', msg, id='createdate') # get copyright license for all pages copy_nr = self.report.copyright @@ -386,11 +389,10 @@ class BasePage(object): fname = '/'.join(["images", "somerights20.gif"]) url = self.report.build_url_fname(fname, None, self.up) text = _CC[copy_nr] % {'gif_fname' : url} - copyrightlicense = Html('p', text, id='copyright') + footer += Html('p', text, id='copyright') - # bring all footer pieces together # add clear line for proper styling - footer += (createdate, copyrightlicense, fullclear) + footer += fullclear # return footer to its caller return footer @@ -549,45 +551,46 @@ class BasePage(object): db = self.report.database if not photolist or not self.use_gallery: - return + return None photo_handle = photolist[0].get_reference_handle() photo = db.get_object_from_handle(photo_handle) mime_type = photo.get_mime_type() # begin snapshot division - snapshot = Html('div', class_='snapshot') + with Html('div', class_='snapshot') as snapshot: - if mime_type: - try: - lnkref = (self.report.cur_fname, self.page_title, self.gid) - self.report.add_lnkref_to_photo(photo, lnkref) - real_path, newpath = self.report.prepare_copy_media(photo) + if mime_type: + try: + lnkref = (self.report.cur_fname, self.page_title, self.gid) + self.report.add_lnkref_to_photo(photo, lnkref) + real_path, newpath = self.report.prepare_copy_media(photo) - # TODO. Check if build_url_fname can be used. - newpath = '/'.join(['..']*3 + [newpath]) + # TODO. Check if build_url_fname can be used. + newpath = '/'.join(['..']*3 + [newpath]) + + # begin hyperlink + # description is given only for the purpose of the alt tag in img element + snapshot += self.media_link(photo_handle, newpath, '', up=True) + + except (IOError, OSError), msg: + WarningDialog(_("Could not add photo to page"), str(msg)) + else: + + # get media description + descr = photo.get_description() # begin hyperlink - hyper = self.media_link(photo_handle, newpath, '', up=True) + snapshot += self.doc_link(photo_handle, descr, up=True) - except (IOError, OSError), msg: - WarningDialog(_("Could not add photo to page"), str(msg)) - else: - - # begin hyperlink - hyper = self.doc_link(photo_handle, descr, up=True) - - lnk = (self.report.cur_fname, self.page_title, self.gid) - # FIXME. Is it OK to add to the photo_list of report? - photo_list = self.report.photo_list - if photo_handle in photo_list: - if lnk not in photo_list[photo_handle]: - photo_list[photo_handle].append(lnk) - else: - photo_list[photo_handle] = [lnk] - - # add hyperlink to snapshot division - snapshot += hyper + lnk = (self.report.cur_fname, self.page_title, self.gid) + # FIXME. Is it OK to add to the photo_list of report? + photo_list = self.report.photo_list + if photo_handle in photo_list: + if lnk not in photo_list[photo_handle]: + photo_list[photo_handle].append(lnk) + else: + photo_list[photo_handle] = [lnk] # return snapshot division to its callers return snapshot @@ -796,49 +799,55 @@ class BasePage(object): if not handlelist: return None - # begin references division - sect_references = Html('div', id='references', class_='subsection') + # begin references division and title + with Html('div', class_='subsection', id='references') as section: + section += Html('h4', _('References'), inline=True) - # section title - sect_title = Html('h4', _('References'), inline=True) - sect_references += sect_title - ordered = Html('ol') - sortlist = sorted(handlelist, key=lambda x:locale.strxfrm(x[1])) + ordered = Html('ol') + section += ordered + sortlist = sorted(handlelist, key=lambda x:locale.strxfrm(x[1])) - for (path, name, gid) in sortlist: - list = Html('li') + for (path, name, gid) in sortlist: + list = Html('li') + ordered += list - # Note. 'path' already has a filename extension - url = self.report.build_url_fname(path, None, self.up) - hyper = self.person_link(url, name, gid) - list += hyper - ordered += list - sect_references += ordered + # Note. 'path' already has a filename extension + url = self.report.build_url_fname(path, None, self.up) + list += self.person_link(url, name, None, gid) # return references division to its caller - return sect_references + return section - def person_link(self, url, name, gid=None, thumbnailUrl=None): + def person_link(self, url, person, name_style, gid=None, thumbnailUrl=None): """ creates a hyperlink for a person + namestyle = False -- first and suffix only + = True -- name displayed in name_format variable + = None -- person is name """ + # see above for explanation + if name_style: + person_name = self.get_name(person) + elif name_style == False: + person_name = _get_short_name(person.gender, person.primary_name) + elif name_style == None: # abnormal specialty situation + person_name = person + # 1. start building link to image or person hyper = Html('a', href=url) # 2. insert thumbnail if there is one, otherwise insert class = "noThumb" if thumbnailUrl: hyper += (Html('span', class_="thumbnail") + - Html('img', src= thumbnailUrl, - alt = "Image of " + name) + Html('img', src= thumbnailUrl, alt = "Image of " + person_name) ) else: # for proper spacing, force a new line after hyperlink url - #hyper.attr = 'href="%s" class= "noThumb"' % url hyper.attr += ' class= "noThumb"' # 3. insert the person's name - hyper += name + hyper += person_name # 3. insert gramps id if requested and available if not self.noid and gid: @@ -851,17 +860,18 @@ class BasePage(object): def media_link(self, handle, img_url, name, up, usedescr=True): url = self.report.build_url_fname_html(handle, 'img', up) - thumbnail = Html('div', class_='thumbnail') + # begin thumbnail division + with Html('div', class_='thumbnail') as thumbnail: - # begin hyperlink - hyper = (Html('a', href=url, title=name) + - Html('img', src=img_url, alt=name) + - (Html('p', inline=True) + - html_escape(name) if usedescr else ' [Untitled] ' - ) - ) - # add hyperlink and description to thumbnail division - thumbnail += hyper + # begin hyperlink + hyper = (Html('a', href=url, title=name) + + Html('img', src=img_url, alt=name) + + (Html('p', inline=True) + + html_escape(name) if usedescr else ' [Untitled] ' + ) + ) + # add hyperlink and description to thumbnail division + thumbnail += hyper # return thumbnail division to its callers return thumbnail @@ -938,7 +948,7 @@ class IndividualListPage(BasePage): section += Html('p', msg, id='description') # add alphabet navigation after page msg - alpha_nav = alphabet_navigation(report.database, person_handle_list, _PERSON) + alpha_nav = alphabet_navigation(db, person_handle_list, _PERSON) if alpha_nav is not None: section += alpha_nav @@ -1015,10 +1025,9 @@ class IndividualListPage(BasePage): first = False # firstname column tcell = Html('td', class_='ColumnName') - url = self.report.build_url_fname_html(person.handle, 'ppl') - first_suffix = _get_short_name(person.gender, person.primary_name) - tcell += self.person_link(url, first_suffix, person.gramps_id) trow += tcell + url = self.report.build_url_fname_html(person.handle, 'ppl') + tcell += self.person_link(url, person, False, person.gramps_id) # birth column if showbirth: @@ -1065,7 +1074,7 @@ class IndividualListPage(BasePage): tcell += ', ' if partner_handle in report_handle_list: url = self.report.build_url_fname_html(partner_handle, 'ppl') - tcell += self.person_link(url, partner_name) + tcell += self.person_link(url, partner, name_style=True) else: tcell += partner_name first_family = False @@ -1173,8 +1182,7 @@ class SurnamePage(BasePage): trow = Html('tr') tcell = Html('td', class_='ColumnName') url = self.report.build_url_fname_html(person.handle, 'ppl', True) - first_suffix = _get_short_name(person.gender, person.primary_name) - tcell += self.person_link(url, first_suffix, person.gramps_id) + tcell += self.person_link(url, person, False, person.gramps_id) trow += tcell # birth column @@ -1221,9 +1229,8 @@ class SurnamePage(BasePage): tcell += ',' if partner_handle in report_handle_list: url = self.report.build_url_fname_html( - partner_handle, - 'ppl', True) - tcell += self.person_link(url, partner_name) + partner_handle, 'ppl', True) + tcell += self.person_link(url, partner, name_style=True) else: tcell += partner_name else: @@ -1277,176 +1284,185 @@ class PlaceListPage(BasePage): def __init__(self, report, title, place_handles, src_list): BasePage.__init__(self, report, title) self.src_list = src_list # TODO verify that this is correct + db = report.database of = self.report.create_file("places") - placeslist, body = self.write_header(_('Places')) + placelistpage, body = self.write_header(_('Places')) # begin places division - sect_places = Html('div', id='Places', class_='content') - body += (sect_places, fullclear) + with Html('div', class_='content', id='Places') as section: + body += section - msg = _("This page contains an index of all the places in the " - "database, sorted by their title. Clicking on a place’s " - "title will take you to that place’s page.") - descr= Html('p', msg, id='description') - sect_places += descr + msg = _("This page contains an index of all the places in the " + "database, sorted by their title. Clicking on a place’s " + "title will take you to that place’s page.") + section += Html('p', msg, id='description') - # begin alphabetic navigation - alpha_nav = alphabet_navigation(report.database, place_handles, _PLACE) - sect_places += alpha_nav + # begin alphabetic navigation + alpha_nav = alphabet_navigation(db, place_handles, _PLACE) + if alpha_nav is not None: + section += alpha_nav - # begin places table and table head - places_table = Html('table', class_='infolist placelist') - sect_places += places_table + # begin places table and table head + with Html('table', class_='infolist placelist') as table: + section += table - # begin table head - thead = Html('thead') - places_table += thead + # begin table head + thead = Html('thead') + table += thead - tabrow = Html('tr') + ( - Html('th', _('Letter'), class_='ColumnLetter', inline=True), - Html('th', _('Name'), class_='ColumnName', inline=True) - ) - thead += tabrow - - sort = Sort.Sort(report.database) - handle_list = sorted(place_handles, sort.by_place_title) - last_letter = '' - - # begin table body - tbody = Html('tbody') - places_table += tbody - - for handle in handle_list: - place = report.database.get_place_from_handle(handle) - place_title = ReportUtils.place_name(report.database, handle) - - if not place_title: - continue - - letter = normalize('NFKC', place_title)[0].upper() - # See : http://www.gramps-project.org/bugs/view.php?id=2933 - (lang_country, modifier ) = locale.getlocale() - if lang_country == "sv_SE" and ( letter == u'W' or letter == u'V' ): - letter = u'V,W' - - if letter != last_letter: - last_letter = letter - tabrow = Html('tr', class_='BeginLetter') - tabcol = Html('td', class_='ColumnLetter', inline=True) + ( - Html('a', last_letter, name=last_letter, title="Letter %s" % last_letter) + trow = Html('tr') + ( + Html('th', _('Letter'), class_='ColumnLetter', inline=True), + Html('th', _('Name'), class_='ColumnName', inline=True) ) - else: - tabrow = Html('tr') - tabcol = Html('td', ' ', class_='ColumnLetter', inline=True) - tabrow += tabcol + thead += trow - tabcol = Html('td', class_='ColumnName') - hyper = self.place_link(place.handle, place_title, place.gramps_id) - tabcol += hyper - tabrow += tabcol - tbody += tabrow + sort = Sort.Sort(db) + handle_list = sorted(place_handles, sort.by_place_title) + last_letter = '' + + # begin table body + tbody = Html('tbody') + table += tbody + + for handle in handle_list: + place = db.get_place_from_handle(handle) + place_title = ReportUtils.place_name(db, handle) + + if not place_title: + continue + + letter = normalize('NFKC', place_title)[0].upper() + # See : http://www.gramps-project.org/bugs/view.php?id=2933 + (lang_country, modifier ) = locale.getlocale() + if lang_country == "sv_SE" and ( letter == u'W' or letter == u'V' ): + letter = u'V,W' + + if letter != last_letter: + last_letter = letter + trow = Html('tr', class_='BeginLetter') + tbody += trow + tcell = Html('td', class_='ColumnLetter', inline=True) + ( + Html('a', last_letter, name=last_letter, title="Letter %s" % last_letter) + ) + else: + trow = Html('tr') + tbody += trow + tcell = Html('td', ' ', class_='ColumnLetter', inline=True) + trow += tcell + + tcell = Html('td', class_='ColumnName') + \ + self.place_link(place.handle, place_title, place.gramps_id) + trow += tcell - # add footer section # add clearline for proper styling - # bring body pieces together + # add footer section footer = self.write_footer() - body += footer + body += (fullclear, footer) # send page out for processing - self.mywriter(placeslist, of) + # and close the file + self.mywriter(placelistpage, of) class PlacePage(BasePage): def __init__(self, report, title, place_handle, src_list, place_list): + db = report.database - place = report.database.get_place_from_handle(place_handle) + place = db.get_place_from_handle(place_handle) BasePage.__init__(self, report, title, place.gramps_id) self.src_list = src_list # TODO verify that this is correct of = self.report.create_file(place.get_handle(), 'plc') self.up = True - self.page_title = ReportUtils.place_name(report.database, place_handle) - places, body = self.write_header("%s - %s" % (_('Places'), self.page_title)) + self.page_title = ReportUtils.place_name(db, place_handle) + placepage, body = self.write_header("%s - %s" % (_('Places'), self.page_title)) # begin PlaceDetail Division - sect_places = Html('div', id='PlaceDetail', class_='content') + with Html('div', class_='content', id='PlaceDetail') as section: + body += section - media_list = place.get_media_list() - thumbnail = self.display_first_image_as_thumbnail(media_list) - if thumbnail: - sect_places += thumbnail + media_list = place.get_media_list() + thumbnail = self.display_first_image_as_thumbnail(media_list) + if thumbnail is not None: + section += thumbnail - sect_title = Html('h3', html_escape(self.page_title.strip())) - sect_places += sect_title + # section title + section += Html('h3', html_escape(self.page_title.strip())) - # begin summaryarea division and places table - summaryarea = Html('div', id='summaryarea') - places_table = Html('table', class_='infolist place') + # begin summaryarea division and places table + with Html('div', id='summaryarea') as summaryarea: + section += summaryarea - if not self.noid: - tabrow = Html('tr') - tabcol1 = Html('td', _('GRAMPS ID'), class_='ColumnAttribute', inline=True) - tabcol2 = Html('td', place.gramps_id, class_='ColumnValue', inline=True) - tabrow += (tabcol1, tabcol2) - places_table += tabrow + with Html('table', class_='infolist place') as table: + summaryarea += table - if place.main_loc: - ml = place.main_loc - for val in [(_('Street'), ml.street), - (_('City'), ml.city), - (_('Church Parish'), ml.parish), - (_('County'), ml.county), - (_('State/Province'), ml.state), - (_('ZIP/Postal Code'), ml.postal), - (_('Country'), ml.country)]: - if val[1]: - tabrow = Html('tr') - tabcol1 = Html('td', val[0], class_='ColumnAttribute', inline=True) - tabcol2 = Html('td', val[1], class_='ColumnValue', inline=True) - tabrow += (tabcol1, tabcol2) - places_table += tabrow + if not self.noid: + trow = Html('tr') + ( + Html('td', _('GRAMPS ID'), class_='ColumnAttribute', inline=True), + Html('td', place.gramps_id, class_='ColumnValue', inline=True) + ) + table += trow - if place.lat: - tabrow = Html('tr') - tabcol1 = Html('td', _('Latitude'), class_='ColumnAttribute', inline=True) - tabcol2 = Html('td', place.lat, class_='ColumnValue', inline=True) - tabrow += (tabcol1, tabcol2) - places_table += tabrow + if place.main_loc: + ml = place.main_loc + for val in [(_('Street'), ml.street), + (_('City'), ml.city), + (_('Church Parish'), ml.parish), + (_('County'), ml.county), + (_('State/Province'), ml.state), + (_('ZIP/Postal Code'), ml.postal), + (_('Country'), ml.country)]: + if val[1]: + trow = Html('tr') + ( + Html('td', val[0], class_='ColumnAttribute', inline=True), + Html('td', val[1], class_='ColumnValue', inline=True) + ) + table += trow - if place.long: - tabrow = Html('tr') - tabcol1 = Html('td', _('Longitude'), class_='ColumnAttribute', inline=True) - tabcol2 = Html('td', place.long, class_='ColumnValue', inline=True) - tabrow += (tabcol1, tabcol2) - places_table += tabrow + if place.lat: + trow = Html('tr') + ( + Html('td', _('Latitude'), class_='ColumnAttribute', inline=True), + Html('td', place.lat, class_='ColumnValue', inline=True) + ) + table += trow - # close table and summary area - summaryarea += places_table - sect_places += summaryarea + if place.long: + trow = Html('tr') + ( + Html('td', _('Longitude'), class_='ColumnAttribute', inline=True), + Html('td', place.long, class_='ColumnValue', inline=True) + ) + table += trow - if self.use_gallery: - placegallery = self.display_additional_images_as_gallery(media_list) - if placegallery: - sect_places += placegallery - notelist = self.display_note_list(place.get_note_list()) - if notelist: - sect_places += notelist - urllinks = self.display_url_list(place.get_url_list()) - if urllinks: - sect_places += urllinks - referenceslist = self.display_references(place_list[place.handle]) - if referenceslist: - sect_places += referenceslist + # place gallery + if self.use_gallery: + placegallery = self.display_additional_images_as_gallery(media_list) + if placegallery is not None: + section += placegallery + + # place notes + notelist = self.display_note_list(place.get_note_list()) + if notelist is not None: + section += notelist + + # place urls + urllinks = self.display_url_list(place.get_url_list()) + if urllinks is not None: + section += urllinks + + # place references + referenceslist = self.display_references(place_list[place.handle]) + if referenceslist is not None: + section += referenceslist - # add footer section # add clearline for proper styling - # bring all body pieces together + # add footer section footer = self.write_footer() - body += (sect_places, fullclear, footer) + body += (fullclear, footer) # send page out for processing - self.mywriter(places, of) + # and close the file + self.mywriter(placepage, of) class MediaPage(BasePage): @@ -1834,6 +1850,7 @@ class SurnameListPage(BasePage): def __init__(self, report, title, person_handle_list, order_by=ORDER_BY_NAME, filename="surnames"): BasePage.__init__(self, report, title) + db = report.database if order_by == self.ORDER_BY_NAME: of = self.report.create_file(filename) @@ -1857,7 +1874,7 @@ class SurnameListPage(BasePage): # add alphabet navigation after page msg # only if surname list not surname count if order_by == self.ORDER_BY_NAME: - alpha_nav = alphabet_navigation(report.database, person_handle_list, _PERSON) + alpha_nav = alphabet_navigation(db, person_handle_list, _PERSON) if alpha_nav is not None: section += alpha_nav @@ -1889,7 +1906,7 @@ class SurnameListPage(BasePage): with Html('tbody') as tbody: table += tbody - person_handle_list = sort_people(report.database, person_handle_list) + person_handle_list = sort_people(db, person_handle_list) if order_by == self.ORDER_BY_COUNT: temp_list = {} for (surname, data_list) in person_handle_list: @@ -1984,18 +2001,16 @@ class IntroductionPage(BasePage): note = db.get_note_from_gramps_id(note_id) if note: note_text = note.get() + if note_text: - # styled notes - htmlnotetext = self.styled_note(note.get_styledtext(), + # styled notes + htmlnotetext = self.styled_note(note.get_styledtext(), note.get_format()) - if htmlnotetext: - text = htmlnotetext - else: - text = Html('pre', note_text) - else: - text = None - text = text or ' ' - section += text + if htmlnotetext: + text = htmlnotetext + else: + text = Html('p', note_text) + section += text # add clearline for proper styling # create footer section @@ -2013,49 +2028,51 @@ class HomePage(BasePage): def __init__(self, report, title): BasePage.__init__(self, report, title) + db = report.database of = self.report.create_file("index") - Home, body = self.write_header(_('Home')) + homepage, body = self.write_header(_('Home')) - sect_home_page = Html('div', id='Home', class_='content') + # begin home division + with Html('div', class_='content', id='Home') as section: + body += section - homeimg = report.add_image('homeimg') - if homeimg: - sect_home_page += homeimg + homeimg = report.add_image('homeimg') + if homeimg is not None: + section += homeimg - note_id = report.options['homenote'] - if note_id: - note = report.database.get_note_from_gramps_id(note_id) - note_text = note.get() - if note_text: - user_footer = Html('div', id='user_footer') + note_id = report.options['homenote'] + if note_id: + note = db.get_note_from_gramps_id(note_id) + note_text = note.get() + if note_text: - # styled notes - htmlnotetext = self.styled_note(note.get_styledtext(), - note.get_format()) - if htmlnotetext: - text = htmlnotetext - else: - text = Html('p', note_text) - user_footer += text - sect_home_page += user_footer + # styled notes + htmlnotetext = self.styled_note(note.get_styledtext(), + note.get_format()) + if htmlnotetext: + text = htmlnotetext + else: + text = Html('p', note_text) + section += text - # create footer section # create clear line for proper styling - # bring all bosy pieces together + # create footer section footer = self.write_footer() - body += (sect_home_page, fullclear, footer) + body += (fullclear, footer) # send page out for processing - self.mywriter(Home, of) + # and close the file + self.mywriter(homepage, of) class SourceListPage(BasePage): def __init__(self, report, title, handle_set): BasePage.__init__(self, report, title) + db = report.database of = self.report.create_file("sources") - sourcelist, body = self.write_header(_('Sources')) + sourcelistpage, body = self.write_header(_('Sources')) # begin source list division with Html('div', class_='content', id='sources') as section: @@ -2064,9 +2081,9 @@ class SourceListPage(BasePage): handle_list = list(handle_set) source_dict = {} - #Sort the sources + # Sort the sources for handle in handle_list: - source = report.database.get_source_from_handle(handle) + source = db.get_source_from_handle(handle) key = source.get_title() + str(source.get_gramps_id()) source_dict[key] = (source, handle) @@ -2109,14 +2126,14 @@ class SourceListPage(BasePage): # send page out for processing # and close the file - self.mywriter(sourcelist, of) + self.mywriter(sourcelistpage, of) class SourcePage(BasePage): def __init__(self, report, title, handle, src_list): db = report.database - source = report.database.get_source_from_handle(handle) + source = db.get_source_from_handle(handle) BasePage.__init__(self, report, title, source.gramps_id) of = self.report.create_file(source.get_handle(), 'src') @@ -2130,7 +2147,7 @@ class SourcePage(BasePage): media_list = source.get_media_list() thumbnail = self.display_first_image_as_thumbnail(media_list) - if thumbnail: + if thumbnail is not None: section += thumbnail # begin section title @@ -2161,17 +2178,17 @@ class SourcePage(BasePage): # additional gallery sourcegallery = self.display_additional_images_as_gallery(media_list) - if sourcegallery: + if sourcegallery is not None: section += sourcegallery # additional notes sourcenotes = self.display_note_list(source.get_note_list()) - if sourcenotes: + if sourcenotes is not None: section += sourcenotes # references source_references = self.display_references(src_list[source.handle]) - if source_references: + if source_references is not None: section += source_references # add clearline for proper styling @@ -2187,6 +2204,7 @@ class MediaListPage(BasePage): def __init__(self, report, title): BasePage.__init__(self, report, title) + db = report.database of = self.report.create_file("gallery") gallery, body = self.write_header(_('Gallery')) @@ -2216,11 +2234,11 @@ class MediaListPage(BasePage): table += tbody index = 1 - sort = Sort.Sort(report.database) + sort = Sort.Sort(db) mlist = sorted(self.report.photo_list, sort.by_media_title) for handle in mlist: - media = report.database.get_object_from_handle(handle) + media = db.get_object_from_handle(handle) date = _dd.display(media.get_date_object()) title = media.get_description() if not title: @@ -2409,6 +2427,7 @@ class ContactPage(BasePage): def __init__(self, report, title): BasePage.__init__(self, report, title) + db = report.database of = self.report.create_file("contact") contactpage, body = self.write_header(_('Contact')) @@ -2422,9 +2441,10 @@ class ContactPage(BasePage): section += summaryarea contactimg = report.add_image('contactimg', 200) - if contactimg: + if contactimg is not None: summaryarea += contactimg + # get researcher information r = Utils.get_researcher() with Html('div', id='researcher') as researcher: @@ -2433,7 +2453,7 @@ class ContactPage(BasePage): r.name = r.name.replace(',,,', '') researcher += Html('h3', r.name, inline=True) if r.addr: - researcher += Html('span', r.addr, id='streetaddress', inline=True) + researcher += Html('span', r.addr, id='streetaddress') text = "".join([r.city, r.state, r.postal]) if text: city = Html('span', r.city, id='city', inline=True) @@ -2453,7 +2473,7 @@ class ContactPage(BasePage): note_id = report.options['contactnote'] if note_id: - note = report.database.get_note_from_gramps_id(note_id) + note = db.get_note_from_gramps_id(note_id) note_text = note.get() if note_text: @@ -2493,95 +2513,96 @@ class IndividualPage(BasePage): self.src_list = src_list # Used by get_citation_links() self.bibli = Bibliography() self.place_list = place_list - self.sort_name = _nd.sorted(self.person) - self.name = _nd.sorted(self.person) + self.sort_name = self.get_name(self.person) + self.name = self.get_name(self.person) + db = report.database of = self.report.create_file(person.handle, 'ppl') self.up = True indivdetpage, body = self.write_header(self.sort_name) # begin individualdetail division - with Html('div', class_='content', id='IndividualDetail') as individualdetail: - body += individualdetail + with Html('div', class_='content', id='IndividualDetail') as section: + body += section # display a person's general data thumbnail, name, summary = self.display_ind_general() # if there is a thumbnail, add it also? if thumbnail is not None: - individualdetail += (thumbnail, name, summary) + section += (thumbnail, name, summary) else: - individualdetail += (name, summary) + section += (name, summary) # display a person's events sect2 = self.display_ind_events() if sect2 is not None: - individualdetail += sect2 + section += sect2 # display attributes sect3 = self.display_attr_list(self.person.get_attribute_list()) if sect3 is not None: - individualdetail += sect3 + section += sect3 # display parents sect4 = self.display_ind_parents() if sect4 is not None: - individualdetail += sect4 + section += sect4 # display relationships sect5 = self.display_ind_families() if sect5 is not None: - individualdetail += sect5 + section += sect5 # display address(es) sect6 = self.display_addresses() if sect6 is not None: - individualdetail += sect6 + section += sect6 media_list = [] photo_list = self.person.get_media_list() if len(photo_list) > 1: media_list = photo_list[1:] for handle in self.person.get_family_handle_list(): - family = report.database.get_family_from_handle(handle) + family = db.get_family_from_handle(handle) media_list += family.get_media_list() for evt_ref in family.get_event_ref_list(): - event = report.database.get_event_from_handle(evt_ref.ref) + event = db.get_event_from_handle(evt_ref.ref) media_list += event.get_media_list() for evt_ref in self.person.get_primary_event_ref_list(): - event = report.database.get_event_from_handle(evt_ref.ref) + event = db.get_event_from_handle(evt_ref.ref) if event: media_list += event.get_media_list() # display additional images as gallery sect7 = self.display_additional_images_as_gallery(media_list) if sect7 is not None: - individualdetail += sect7 + section += sect7 # display notes sect8 = self.display_note_list(self.person.get_note_list()) if sect8 is not None: - individualdetail += sect8 + section += sect8 # display web links sect9 = self.display_url_list(self.person.get_url_list()) if sect9 is not None: - individualdetail += sect9 + section += sect9 # display sources sect10 = self.display_ind_sources() if sect10 is not None: - individualdetail += sect10 + section += sect10 # display pedigree sect11 = self.display_ind_pedigree() if sect11 is not None: - individualdetail += sect11 + section += sect11 # display ancestor tree if report.options['graph']: sect12 = self.display_tree() - individualdetail += sect12 + section += sect12 # add clearline for proper styling # create footer section @@ -2639,6 +2660,7 @@ class IndividualPage(BasePage): style="top: %dpx; left: %dpx;" % (top, xoff+1) ) + person_name = self.get_name(person) if person.handle in self.ind_list: thumbnailUrl = None if self.use_gallery and col < 5: @@ -2650,16 +2672,13 @@ class IndividualPage(BasePage): if mime_type: (photoUrl, thumbnailUrl) = self.report.prepare_copy_media(photo) thumbnailUrl = '/'.join(['..']*3 + [thumbnailUrl]) - person_name = _nd.display(person) url = self.report.build_url_fname_html(person.handle, 'ppl', True) - boxbg += self.person_link(url, person_name, thumbnailUrl=thumbnailUrl) + boxbg += self.person_link(url, person, name_style=True, + thumbnailUrl=thumbnailUrl) else: - boxbg += Html('span', _nd.display(person), class_="unlinked", - inline=True) - shadow = Html('div', class_="shadow", inline=True, - style="top: %dpx; left: %dpx;" % - (top+_SHADOW, xoff+_SHADOW) - ) + boxbg += Html('span', person_name, class_="unlinked", inline=True) + shadow = Html('div', class_="shadow", inline=True, style="top: %dpx; left: %dpx;" + % (top+_SHADOW, xoff+_SHADOW) ) return [boxbg, shadow] @@ -2789,7 +2808,7 @@ class IndividualPage(BasePage): return ol def child_ped(ol): - ol += Html('li', class_="thisperson") + self.name + ol += Html('li', class_="thisperson", inline=True) + self.name family = self.pedigree_family() if family: ol += Html('ol', class_="spouselist") + family @@ -2846,115 +2865,122 @@ class IndividualPage(BasePage): sect_name = Html('h3', self.sort_name.strip(), inline=True) - summaryarea = Html('div', id='summaryarea') - gen_table = Html('table', class_='infolist') + # begin summaryarea division + with Html('div', id='summaryarea') as summaryarea: - primary_name = self.person.get_primary_name() + # begin general details table + with Html('table', class_='infolist') as table: + summaryarea += table - # Names [and their sources] - for name in [primary_name] + self.person.get_alternate_names(): - pname = _nd.display_name(name) - pname += self.get_citation_links( name.get_source_references() ) + primary_name = self.person.get_primary_name() + all_names = [primary_name] + self.person.get_alternate_names() - # if we have just a firstname, then the name is preceeded by ", " - # which doesn't exactly look very nice printed on the web page - if pname[:2] == ', ': - pname = pname[2:] + # Names [and their sources] + for name in all_names: + pname = _nd.display_name(name) + pname += self.get_citation_links( name.get_source_references() ) - type_ = str( name.get_type() ) - tabrow = Html('tr') - tabcol1 = Html('td', type_, class_='ColumnAttribute', inline=True) - tabcol2 = Html('td', pname, class_='ColumnValue') + # if we have just a firstname, then the name is preceeded by ", " + # which doesn't exactly look very nice printed on the web page + if pname[:2] == ', ': + pname = pname[2:] - # display any notes associated with this name - notelist = name.get_note_list() - if len(notelist): - unordered = Html('ul') - tabcol2 += unordered - for notehandle in notelist: - note = db.get_note_from_handle(notehandle) - if note: - note_text = note.get() - if note_text: + type_ = str( name.get_type() ) + trow = Html('tr') + ( + Html('td', type_, class_='ColumnAttribute', inline=True), + ) + table += trow + tcell = Html('td', pname, class_='ColumnValue', inline=True) + trow += tcell + + # display any notes associated with this name + notelist = name.get_note_list() + if len(notelist): + unordered = Html('ul') + tcell += unordered + for notehandle in notelist: + note = db.get_note_from_handle(notehandle) + if note: + note_text = note.get() + if note_text: - # styled notes - htmlnotetext = self.styled_note(note.get_styledtext(), - note.get_format()) - if htmlnotetext: - text = htmlnotetext - else: - text = Html('pre', note_text) - unordered += text + # styled notes + htmlnotetext = self.styled_note(note.get_styledtext(), + note.get_format()) + if htmlnotetext: + text = htmlnotetext + else: + text = Html('p', note_text) + unordered += text - # finished with this name - tabrow += (tabcol1, tabcol2) - gen_table += tabrow + # display call names + first_name = primary_name.get_first_name() + for name in all_names: + call_name = name.get_call_name() + if call_name and call_name != first_name: + call_name += self.get_citation_links( + name.get_source_references() ) + trow = Html('tr') + ( + Html('td', _('Common Name'), class_='ColumnAttribute', + inline=True), + Html('td', call_name, class_='ColumnValue', inline=True) + ) + table += trow + + # display the nickname attribute + nick_name = self.person.get_nick_name() + if nick_name and nick_name != first_name: + nick_name += self.get_citation_links( + self.person.get_source_references() ) + trow = Html('tr') + ( + Html('td', _('Nick Name'), class_='ColumnAttribute', + inline=True), + Html('td', nick_name, class_='ColumnValue', inline=True) + ) + table += trow + # GRAMPS ID + if not self.noid: + trow = Html('tr') + ( + Html('td', _('GRAMPS ID'), class_='ColumnAttribute', + inline=True), + Html('td', self.person.gramps_id, class_='ColumnValue', + inline=True) + ) + table += trow - # display call names - first_name = primary_name.get_first_name() - for name in [primary_name] + self.person.get_alternate_names(): - call_name = name.get_call_name() - if call_name and call_name != first_name: - call_name += self.get_citation_links( name.get_source_references() ) - tabrow = Html('tr') - tabcol1 = Html('td', _('Name'), class_='ColumnAttribute', inline=True) - tabcol2 = Html('td', call_name, class_='ColumnValue', inline=True) - tabrow += (tabcol1, tabcol2) - gen_table += tabrow + # Gender + gender = self.gender_map[self.person.gender] + trow = Html('tr') + ( + Html('td', _('Gender'), class_='ColumnAttribute', inline=True), + Html('td', gender, class_='ColumnValue', inline=True) + ) + table += trow - # display the nickname attribute - nick_name = self.person.get_nick_name() - if nick_name and nick_name != first_name: - nick_name += self.get_citation_links( self.person.get_source_references() ) - tabrow = Html('tr') - tabcol1 = Html('td', _('Name'), class_='ColumnAttribute', inline=True) - tabcol2 = Html('td', nick_name, class_='ColumnValue', inline=True) - tabrow += (tabcol1, tabcol2) - gen_table += tabrow + # Age At Death??? + birth_ref = self.person.get_birth_ref() + birth_date = None + if birth_ref: + birth_event = db.get_event_from_handle(birth_ref.ref) + birth_date = birth_event.get_date_object() - # GRAMPS ID - if not self.noid: - tabrow = Html('tr') - tabcol1 = Html('td', _('GRAMPS ID'), class_='ColumnAttribute', inline=True) - tabcol2 = Html('td', self.person.gramps_id, class_='ColumnValue', inline=True) - tabrow += (tabcol1, tabcol2) - gen_table += tabrow + if birth_date is not None: + alive = probably_alive(self.person, db, date.Today()) + death_ref = self.person.get_death_ref() + death_date = None + if death_ref: + death_event = db.get_event_from_handle(death_ref.ref) + death_date = death_event.get_date_object() - # Gender - gender = self.gender_map[self.person.gender] - tabrow = Html('tr') - tabcol1 = Html('td', _('Gender'), class_='ColumnAttribute', inline=True) - tabcol2 = Html('td', gender, class_='ColumnValue', inline=True) - tabrow += (tabcol1, tabcol2) - gen_table += tabrow - - # Age At Death??? - birth_ref = self.person.get_birth_ref() - birth_date = None - if birth_ref: - birth_event = db.get_event_from_handle(birth_ref.ref) - birth_date = birth_event.get_date_object() - - if (birth_date is not None and birth_date.is_valid()): - alive = probably_alive(self.person, db, date.Today()) - death_ref = self.person.get_death_ref() - death_date = None - if death_ref: - death_event = db.get_event_from_handle(death_ref.ref) - death_date = death_event.get_date_object() - - if not alive and (death_date is not None and death_date.is_valid()): - nyears = death_date - birth_date - nyears.format(precision=3) - tabrow = Html('tr') - tabcol1 = Html('td', _('Age at Death'), class_='ColumnAttribute', inline=True) - tabcol2 = Html('td', nyears, class_='ColumnValue', inline=True) - tabrow += (tabcol1, tabcol2) - gen_table += tabrow - - # close table - summaryarea += gen_table + if not alive and death_date is not None: + nyears = death_date - birth_date + nyears.format(precision=3) + trow = Html('tr') + ( + Html('td', _('Age at Death'), class_='ColumnAttribute', + inline=True), + Html('td', nyears, class_='ColumnValue', inline=True) + ) + table += trow # return all three pieces to its caller # do NOT combine before returning to class IndividualPage @@ -2981,11 +3007,9 @@ class IndividualPage(BasePage): with Html('tbody') as tbody: table += tbody for event_ref in evt_ref_list: - event = db.get_event_from_handle( - event_ref.ref) + event = db.get_event_from_handle(event_ref.ref) if event: - tbody += self.display_event_row( - db, event, event_ref) + tbody += self.display_event_row(db, event, event_ref) return section def display_event_row(self, db, event, event_ref): @@ -3010,94 +3034,86 @@ class IndividualPage(BasePage): place = '' # begin table row for either: display_event_row() or format_event() - tabrow = Html('tr') + with Html('tr') as trow: - # Event/ Type - evt_name = str(event.get_type()) + # Event/ Type + evt_name = str(event.get_type()) - if event_ref.get_role() == EventRoleType.PRIMARY: - txt = u"%(evt_name)s" % locals() - else: - evt_role = event_ref.get_role() - txt = u"%(evt_name)s (%(evt_role)s)" % locals() - txt = txt or ' ' - tabcol = Html('td', txt, class_='ColumnValue EventType', inline=False - if txt != ' ' else True) - tabrow += tabcol - - # Date - event_date = event.get_date_object() - if event_date and event_date.is_valid(): - txt = _dd.display(event_date) - else: - txt = ' ' - tabcol = Html('td', txt, class_='ColumnValue Date', inline=False - if txt != ' ' else True) - tabrow += tabcol - - # Place - place_handle = event.get_place_handle() - if place_handle: - - lnk = (self.report.cur_fname, self.page_title, self.gid) - if place_handle in self.place_list: - if lnk not in self.place_list[place_handle]: - self.place_list[place_handle].append(lnk) + if event_ref.get_role() == EventRoleType.PRIMARY: + txt = u"%(evt_name)s" % locals() else: - self.place_list[place_handle] = [lnk] + evt_role = event_ref.get_role() + txt = u"%(evt_name)s (%(evt_role)s)" % locals() + txt = txt or ' ' + trow += Html('td', txt, class_='ColumnValue EventType', inline=True) - place = self.place_link(place_handle, - ReportUtils.place_name(db, - place_handle), - up=True) - else: - place = None - txt = place or ' ' - tabcol = Html('td', txt, class_='ColumnValue Place') - tabrow += tabcol + # Date + event_date = event.get_date_object() + if event_date: + txt = _dd.display(event_date) + else: + txt = ' ' + trow += Html('td', txt, class_='ColumnValue Date', inline=True) - # Description - # Get the links in super script to the Source References section in the same page - sref_links = self.get_citation_links(event.get_source_references()) - txt = ''.join(wrapper.wrap(event.get_description())) - txt = txt or ' ' - tabcol = Html('td', txt, class_='ColumnValue Description') - tabrow += tabcol + # Place + place_handle = event.get_place_handle() + if place_handle: - # event sources - citation = self.get_citation_links(event.get_source_references()) - txt = citation or ' ' - tabcol = Html('td', txt, class_='ColumnValue Source', inline=True) - tabrow += tabcol + lnk = (self.report.cur_fname, self.page_title, self.gid) + if place_handle in self.place_list: + if lnk not in self.place_list[place_handle]: + self.place_list[place_handle].append(lnk) + else: + self.place_list[place_handle] = [lnk] - # Notes - # if the event or event reference has a note attached to it, - # get the text and format it correctly - notelist = event.get_note_list() - notelist.extend(event_ref.get_note_list()) - if not notelist: - tabcol = Html('td', ' ', class_='ColumnValue Notes') - tabrow += tabcol - else: - tabcol = Html('td', class_='ColumnValue Notes') - for notehandle in notelist: - note = db.get_note_from_handle(notehandle) - if note: - note_text = note.get() - if note_text: + place = self.place_link(place_handle, + ReportUtils.place_name(db, + place_handle), + up=True) + else: + place = None + txt = place or ' ' + trow += Html('td', txt, class_='ColumnValue Place') + + # Description + # Get the links in super script to the Source References section in the same page + sref_links = self.get_citation_links(event.get_source_references()) + txt = ''.join(wrapper.wrap(event.get_description())) + txt = txt or ' ' + trow += Html('td', txt, class_='ColumnValue Description') + + # event sources + citation = self.get_citation_links(event.get_source_references()) + txt = citation or ' ' + trow += Html('td', txt, class_='ColumnValue Source') + + # Notes + # if the event or event reference has a note attached to it, + # get the text and format it correctly + notelist = event.get_note_list() + notelist.extend(event_ref.get_note_list()) + tcell = Html('td', class_='ColumnValue Notes') + trow += tcell + if not notelist: + tcell += ' ' + else: + for notehandle in notelist: + note = db.get_note_from_handle(notehandle) + if note: + note_text = note.get() + if note_text: - # styled notes - htmlnotetext = self.styled_note(note.get_styledtext(), - note.get_format()) - if htmlnotetext: - text = htmlnotetext - else: - text = Html('p', note_text) - tabcol += text - tabrow += tabcol + # styled notes + htmlnotetext = self.styled_note(note.get_styledtext(), + note.get_format()) + if htmlnotetext: + text = htmlnotetext + else: + text = Html('p', note_text) + tcell += text # return events table row to its caller - return tabrow + return trow def display_addresses(self): """ @@ -3105,58 +3121,49 @@ class IndividualPage(BasePage): """ alist = self.person.get_address_list() - if not alist: return None # begin addresses division and title - sect_address = Html('div', class_='subsection', id='addresses') - sect_title = Html('h4', _('Addresses'), inline=True) - sect_address += sect_title + with Html('div', class_='subsection', id='Addresses') as section: + section += Html('h4', _('Addresses'), inline=True) - # begin addresses table and table head - address_table = Html('table', class_='infolist') - thead = Html('thead') - tabrow = Html('tr') + # begin addresses table and table head + with Html('table', class_='infolist') as table: + section += table - # head, Column 01 - tabhead = Html('th', _('Dates of Residence'), class_ = 'ColumnValue Date', - inline=True) - tabrow += tabhead + thead = Html('thead') + table += thead + trow = Html('tr') + ( + Html('th', _('Date of Residence'), class_ = 'ColumnAttribute', + inline=True), + Html('th', _('Address'), class_ = 'ColumnAttribute') + ) + thead += trow - # head, Column 02 - tabhead = Html('th', _('Address'), class_ = 'ColumnValue Place', inline=True) - tabrow += tabhead + # begin table body + tbody = Html('tbody') + table += tbody - # close table header - thead += tabrow - address_table += thead + for addr in alist: + location = ReportUtils.get_address_str(addr) + citation_link = self.get_citation_links(addr.get_source_references()) + date = _dd.display(addr.get_date_object()) - # begin table body - tbody = Html('tbody') - - for addr in alist: - location = ReportUtils.get_address_str(addr) - citation_link = self.get_citation_links(addr.get_source_references()) - date = _dd.display(addr.get_date_object()) - - tabrow = Html('tr') - tabcol1 = Html('td', date, class_='ColumnAttribute', inline=True) - tabcol2 = Html('td', location, class_='ColumnValue') - if len(citation_link): - for citation in citation_link.splitlines(): - tabcol2 += Html('sup') + ( - Html('a', citation, href=' #sref%s ' % citation, inline=True) + trow = Html('tr') + ( + Html('td', date, class_='ColumnValue Date', inline=True) ) - tabrow += (tabcol1, tabcol2) - tbody += tabrow - - # close table body and table - address_table += tbody - sect_address += address_table + tbody += trow + tcell = Html('td', location, class_='ColumnValue Citation') + trow += tcell + if len(citation_link): + for citation in citation_link.splitlines(): + tcell += Html('sup') + ( + Html('a', citation, href='#sref%s' % citation) + ) # return address division to its caller - return sect_address + return section def display_child_link(self, child_handle): """ @@ -3166,14 +3173,13 @@ class IndividualPage(BasePage): child = db.get_person_from_handle(child_handle) gid = child.gramps_id - list = Html('li', inline=True) + list = Html('li') if child_handle in self.ind_list: - child_name = self.get_name(child) url = self.report.build_url_fname_html(child_handle, 'ppl', True) - hyper = self.person_link(url, child_name, gid) - list += hyper + list += self.person_link(url, child, True, gid) else: - list += self.get_name(child) + child_name = self.get_name(child) + list += child_name # return list to its caller return list @@ -3185,31 +3191,33 @@ class IndividualPage(BasePage): db = self.report.database person = db.get_person_from_handle(handle) - tabcol1 = Html('td', title, class_='ColumnAttribute', inline=True) - tabcol2 = Html('td', class_='ColumnValue') + tcell1 = Html('td', title, class_='ColumnAttribute', inline=True) + tcell2 = Html('td', class_='ColumnValue') gid = person.gramps_id if handle in self.ind_list: url = self.report.build_url_fname_html(handle, 'ppl', True) - hyper = self.person_link(url, self.get_name(person), gid) - tabcol2 += hyper + tcell2 += self.person_link(url, person, True, gid) else: - tabcol2 += self.get_name(person) + person_name = self.get_name(person) + tcell2 += person_name if rel and rel != ChildRefType(ChildRefType.BIRTH): - tabcol2 += '   (%s)' % str(rel) + tcell2 += '   (%s)' % str(rel) # return table columns to its caller - return tabcol1, tabcol2 + return tcell1, tcell2 def display_ind_parents(self): """ Display a person's parents """ + birthorder = self.report.options['birthorder'] parent_list = self.person.get_parent_family_handle_list() if not parent_list: return None + db = self.report.database # begin parents division @@ -3239,26 +3247,26 @@ class IndividualPage(BasePage): break if not first: - tabrow = Html('tr') + trow = Html('tr') tabcol = Html('td', ' ', colspan=2, inline=True) - tabrow += tabcol - parent_table += tabrow + trow += tabcol + parent_table += trow else: first = False father_handle = family.get_father_handle() if father_handle: - tabrow = Html('tr') + trow = Html('tr') tabcol1, tabcol2 = self.display_parent(father_handle, _('Father'), frel) - tabrow += (tabcol1, tabcol2) - parent_table += tabrow + trow += (tabcol1, tabcol2) + parent_table += trow mother_handle = family.get_mother_handle() if mother_handle: - tabrow = Html('tr') + trow = Html('tr') tabcol1, tabcol2 = self.display_parent(mother_handle, _('Mother'), mrel) - tabrow += (tabcol1, tabcol2) - parent_table += tabrow + trow += (tabcol1, tabcol2) + parent_table += trow first = False if len(child_ref_list) > 1: @@ -3266,9 +3274,12 @@ class IndividualPage(BasePage): for child_handle in childlist: sibling.add(child_handle) # remember that we've already "seen" this child - # now that we have all natural siblings, display them... - if len(sibling) > 0 : - tabrow = Html('tr') + # now that we have all natural siblings, display them... + if birthorder: + sibling = sort_birth_order(db, sibling, key=_PARENTS) + + if len(sibling) > 0: + trow = Html('tr') tabcol1 = Html('td', _('Siblings'), class_='ColumnAttribute', inline=True) tabcol2 = Html('td', class_='ColumnValue') ordered = Html('ol') @@ -3278,8 +3289,8 @@ class IndividualPage(BasePage): kid_link = self.display_child_link(child_handle) ordered += kid_link tabcol2 += ordered - tabrow += (tabcol1, tabcol2) - parent_table += tabrow + trow += (tabcol1, tabcol2) + parent_table += trow # Also try to identify half-siblings half_siblings = set() @@ -3313,9 +3324,12 @@ class IndividualPage(BasePage): # we have a new half sibling half_siblings.add(half_child_handle) + if birthorder: + half_siblings = sort_birth_order(db, half_siblings, key=_PARENTS) + # now that we have all of the half-siblings, print them out - if len(half_siblings) > 0 : - tabrow = Html('tr') + if len(half_siblings) : + trow = Html('tr') tabcol1 = Html('td', _('Half Siblings'), class_='ColumnAttribute', inline=True) tabcol2 = Html('td', class_='ColumnValue') ordered = Html('ol') @@ -3324,8 +3338,8 @@ class IndividualPage(BasePage): kid_link = self.display_child_link(child_handle) ordered += kid_link tabcol2 += ordered - tabrow += (tabcol1, tabcol2) - parent_table += tabrow + trow += (tabcol1, tabcol2) + parent_table += trow # get step-siblings step_siblings = set() @@ -3394,9 +3408,12 @@ class IndividualPage(BasePage): # we have a new step sibling step_siblings.add(step_child_handle) + if birthorder: + step_iblings = sort_birth_order(db, step_siblings, key=_PARENTS) + # now that we have all of the step-siblings, print them out if len(step_siblings) > 0: - tabrow = Html('tr') + trow = Html('tr') tabcol1 = Html('td', _('Step Siblings'), class_='ColumnAttribute', inline=True) tabcol2 = Html('td', class_='ColumnValue') ordered = Html('ol') @@ -3405,8 +3422,8 @@ class IndividualPage(BasePage): kid_link = self.display_child_link(child_handle) ordered += kid_link tabcol2 += ordered - tabrow += (tabcol1, tabcol2) - parent_table += tabrow + trow += (tabcol1, tabcol2) + parent_table += trow # add table to parent division sect_parents += parent_table @@ -3420,42 +3437,41 @@ class IndividualPage(BasePage): """ family_list = self.person.get_family_handle_list() - if not family_list: return None + db = self.report.database - - # begin relationships division and title + # begin families division and section title with Html('div', class_='subsection', id='families') as section: + section += Html('h4', _('Families'), inline=True) - # section title - section += Html('h4',_('Families'), inline=True) - - # begin relationships table + # begin families table with Html('table', class_='infolist') as table: - section += table + section += table for family_handle in family_list: family = db.get_family_from_handle(family_handle) self.display_partner(family, table) - childlist = family.get_child_ref_list() if childlist: - trow = Html('tr') + ( - Html('td', ' ', class_='ColumnType', inline=True), - Html('td', _('Children') if len(childlist) > 1 else _('Child'), - class_='ColumnAttribute', inline=True) - ) - with Html('td', class_='ColumnValue') as tcell: - trow += tcell - with Html('ol') as ol: - tcell += ol - childlist = [child_ref.ref for child_ref in childlist] - # TODO. Optionally sort on birthdate - for child_handle in childlist: - ol += self.display_child_link(child_handle) + trow = Html('tr') + table += trow + tcell1 = Html('td', ' ', class_='ColumnType', inline=True) + tcell2 = Html('td', _('Children'), class_='ColumnAttribute', inline=True) + tcell3 = Html('td', class_='ColumnValue') + trow += (tcell1, tcell2, tcell3) + ordered = Html('ol') + tcell3 += ordered + childlist = [child_ref.ref for child_ref in childlist] + # TODO. Optionally sort on birthdate - # return relationships section + if self.report.options['birthorder']: + childlist = sort_birth_order(db, childlist, key=_FAMILY) + + for child_handle in childlist: + ordered += self.display_child_link(child_handle) + + # return section to its caller return section def display_partner(self, family, relation_table): @@ -3480,53 +3496,51 @@ class IndividualPage(BasePage): partner_handle = ReportUtils.find_spouse(self.person, family) if partner_handle: partner = db.get_person_from_handle(partner_handle) - name = self.get_name(partner) + partner_name = self.get_name(partner) else: - name = _("unknown") + partner_name = _("unknown") rtype = str(family.get_relationship()) - tabrow = Html('tr', class_='BeginFamily') + trow = Html('tr', class_='BeginFamily') tabcol1 = Html('td', rtype, class_='ColumnType', inline=True) tabcol2 = Html('td', relstr, class_='ColumnAttribute', inline=True) tabcol3 = Html('td', class_='ColumnValue') if partner_handle: gid = partner.gramps_id if partner_handle in self.ind_list: - partner_name = self.get_name(partner) url = self.report.build_url_fname_html(partner_handle, 'ppl', True) - hyper = self.person_link(url, partner_name, gid) - tabcol3 += hyper + tabcol3 += self.person_link(url, partner, True, gid) else: - tabcol3 += name - tabrow += (tabcol1, tabcol2, tabcol3) - relation_table += tabrow + tabcol3 += partner_name + trow += (tabcol1, tabcol2, tabcol3) + relation_table += trow for event_ref in family.get_event_ref_list(): event = db.get_event_from_handle(event_ref.ref) evtType = str(event.get_type()) - tabrow = Html('tr') + trow = Html('tr') tabcol1 = Html('td', ' ', class_='ColumnType', inline=True) tabcol2 = Html('td', '', class_='ColumnAttribute', inline=True) tabcol3 = Html('td', class_='ColumnValue') formatted_event = self.format_event(event, event_ref) tabcol3 += formatted_event - tabrow += (tabcol1, tabcol2, tabcol3) - relation_table += tabrow + trow += (tabcol1, tabcol2, tabcol3) + relation_table += trow for attr in family.get_attribute_list(): attrType = str(attr.get_type()) if attrType: - tabrow = Html('tr') + trow = Html('tr') tabcol1 = Html('td', ' ', class_='ColumnType', inline=True) tabcol2 = Html('td', attrType, class_='ColumnAttribute', inline=True) tabcol3 = Html('td', attr.get_value(), class_='ColumnValue', inline=True) - tabrow += (tabcol1, tabcol2, tabcol3) - relation_table += tabrow + trow += (tabcol1, tabcol2, tabcol3) + relation_table += trow notelist = family.get_note_list() for notehandle in notelist: note = db.get_note_from_handle(notehandle) if note: - tabrow = Html('tr') + trow = Html('tr') tabcol1 = Html('td', ' ', class_='ColumnType', inline=True) tabcol2 = Html('td', _('Narrative'), class_='ColumnAttribute', inline=True) tabcol3 = Html('td', class_='ColumnValue') @@ -3542,8 +3556,8 @@ class IndividualPage(BasePage): else: text = Html('p', note_text) tabcol3 += text - tabrow += (tabcol1, tabcol2, tabcol3) - relation_table += tabrow + trow += (tabcol1, tabcol2, tabcol3) + relation_table += trow # return table to its caller return relation_table @@ -3556,7 +3570,7 @@ class IndividualPage(BasePage): person_name = self.get_name(person) if person.handle in self.ind_list: url = self.report.build_url_fname_html(person.handle, 'ppl', True) - hyper = self.person_link(url, person_name) + hyper = self.person_link(url, person, name_style=True) else: hyper = person_name @@ -3603,14 +3617,14 @@ class IndividualPage(BasePage): _('Sources'), _('Notes')] # begin table header row - tabrow = Html('tr') + trow = Html('tr') for section in header_row: - tabrow += Html('th', section, class_ = 'ColumnAttribute %s' + trow += Html('th', section, class_ = 'ColumnAttribute %s' % section, inline = True) # return header row to its caller - return tabrow + return trow def format_event(self, event, event_ref): db = self.report.database @@ -3642,12 +3656,12 @@ class IndividualPage(BasePage): self.src_list[handle] = [lnk] text = "" - if len(gid_list) > 0: + if len(gid_list): text = text + " " for ref in gid_list: index, key = self.bibli.add_reference(ref) id_ = "%d%s" % (index+1, key) - text = text + ' %s' % (id_, id_) + text = text + '%s' % (id_, id_) text = text + "" return text @@ -3720,6 +3734,9 @@ class NavWebReport(Report): # either include the gender graphics or not? self.graph = self.options['graph'] + # whether to display children in birthorder or entry order? + self.birthorder = self.options['birthorder'] + if self.use_home: self.index_fname = "index" self.surname_fname = "surnames" @@ -4430,6 +4447,11 @@ class NavWebOptions(MenuReportOptions): "step-siblings with the parents and siblings")) menu.add_option(category_name, 'showhalfsiblings', showallsiblings) + birthorder = BooleanOption(_('Sort children in birth order'), False) + birthorder.set_help(_('Whether to display children in birth order' + ' or in entry order?')) + menu.add_option(category_name, 'birthorder', birthorder) + def __archive_changed(self): """ Update the change of storage: archive or directory @@ -4642,7 +4664,7 @@ def alphabet_navigation(db, handle_list, key): num_ltrs = len(sorted_first_letter) if num_ltrs <= 26: - tabrow = Html('tr') + trow = Html('tr') unordered = Html('ul') for ltr in sorted_first_letter: title_str = _('Surnames') if key == 0 else _('Places') @@ -4658,13 +4680,13 @@ def alphabet_navigation(db, handle_list, key): ) # bring table pieces back together - tabrow += unordered - alpha_table += tabrow + trow += unordered + alpha_table += trow else: nrows = (num_ltrs / 26) + 1 index = 0 for rows in range(0, nrows): - tabrow = Html('tr') + trow = Html('tr') unordered = Html('ul') cols = 0 while (cols <= 26 and index < num_ltrs): @@ -4684,10 +4706,10 @@ def alphabet_navigation(db, handle_list, key): index += 1 # bring table pieces to table row - tabrow += unordered + trow += unordered # attach table row to table - alpha_table += tabrow + alpha_table += trow # close the table alphabet += alpha_table @@ -4695,6 +4717,51 @@ def alphabet_navigation(db, handle_list, key): # return alphabet navigation to its callers return alphabet +def sort_birth_order(db, childlist, key): + """ + This will sort a list of child handles in birth order + """ + sorted_children = [] + for child_handle in childlist: + child = db.get_person_from_handle(child_handle) + + birth_date = None + birth_ref = child.get_birth_ref() + if birth_ref: + birth_event = db.get_event_from_handle(birth_ref.ref) + birth_date = birth_event.get_date_object() + if birth_date is not None: + if 1423 < birth_date.get_year() <= 2100: + year = birth_date.get_year() + else: + year = 1423 + if 0 < birth_date.get_month() <= 12: + month = birth_date.get_month() + else: + month = 1 + if 0 < birth_date.get_day() <= 31: + day = birth_date.get_day() + else: + day = 1 + else: + year, month, day = 1423, 1, 1 + date_obj = datetime.date(year, month, day) + sorted_children.append((date_obj, child_handle)) + + sorted_children.sort() + if key ==_FAMILY: + childlist = [] + else: + childlist = set() + + for birth_date, handle in sorted_children: + if key == _FAMILY: + childlist.append(handle) + else: + childlist.add(handle) + + return childlist + # ------------------------------------------ # # Register Plugin