several fixes and feature requests for NarrativeWeb, including optional columns, half-siblings, and event

notes


svn: r8745
This commit is contained in:
Stéphane Charette 2007-07-19 06:45:25 +00:00
parent 05076eeed1
commit 25a7416f8a
2 changed files with 329 additions and 29 deletions

View File

@ -1,3 +1,9 @@
2007-07-18 Stephane Charette <stephanecharette@gmail.com>
* src/plugins/NarrativeWeb.py: added several new optional columns;
added optional link to home person; show half-siblings on individual
pages; display events notes just below the event; created a new
"Advanced Options" tab to toggle all of these optional items
2007-07-18 Alex Roitman <shura@gramps-project.org>
* TODO: Update.

View File

@ -147,6 +147,12 @@ class BasePage:
self.encoding = options.handler.options_dict['NWEBencoding']
self.css = options.handler.options_dict['NWEBcss']
self.noid = options.handler.options_dict['NWEBnoid']
self.linkhome = options.handler.options_dict['NWEBlinkhome']
self.showbirth = options.handler.options_dict['NWEBshowbirth']
self.showdeath = options.handler.options_dict['NWEBshowdeath']
self.showspouse = options.handler.options_dict['NWEBshowspouse']
self.showparents = options.handler.options_dict['NWEBshowparents']
self.showhalfsiblings = options.handler.options_dict['NWEBshowhalfsiblings']
self.use_intro = options.handler.options_dict['NWEBintronote'] != u""
self.use_contact = options.handler.options_dict['NWEBcontact'] != u""
self.use_gallery = options.handler.options_dict['NWEBgallery']
@ -322,6 +328,16 @@ class BasePage:
msg = _('Generated by <a href="http://gramps-project.org">'
'GRAMPS</a> on %(date)s') % { 'date' : value }
if self.linkhome:
home_person_handle = db.get_default_handle()
if home_person_handle:
home_person = db.get_default_person()
home_person_url = self.build_name(
self.build_path(home_person_handle, "ppl", up),
home_person.handle)
home_person_name = home_person.get_primary_name().get_regular_name()
msg += _('<br>for <a href="%s">%s</a>') % (home_person_url, home_person_name)
of.write('<div class="navbyline">%s</div>\n' % msg)
of.write('<h1 class="navtitle">%s</h1>\n' % self.title_str)
of.write('<div class="nav">\n')
@ -605,37 +621,123 @@ class IndividualListPage(BasePage):
of.write('<table class="infolist">\n<thead><tr>\n')
of.write('<th>%s</th>\n' % _('Surname'))
of.write('<th>%s</th>\n' % _('Name'))
of.write('<th>%s</th>\n' % _('Birth date'))
column_count = 2
if self.showbirth:
of.write('<th>%s</th>\n' % _('Birth'))
column_count += 1
if self.showdeath:
of.write('<th>%s</th>\n' % _('Death'))
column_count += 1
if self.showspouse:
of.write('<th>%s</th>\n' % _('Partner'))
column_count += 1
if self.showparents:
of.write('<th>%s</th>\n' % _('Parents'))
column_count += 1
of.write('</tr></thead>\n<tbody>\n')
person_handle_list = sort_people(db,person_handle_list)
for (surname,handle_list) in person_handle_list:
first = True
of.write('<tr><td colspan="2">&nbsp;</td></tr>\n')
of.write('<tr><td colspan="%d">&nbsp;</td></tr>\n' % column_count)
for person_handle in handle_list:
person = db.get_person_from_handle(person_handle)
if self.exclude_private:
person = ReportUtils.sanitize_person(db,person)
# surname column
of.write('<tr><td class="category">')
if first:
of.write('<a name="%s">%s</a>' % (self.lnkfmt(surname),surname))
else:
of.write('&nbsp;')
of.write('</td><td class="data">')
of.write('</td>')
# firstname column
of.write('<td class="data">')
path = self.build_path(person.handle,"ppl",False)
self.person_link(of, self.build_name(path,person.handle),
_nd.display_given(person), person.gramps_id,False)
of.write('</td><td class="field">')
of.write('</td>')
if person.handle in restrict_list:
of.write(_('restricted'))
else:
birth_ref = person.get_birth_ref()
if birth_ref:
birth = db.get_event_from_handle(birth_ref.ref)
of.write(_dd.display(birth.get_date_object()))
of.write('</td></tr>\n')
# birth column
if self.showbirth:
of.write('<td class="field">')
if person.handle in restrict_list:
of.write(_('restricted'))
else:
birth_ref = person.get_birth_ref()
if birth_ref:
birth = db.get_event_from_handle(birth_ref.ref)
of.write(_dd.display(birth.get_date_object()))
of.write('</td>')
# death column
if self.showdeath:
of.write('<td class="field">')
if person.handle in restrict_list:
of.write(_('restricted'))
else:
death_ref = person.get_death_ref()
if death_ref:
death = db.get_event_from_handle(death_ref.ref)
of.write(_dd.display(death.get_date_object()))
of.write('</td>')
# spouse (partner) column
if self.showspouse:
of.write('<td class="field">')
if person.handle in restrict_list:
of.write(_('restricted'))
else:
family_list = person.get_family_handle_list()
first_family = True
spouse_name = None
if family_list:
for family_handle in family_list:
family = db.get_family_from_handle(family_handle)
spouse_id = ReportUtils.find_spouse(person, family)
if spouse_id:
spouse = db.get_person_from_handle(spouse_id)
if self.exclude_private:
spouse = ReportUtils.sanitize_person(db, spouse)
spouse_name = spouse.get_primary_name().get_regular_name()
if not first_family:
of.write(', ')
of.write('%s' % spouse_name)
first_family = False
of.write('</td>')
# parents column
if self.showparents:
of.write('<td class="field">')
parent_handle_list = person.get_parent_family_handle_list()
if parent_handle_list:
parent_handle = parent_handle_list[0]
family = db.get_family_from_handle(parent_handle)
father_name = ''
mother_name = ''
father_id = family.get_father_handle()
mother_id = family.get_mother_handle()
father = db.get_person_from_handle(father_id)
mother = db.get_person_from_handle(mother_id)
if father and self.exclude_private:
father = ReportUtils.sanitize_person(db, father)
father_name = father.get_primary_name().get_regular_name()
if mother and self.exclude_private:
mother = ReportUtils.sanitize_person(db, mother)
mother_name = mother.get_primary_name().get_regular_name()
if mother and father:
of.write('%s, %s' % (father_name, mother_name))
elif mother:
of.write('%s' % mother_name)
elif father:
of.write('%s' % father_name)
of.write('</td>')
# finished writing all columns
of.write('</tr>\n')
first = False
of.write('</tbody>\n</table>\n')
@ -665,10 +767,19 @@ class SurnamePage(BasePage):
of.write('<p>%s</p>\n' % msg)
of.write('<table class="infolist">\n<thead><tr>\n')
of.write('<th>%s</th>\n' % _('Name'))
of.write('<th>%s</th>\n' % _('Birth date'))
if self.showbirth:
of.write('<th>%s</th>\n' % _('Birth'))
if self.showdeath:
of.write('<th>%s</th>\n' % _('Death'))
if self.showspouse:
of.write('<th>%s</th>\n' % _('Partner'))
if self.showparents:
of.write('<th>%s</th>\n' % _('Parents'))
of.write('</tr></thead>\n<tbody>\n')
for person_handle in person_handle_list:
# firstname column
person = db.get_person_from_handle(person_handle)
if self.exclude_private:
person = ReportUtils.sanitize_person(db,person)
@ -677,16 +788,85 @@ class SurnamePage(BasePage):
self.person_link(of, self.build_name(path,person.handle),
person.get_primary_name().get_first_name(),
person.gramps_id,False)
of.write('</td><td class="field">')
if person.handle in restrict_list:
of.write(_('restricted'))
else:
birth_ref = person.get_birth_ref()
if birth_ref:
birth = db.get_event_from_handle(birth_ref.ref)
birth_date = _dd.display(birth.get_date_object())
of.write(birth_date)
of.write('</td></tr>\n')
of.write('</td>')
# birth column
if self.showbirth:
of.write('<td class="field">')
if person.handle in restrict_list:
of.write(_('restricted'))
else:
birth_ref = person.get_birth_ref()
if birth_ref:
birth = db.get_event_from_handle(birth_ref.ref)
of.write(_dd.display(birth.get_date_object()))
of.write('</td>')
# death column
if self.showdeath:
of.write('<td class="field">')
if person.handle in restrict_list:
of.write(_('restricted'))
else:
death_ref = person.get_death_ref()
if death_ref:
death = db.get_event_from_handle(death_ref.ref)
of.write(_dd.display(death.get_date_object()))
of.write('</td>')
# spouse (partner) column
if self.showspouse:
of.write('<td class="field">')
if person.handle in restrict_list:
of.write(_('restricted'))
else:
family_list = person.get_family_handle_list()
first_family = True
spouse_name = None
if family_list:
for family_handle in family_list:
family = db.get_family_from_handle(family_handle)
spouse_id = ReportUtils.find_spouse(person, family)
if spouse_id:
spouse = db.get_person_from_handle(spouse_id)
if self.exclude_private:
spouse = ReportUtils.sanitize_person(db, spouse)
spouse_name = spouse.get_primary_name().get_regular_name()
if not first_family:
of.write(', ')
of.write('%s' % spouse_name)
first_family = False
of.write('</td>')
# parents column
if self.showparents:
of.write('<td class="field">')
parent_handle_list = person.get_parent_family_handle_list()
if parent_handle_list:
parent_handle = parent_handle_list[0]
family = db.get_family_from_handle(parent_handle)
father_name = ''
mother_name = ''
father_id = family.get_father_handle()
mother_id = family.get_mother_handle()
father = db.get_person_from_handle(father_id)
mother = db.get_person_from_handle(mother_id)
if father and self.exclude_private:
father = ReportUtils.sanitize_person(db, father)
father_name = father.get_primary_name().get_regular_name()
if mother and self.exclude_private:
mother = ReportUtils.sanitize_person(db, mother)
mother_name = mother.get_primary_name().get_regular_name()
if mother and father:
of.write('%s, %s' % (father_name, mother_name))
elif mother:
of.write('%s' % mother_name)
elif father:
of.write('%s' % father_name)
of.write('</td>')
# finished writing all columns
of.write('</tr>\n')
of.write('<tbody>\n</table>\n')
self.display_footer(of,db)
self.close_file(of)
@ -1100,7 +1280,7 @@ class IntroductionPage(BasePage):
of.write('</div>\n')
except (IOError,OSError),msg:
WarningDialog(_("Could not add photo to page"),str(msg))
notelist = obj.get_note_list()
if notelist:
note_obj = db.get_note_from_handle(notelist[0])
@ -1109,7 +1289,7 @@ class IntroductionPage(BasePage):
of.write('<pre>\n%s\n</pre>\n' % text)
else:
of.write('<p>')
of.write('</p><p>'.join(text.split('\n')))
of.write('<br>'.join(text.split('\n')))
of.write('</p>')
self.display_footer(of,db)
@ -1400,7 +1580,7 @@ class ContactPage(BasePage):
if format:
text = u"<pre>%s</pre>" % text
else:
text = u"</p><p>".join(text.split("\n"))
text = u"<br>".join(text.split("\n"))
of.write('<p>%s</p>\n' % text)
of.write('</div>\n')
@ -1849,6 +2029,7 @@ class IndividualPage(BasePage):
# Get the mother and father relationships
frel = ""
mrel = ""
sibling = set()
child_handle = self.person.get_handle()
child_ref_list = ReportUtils.sanitize_list( family.get_child_ref_list(),
self.exclude_private )
@ -1872,6 +2053,7 @@ class IndividualPage(BasePage):
of.write('<tr>\n')
self.display_parent(of,mother_handle,_('Mother'),mrel)
of.write('</tr>\n')
first = False
if len(child_ref_list) > 1:
of.write('<tr>\n')
@ -1879,9 +2061,53 @@ class IndividualPage(BasePage):
of.write('<td class="data">\n')
for child_ref in child_ref_list:
child_handle = child_ref.ref
sibling.add(child_handle) # remember that we've already "seen" this child
if child_handle != self.person.handle:
self.display_child_link(of,child_handle)
of.write('</td>\n</tr>\n')
# Also try to identify half-siblings
other_siblings = set()
# if we have a known father...
if father_handle and self.showhalfsiblings:
# 1) get all of the families in which this father is involved
# 2) get all of the children from those families
# 3) if the children are not already listed as siblings...
# 4) then remember those children since we're going to list them
father = self.db.get_person_from_handle(father_handle)
for family_handle in father.get_family_handle_list():
family = self.db.get_family_from_handle(family_handle)
step_child_ref_list = ReportUtils.sanitize_list(family.get_child_ref_list(), self.exclude_private)
for step_child_ref in step_child_ref_list:
step_child_handle = step_child_ref.ref
if step_child_handle not in sibling:
if step_child_handle != self.person.handle:
# we have a new step/half sibling
other_siblings.add(step_child_ref.ref)
# do the same thing with the mother (see "father" just above):
if mother_handle and self.showhalfsiblings:
mother = self.db.get_person_from_handle(mother_handle)
for family_handle in mother.get_family_handle_list():
family = self.db.get_family_from_handle(family_handle)
step_child_ref_list = ReportUtils.sanitize_list(family.get_child_ref_list(), self.exclude_private)
for step_child_ref in step_child_ref_list:
step_child_handle = step_child_ref.ref
if step_child_handle not in sibling:
if step_child_handle != self.person.handle:
# we have a new step/half sibling
other_siblings.add(step_child_ref.ref)
# now that we have all of the step-siblings/half-siblings, print them out
if len(other_siblings) > 0:
of.write('<tr>\n')
of.write('<td class="field">%s</td>\n' % _("Half Siblings"))
of.write('<td class="data">\n')
for child_handle in other_siblings:
self.display_child_link(of, child_handle)
of.write('</td>\n</tr>\n')
of.write('<tr><td colspan="3">&nbsp;</td></tr>\n')
of.write('</table>\n')
of.write('</div>\n')
@ -1986,7 +2212,7 @@ class IndividualPage(BasePage):
if format:
of.write( u"<pre>%s</pre>" % text )
else:
of.write( u"</p><p>".join(text.split("\n")))
of.write( u"<br>".join(text.split("\n")))
of.write('</td>\n</tr>\n')
def pedigree_person(self,of,person,is_spouse=False):
@ -2059,6 +2285,22 @@ class IndividualPage(BasePage):
else:
text = '\n'
text += self.get_citation_links( event.get_source_references() )
# if the event has a note attached to it, get the text and format it correctly
notelist = event.get_note_list()
for notehandle in notelist:
nobj = self.db.get_note_from_handle(notehandle)
if nobj:
note_text = nobj.get(markup=True)
format = nobj.get_format()
if note_text:
if format:
text += u"<pre>%s</pre>" % note_text
else:
text += u"<p>"
text += u"<br>".join(note_text.split("\n"))
text += u"</p>"
return text
def get_citation_links(self, source_ref_list):
@ -2123,6 +2365,12 @@ class WebReport(Report):
NWEBintronote
NWEBhomenote
NWEBnoid
NWEBlinkhome
NWEBshowbirth
NWEBshowdeath
NWEBshowspouse
NWEBshowparents
NWEBshowhalfsiblings
"""
self.database = database
@ -2142,6 +2390,12 @@ class WebReport(Report):
self.restrict_years = options.handler.options_dict['NWEBrestrictyears']
self.exclude_private = not options.handler.options_dict['NWEBincpriv']
self.noid = options.handler.options_dict['NWEBnoid']
self.linkhome = options.handler.options_dict['NWEBlinkhome']
self.showbirth = options.handler.options_dict['NWEBshowbirth']
self.showdeath = options.handler.options_dict['NWEBshowdeath']
self.showspouse = options.handler.options_dict['NWEBshowspouse']
self.showparents = options.handler.options_dict['NWEBshowparents']
self.showhalfsiblings = options.handler.options_dict['NWEBshowhalfsiblings']
self.title = options.handler.options_dict['NWEBtitle']
self.sort = Sort.Sort(self.database)
self.inc_gallery = options.handler.options_dict['NWEBgallery']
@ -2298,7 +2552,10 @@ class WebReport(Report):
def person_pages(self, ind_list, restrict_list, place_list, source_list, archive):
self.progress.set_pass(_('Creating individual pages'),len(ind_list))
self.progress.set_pass(_('Creating individual pages'),len(ind_list) + 1)
self.progress.step() # otherwise the progress indicator sits at 100%
# for a short while from the last step we did,
# which was to apply the privacy filter
IndividualListPage(
self.database, self.title, ind_list, restrict_list,
@ -2459,6 +2716,12 @@ class WebReportOptions(ReportOptions):
'NWEBincpriv' : 0,
'NWEBnonames' : 0,
'NWEBnoid' : 0,
'NWEBlinkhome' : 0,
'NWEBshowbirth' : 1,
'NWEBshowdeath' : 0,
'NWEBshowspouse' : 0,
'NWEBshowparents' : 0,
'NWEBshowhalfsiblings' : 0,
'NWEBcontact' : '',
'NWEBgallery' : 1,
'NWEBheader' : '',
@ -2537,6 +2800,24 @@ class WebReportOptions(ReportOptions):
self.inc_download = gtk.CheckButton(download_msg)
self.inc_download.set_active(self.options_dict['NWEBdownload'])
self.linkhome = gtk.CheckButton(_('Include link to home person on every page'))
self.linkhome.set_active(self.options_dict['NWEBlinkhome'])
self.showbirth = gtk.CheckButton(_('Include a column for birth dates on the index pages'))
self.showbirth.set_active(self.options_dict['NWEBshowbirth'])
self.showdeath = gtk.CheckButton(_('Include a column for death dates on the index pages'))
self.showdeath.set_active(self.options_dict['NWEBshowdeath'])
self.showspouse = gtk.CheckButton(_('Include a column for partners on the index pages'))
self.showspouse.set_active(self.options_dict['NWEBshowspouse'])
self.showparents = gtk.CheckButton(_('Include a column for parents on the index pages'))
self.showparents.set_active(self.options_dict['NWEBshowparents'])
self.showhalfsiblings = gtk.CheckButton(_('Include half-brothers and half-sisters as siblings'))
self.showhalfsiblings.set_active(self.options_dict['NWEBshowhalfsiblings'])
# FIXME: document this:
# 0 -- no images of any kind
# 1 -- no living images, but some images
@ -2604,7 +2885,6 @@ class WebReportOptions(ReportOptions):
title = _("Page Generation")
media_list = [['','']]
html_list = [['','']]
@ -2644,6 +2924,14 @@ class WebReportOptions(ReportOptions):
dialog.add_frame_option(title,None,self.restrict_living)
dialog.add_frame_option(title,None,self.hbox)
title = _("Advanced Options")
dialog.add_frame_option(title,None,self.linkhome,)
dialog.add_frame_option(title,None,self.showbirth)
dialog.add_frame_option(title,None,self.showdeath)
dialog.add_frame_option(title,None,self.showspouse)
dialog.add_frame_option(title,None,self.showparents)
dialog.add_frame_option(title,None,self.showhalfsiblings)
def restrict_toggled(self,obj):
self.restrict_years.set_sensitive(obj.get_active())
@ -2657,6 +2945,12 @@ class WebReportOptions(ReportOptions):
self.options_dict['NWEBincpriv'] = int(not self.no_private.get_active())
self.options_dict['NWEBnoid'] = int(self.noid.get_active())
self.options_dict['NWEBcontact'] = unicode(self.contact.get_handle())
self.options_dict['NWEBlinkhome'] = int(self.linkhome.get_active())
self.options_dict['NWEBshowbirth'] = int(self.showbirth.get_active())
self.options_dict['NWEBshowdeath'] = int(self.showdeath.get_active())
self.options_dict['NWEBshowspouse'] = int(self.showspouse.get_active())
self.options_dict['NWEBshowparents'] = int(self.showparents.get_active())
self.options_dict['NWEBshowhalfsiblings'] = int(self.showhalfsiblings.get_active())
self.options_dict['NWEBgallery'] = int(self.include_gallery.get_active())
self.options_dict['NWEBheader'] = unicode(self.header.get_handle())
self.options_dict['NWEBfooter'] = unicode(self.footer.get_handle())