From a8a59c9f7c2ea5c99353fe1c4c361ca32194fdbd Mon Sep 17 00:00:00 2001 From: Kees Bakker Date: Thu, 13 Mar 2008 22:28:22 +0000 Subject: [PATCH] Major reorganisation of NarrativeWeb.py Pass instance of NavWebReport down to BasePage instead of doing it by many function arguments. There are still a few "TODO" and "FIXME" notes in the code. At least one test succeeded to create exactly the same HTML output. One test, what more do you need? Pylint reports rating of 8.01/10, but I'm sure I can do better :-) * src/plugins/NarrativeWeb.py svn: r10295 --- src/plugins/NarrativeWeb.py | 682 +++++++++++++++++------------------- 1 file changed, 316 insertions(+), 366 deletions(-) diff --git a/src/plugins/NarrativeWeb.py b/src/plugins/NarrativeWeb.py index 8bf5ead67..584334dc5 100644 --- a/src/plugins/NarrativeWeb.py +++ b/src/plugins/NarrativeWeb.py @@ -207,22 +207,19 @@ class BasePage: This the base class to write certain HTML pages. """ - def __init__(self, title, options, archive, photo_list, gid): + def __init__(self, report, title, gid=None): """ + report - instance of NavWebReport title - text for the tag - options - dictionary with the options - archive - an open tar archive (if not None) to write the file to - photo_list - TODO describe gid - Gramps ID """ + self.report = report self.title_str = title self.gid = gid - self.options = options - self.archive = archive + self.src_list = {} + self.page_title = "" - self.warn_dir = True - self.cur_name = None # Internal use. The name of the output file, to be used for the tar archive. self.author = get_researcher().get_name() if self.author: @@ -232,6 +229,7 @@ class BasePage: # TODO. All of these attributes are not necessary, because we have # also the options in self.options. Besides, we need to check which # are still required. + options = report.options self.inc_download = options['incdownload'] self.html_dir = options['target'] self.copyright = options['cright'] @@ -252,7 +250,6 @@ class BasePage: self.use_gallery = options['gallery'] self.header = options['headernote'] self.footer = options['footernote'] - self.photo_list = photo_list self.usegraph = options['graph'] self.graphgens = options['graphgens'] self.use_home = options['homenote'] != "" or \ @@ -262,11 +259,13 @@ class BasePage: handle = photo.get_handle() if store_ref: lnk = (self.cur_fname, self.page_title, self.gid) - if handle in self.photo_list: - if lnk not in self.photo_list[handle]: - self.photo_list[handle].append(lnk) + # FIXME. Is it OK to add to the photo_list of report? + photo_list = self.report.photo_list + if handle in photo_list: + if lnk not in photo_list[handle]: + photo_list[handle].append(lnk) else: - self.photo_list[handle] = [lnk] + photo_list[handle] = [lnk] ext = os.path.splitext(photo.get_path())[1] real_path = "%s/%s" % (self.build_path('images', handle), handle+ext) @@ -275,7 +274,7 @@ class BasePage: def create_file(self, name): self.cur_fname = name + self.ext - if self.archive: + if self.report.archive: self.string_io = StringIO() of = codecs.EncodedFile(self.string_io, 'utf-8', self.encoding, 'xmlcharrefreplace') @@ -311,7 +310,7 @@ class BasePage: 0/2/02c0d8f888f566ae95ffbdca64274b51 """ self.cur_fname = self.link_path(path, name) - if self.archive: + if self.report.archive: self.string_io = StringIO() of = codecs.EncodedFile(self.string_io, 'utf-8', self.encoding, 'xmlcharrefreplace') @@ -326,7 +325,7 @@ class BasePage: return of def close_file(self, of): - if self.archive: + if self.report.archive: tarinfo = tarfile.TarInfo(self.cur_fname) tarinfo.size = len(self.string_io.getvalue()) tarinfo.mtime = time.time() @@ -334,7 +333,7 @@ class BasePage: tarinfo.uid = os.getuid() tarinfo.gid = os.getgid() self.string_io.seek(0) - self.archive.addfile(tarinfo, self.string_io) + self.report.archive.addfile(tarinfo, self.string_io) of.close() else: of.close() @@ -344,11 +343,11 @@ class BasePage: """This creates an MD5 hex string to be used as filename.""" return md5.new(text).hexdigest() - def display_footer(self, of, db): + def display_footer(self, of): of.write('</div>\n\n') of.write('<div id="footer">\n') if self.footer: - note = db.get_note_from_gramps_id(self.footer) + note = self.report.database.get_note_from_gramps_id(self.footer) of.write('\t<div id="user_footer">\n') of.write('\t\t<p>') of.write(note.get()) @@ -379,7 +378,7 @@ class BasePage: of.write('</body>\n') of.write('</html>') - def display_header(self, of, db, title): + def display_header(self, of, title): if self.up: path = "../../.." else: @@ -426,6 +425,7 @@ class BasePage: msg = _('Generated by <a href="http://gramps-project.org">' 'GRAMPS</a> on %(date)s') % { 'date' : value } + db = self.report.database if self.linkhome: home_person = db.get_default_person() if home_person: @@ -555,12 +555,12 @@ class BasePage: cs = cs and ' id="CurrentSection"' or '' of.write('\t\t<li%s><a href="%s%s">%s</a></li>\n' % (cs, lpath, self.ext, title)) - def display_first_image_as_thumbnail( self, of, db, photolist=None): + def display_first_image_as_thumbnail( self, of, photolist=None): if not photolist or not self.use_gallery: return photo_handle = photolist[0].get_reference_handle() - photo = db.get_object_from_handle(photo_handle) + photo = self.report.database.get_object_from_handle(photo_handle) mime_type = photo.get_mime_type() if mime_type: @@ -578,16 +578,19 @@ class BasePage: of.write('\t</div>\n\n') lnk = (self.cur_fname, self.page_title, self.gid) - if photo_handle in self.photo_list: - if lnk not in self.photo_list[photo_handle]: - self.photo_list[photo_handle].append(lnk) + # 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: - self.photo_list[photo_handle] = [lnk] + photo_list[photo_handle] = [lnk] - def display_additional_images_as_gallery( self, of, db, photolist=None): + def display_additional_images_as_gallery( self, of, photolist=None): if not photolist or not self.use_gallery: return + db = self.report.database of.write('\t<div id="indivgallery" class="subsection">\n') of.write('\t\t<h4>%s</h4>\n' % _('Gallery')) for mediaref in photolist: @@ -610,21 +613,24 @@ class BasePage: self.doc_link(of, photo_handle, descr, up=True) lnk = (self.cur_fname, self.page_title, self.gid) - if photo_handle in self.photo_list: - if lnk not in self.photo_list[photo_handle]: - self.photo_list[photo_handle].append(lnk) + # 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: - self.photo_list[photo_handle] = [lnk] + photo_list[photo_handle] = [lnk] except (IOError, OSError), msg: WarningDialog(_("Could not add photo to page"), str(msg)) of.write('\t\t<div class="fullclear"></div>\n') of.write('\t</div>\n\n') - def display_note_list(self, of, db, notelist=None): + def display_note_list(self, of, notelist=None): if not notelist: return + db = self.report.database for notehandle in notelist: note = db.get_note_from_handle(notehandle) format = note.get_format() @@ -672,10 +678,13 @@ class BasePage: # Probably only used in IndividualPage.display_ind_sources # and MediaPage.display_media_sources - def display_source_refs(self, of, db, bibli): + def display_source_refs(self, of): + bibli = self.bibli + if bibli.get_citation_count() == 0: return + db = self.report.database of.write('\t<div id="sourcerefs" class="subsection">\n') of.write('\t\t<h4>%s</h4>\n' % _('Source References')) of.write('\t\t<ol>\n') @@ -725,7 +734,7 @@ class BasePage: of.write('\t\t</ol>\n') of.write('\t</div>\n\n') - def display_references(self, of, db, handlelist): + def display_references(self, of, handlelist): if not handlelist: return @@ -746,9 +755,9 @@ class BasePage: of.write('\t\t</ol>\n') of.write('\t</div>\n') - def person_link(self, of, path, name, gid=""): + def person_link(self, of, path, name, gid=None): of.write('<a href="%s">%s' % (path, name)) - if not self.noid and gid != "": + if not self.noid and gid: of.write(' <span class="grampsid">[%s]</span>' % gid) of.write('</a>') @@ -812,19 +821,14 @@ class BasePage: retval = retval + ' <span class="grampsid">[%s]</span>' % gid return retval + '</a>' -#------------------------------------------------------------------------ -# -# -# -#------------------------------------------------------------------------ class IndividualListPage(BasePage): - def __init__(self, db, title, person_handle_list, - options, archive, media_list): - BasePage.__init__(self, title, options, archive, media_list, "") + def __init__(self, report, title, person_handle_list): + BasePage.__init__(self, report, title) + db = report.database of = self.create_file("individuals") - self.display_header(of, db, _('Individuals')) + self.display_header(of, _('Individuals')) msg = _("This page contains an index of all the individuals in the " "database, sorted by their last names. Selecting the person’s " @@ -953,23 +957,20 @@ class IndividualListPage(BasePage): of.write('\t</tbody>\n') of.write('\t</table>\n') - self.display_footer(of, db) + + self.display_footer(of) self.close_file(of) -#------------------------------------------------------------------------ -# -# -# -#------------------------------------------------------------------------ class SurnamePage(BasePage): - def __init__(self, db, title, person_handle_list, options, archive, media_list): + def __init__(self, report, title, person_handle_list): - BasePage.__init__(self, title, options, archive, media_list, "") + BasePage.__init__(self, report, title) + db = report.database of = self.create_link_file('srn', self.lnkfmt(title)) self.up = True - self.display_header(of, db, title) + self.display_header(of, title) msg = _("This page contains an index of all the individuals in the " "database with the surname of %s. Selecting the person’s name " @@ -1080,22 +1081,20 @@ class SurnamePage(BasePage): of.write('\t\t</tr>\n') of.write('\t</tbody>\n') of.write('\t</table>\n') - self.display_footer(of, db) + + self.display_footer(of) self.close_file(of) -#------------------------------------------------------------------------ -# -# -# -#------------------------------------------------------------------------ class PlaceListPage(BasePage): - def __init__(self, db, title, place_handles, src_list, options, archive, - media_list): - BasePage.__init__(self, title, options, archive, media_list, "") + 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.create_file("places") - self.display_header(of, db, _('Places')) + self.display_header(of, _('Places')) msg = _("This page contains an index of all the places in the " "database, sorted by their title. Clicking on a place’s " @@ -1113,9 +1112,9 @@ class PlaceListPage(BasePage): of.write('\t</thead>\n') of.write('\t<tbody>\n\n') - self.sort = Sort.Sort(db) + sort = Sort.Sort(db) handle_list = place_handles.keys() - handle_list.sort(self.sort.by_place_title) + handle_list.sort(sort.by_place_title) last_letter = '' for handle in handle_list: @@ -1145,29 +1144,25 @@ class PlaceListPage(BasePage): of.write('\t</tbody>\n') of.write('\t</table>\n') - self.display_footer(of, db) + + self.display_footer(of) self.close_file(of) -#------------------------------------------------------------------------ -# -# -# -#------------------------------------------------------------------------ class PlacePage(BasePage): - def __init__(self, db, title, place_handle, src_list, place_list, options, - archive, media_list): - place = db.get_place_from_handle( place_handle) - BasePage.__init__(self, title, options, archive, media_list, - place.gramps_id) + def __init__(self, report, title, place_handle, src_list, place_list): + db = report.database + 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.create_link_file('plc', place.get_handle()) self.page_title = ReportUtils.place_name(db, place_handle) self.up = True - self.display_header(of, db, "%s - %s" % (_('Places'), self.page_title)) + self.display_header(of, "%s - %s" % (_('Places'), self.page_title)) media_list = place.get_media_list() - self.display_first_image_as_thumbnail(of, db, media_list) + self.display_first_image_as_thumbnail(of, media_list) of.write('\t<h2>Places:</h2>\n') of.write('\t<h3>%s</h3>\n\n' % html_escape(self.page_title.strip())) @@ -1211,29 +1206,26 @@ class PlacePage(BasePage): of.write('\t</div>\n') if self.use_gallery: - self.display_additional_images_as_gallery(of, db, media_list) - self.display_note_list(of, db, place.get_note_list()) + self.display_additional_images_as_gallery(of, media_list) + self.display_note_list(of, place.get_note_list()) self.display_url_list(of, place.get_url_list()) - self.display_references(of, db, place_list[place.handle]) - self.display_footer(of, db) + self.display_references(of, place_list[place.handle]) + + self.display_footer(of) self.close_file(of) -#------------------------------------------------------------------------ -# -# -# -#------------------------------------------------------------------------ class MediaPage(BasePage): - def __init__(self, db, title, handle, src_list, options, archive, media_list, info): - + def __init__(self, report, title, handle, src_list, my_media_list, info): (prev, next, page_number, total_pages) = info + db = report.database photo = db.get_object_from_handle(handle) - BasePage.__init__(self, title, options, archive, media_list, photo.gramps_id) + # TODO. How do we pass my_media_list down for use in BasePage? + BasePage.__init__(self, report, title, photo.gramps_id) of = self.create_link_file('img', handle) - self.db = db self.src_list = src_list + self.bibli = Bibliography() mime_type = photo.get_mime_type() @@ -1248,7 +1240,7 @@ class MediaPage(BasePage): self.copy_thumbnail(handle, photo) self.page_title = photo.get_description() self.up = True - self.display_header(of, db, "%s - %s" % (_('Gallery'), self.page_title)) + self.display_header(of, "%s - %s" % (_('Gallery'), self.page_title)) of.write('\t<h2>%s:</h2>\n' % _('Gallery')) @@ -1276,7 +1268,7 @@ class MediaPage(BasePage): # and provide zoom-in/zoom-out functionality when the image # is displayed directly (width, height) = ImgManip.image_size( - Utils.media_path_full(self.db, photo.get_path())) + Utils.media_path_full(db, photo.get_path())) scale = 1.0 of.write('\t\t\t') if width > _MAX_IMG_WIDTH or height > _MAX_IMG_HEIGHT: @@ -1287,7 +1279,7 @@ class MediaPage(BasePage): of.write('<a href="../../../%s">' % newpath) of.write('<img width="%d" height="%d" src="../../../%s" alt="%s" />' % (width, height, newpath, html_escape(self.page_title))) if scale != 1.0: - of.write('</a>'); + of.write('</a>') of.write('\n') else: @@ -1299,12 +1291,12 @@ class MediaPage(BasePage): dirname = tempfile.mkdtemp() thmb_path = os.path.join(dirname, "temp.png") if ThumbNails.run_thumbnailer(mime_type, - Utils.media_path_full(self.db, + Utils.media_path_full(db, photo.get_path()), thmb_path, 320): try: path = "%s/%s.png" % (self.build_path("preview", photo.handle), photo.handle) - self.store_file(archive, self.html_dir, thmb_path, path) + self.report.store_file(thmb_path, path) os.unlink(thmb_path) except IOError: path = os.path.join('images', 'document.png') @@ -1335,32 +1327,35 @@ class MediaPage(BasePage): of.write('\t\t\t\t<td class="ColumnAttribute">%s</td>\n' % _('GRAMPS ID')) of.write('\t\t\t\t<td class="ColumnValue">%s</td>\n' % photo.gramps_id) of.write('\t\t\t</tr>\n') + if not note_only and not mime_type.startswith("image/"): of.write('\t\t\t<tr>\n') of.write('\t\t\t\t<td class="ColumnAttribute">%s</td>\n' % _('File type')) of.write('\t\t\t\t<td class="ColumnValue">%s</td>\n' % Mime.get_description(mime_type)) of.write('\t\t\t</tr>\n') + date = _dd.display(photo.get_date_object()) if date != "": of.write('\t\t\t<tr>\n') of.write('\t\t\t\t<td class="ColumnAttribute">%s</td>\n' % _('Date')) of.write('\t\t\t\t<td class="ColumnValue">%s</td>\n' % date) of.write('\t\t\t</tr>\n') + of.write('\t\t</table>\n') of.write('\t</div>\n\n') - self.display_note_list(of, db, photo.get_note_list()) + self.display_note_list(of, photo.get_note_list()) self.display_attr_list(of, photo.get_attribute_list()) - self.display_media_sources(of, db, photo) - self.display_references(of, db, media_list) - self.display_footer(of, db) + self.display_media_sources(of, photo) + self.display_references(of, media_list) + + self.display_footer(of) self.close_file(of) - def display_media_sources(self, of, db, photo): - self.bibli = Bibliography() + def display_media_sources(self, of, photo): for sref in photo.get_source_references(): self.bibli.add_reference(sref) - self.display_source_refs(of, db, self.bibli) + self.display_source_refs(of) def display_attr_list(self, of, attrlist=None): if not attrlist: @@ -1383,10 +1378,11 @@ class MediaPage(BasePage): to_dir = self.build_path('images', handle) newpath = to_dir + "/" + handle + ext - fullpath = Utils.media_path_full(self.db, photo.get_path()) + db = self.report.database + fullpath = Utils.media_path_full(db, photo.get_path()) try: - if self.archive: - self.archive.add(fullpath, str(newpath)) + if self.report.archive: + self.report.archive.add(fullpath, str(newpath)) else: to_dir = os.path.join(self.html_dir, to_dir) if not os.path.isdir(to_dir): @@ -1404,8 +1400,9 @@ class MediaPage(BasePage): to_dir = self.build_path('thumb', handle) to_path = os.path.join(to_dir, handle+".png") if photo.get_mime_type(): + db = self.report.database from_path = ThumbNails.get_thumbnail_path(Utils.media_path_full( - self.db, + db, photo.get_path()), photo.get_mime_type()) if not os.path.isfile(from_path): @@ -1413,8 +1410,9 @@ class MediaPage(BasePage): else: from_path = os.path.join(const.IMAGE_DIR, "document.png") - if self.archive: - self.archive.add(from_path, to_path) + # FIXME. Why not use copy_file()? + if self.report.archive: + self.report.archive.add(from_path, to_path) else: to_dir = os.path.join(self.html_dir, to_dir) dest = os.path.join(self.html_dir, to_path) @@ -1433,17 +1431,17 @@ class MediaPage(BasePage): class SurnameListPage(BasePage): ORDER_BY_NAME = 0 ORDER_BY_COUNT = 1 - def __init__(self, db, title, person_handle_list, options, archive, - media_list, order_by=ORDER_BY_NAME, filename="surnames"): - BasePage.__init__(self, title, options, archive, media_list, "") + 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.create_file(filename) - self.display_header(of, db, _('Surnames')) + self.display_header(of, _('Surnames')) of.write('\t<h2>%s</h2>\n' % _('Surnames')) else: of = self.create_file("surnames_count") - self.display_header(of, db, _('Surnames by person count')) + self.display_header(of, _('Surnames by person count')) of.write('\t<h2>%s</h2>\n' % _('Surnames by person count')) of.write('\t<p id="description">%s</p>\n' % _( @@ -1513,38 +1511,33 @@ class SurnameListPage(BasePage): of.write('\t</tbody>\n') of.write('\t</table>\n') - self.display_footer(of, db) - self.close_file(of) - return -#------------------------------------------------------------------------ -# -# -# -#------------------------------------------------------------------------ + self.display_footer(of) + self.close_file(of) + class IntroductionPage(BasePage): - def __init__(self, db, title, options, archive, media_list): - BasePage.__init__(self, title, options, archive, media_list, "") + def __init__(self, report, title): + BasePage.__init__(self, report, title) + db = report.database if self.use_home: of = self.create_file("introduction") else: of = self.create_file("index") - self.display_header(of, db, _('Introduction')) + self.display_header(of, _('Introduction')) of.write('\t<h2>%s</h2>\n' % _('Introduction')) - pic_id = options['introimg'] + pic_id = report.options['introimg'] if pic_id: obj = db.get_object_from_gramps_id(pic_id) mime_type = obj.get_mime_type() if mime_type and mime_type.startswith("image"): try: (newpath, thumb_path) = self.copy_media(obj, False) - self.store_file(archive, self.html_dir, - Utils.media_path_full(db, - obj.get_path()), + self.report.store_file(Utils.media_path_full(db, + obj.get_path()), newpath) of.write('\t<img ') of.write('src="%s" ' % newpath) @@ -1552,7 +1545,7 @@ class IntroductionPage(BasePage): except (IOError, OSError), msg: WarningDialog(_("Could not add photo to page"), str(msg)) - note_id = options['intronote'] + note_id = report.options['intronote'] if note_id: note_obj = db.get_note_from_gramps_id(note_id) text = note_obj.get() @@ -1564,34 +1557,29 @@ class IntroductionPage(BasePage): of.write(u'</p>\n\t<p>'.join(text.split("\n"))) of.write('</p>\n') - self.display_footer(of, db) + self.display_footer(of) self.close_file(of) -#------------------------------------------------------------------------ -# -# -# -#------------------------------------------------------------------------ class HomePage(BasePage): - def __init__(self, db, title, options, archive, media_list): - BasePage.__init__(self, title, options, archive, media_list, "") + def __init__(self, report, title): + BasePage.__init__(self, report, title) + db = report.database of = self.create_file("index") - self.display_header(of, db, _('Home')) + self.display_header(of, _('Home')) of.write('\t<h2>%s</h2>\n' % _('Home')) - pic_id = options['homeimg'] + pic_id = report.options['homeimg'] if pic_id: obj = db.get_object_from_gramps_id(pic_id) mime_type = obj.get_mime_type() if mime_type and mime_type.startswith("image"): try: (newpath, thumb_path) = self.copy_media(obj, False) - self.store_file(archive, self.html_dir, - Utils.media_path_full(db, - obj.get_path()), + self.report.store_file(Utils.media_path_full(db, + obj.get_path()), newpath) of.write('\t<img ') of.write('src="%s" ' % newpath) @@ -1599,7 +1587,7 @@ class HomePage(BasePage): except (IOError, OSError), msg: WarningDialog(_("Could not add photo to page"), str(msg)) - note_id = options['homenote'] + note_id = report.options['homenote'] if note_id: note_obj = db.get_note_from_gramps_id(note_id) text = note_obj.get() @@ -1611,21 +1599,17 @@ class HomePage(BasePage): of.write(u'</p>\n\t<p>'.join(text.split("\n"))) of.write('</p>\n') - self.display_footer(of, db) + self.display_footer(of) self.close_file(of) -#------------------------------------------------------------------------ -# -# -# -#------------------------------------------------------------------------ class SourcesPage(BasePage): - def __init__(self, db, title, handle_set, options, archive, media_list): - BasePage.__init__(self, title, options, archive, media_list, "") + def __init__(self, report, title, handle_set): + BasePage.__init__(self, report, title) + db = report.database of = self.create_file("sources") - self.display_header(of, db, _('Sources')) + self.display_header(of, _('Sources')) handle_list = list(handle_set) source_dict = {} @@ -1668,29 +1652,23 @@ class SourcesPage(BasePage): of.write('\t</tbody>\n') of.write('\t</table>\n') - self.display_footer(of, db) + self.display_footer(of) self.close_file(of) -#------------------------------------------------------------------------ -# -# -# -#------------------------------------------------------------------------ class SourcePage(BasePage): - def __init__(self, db, title, handle, src_list, options, archive, - media_list): + def __init__(self, report, title, handle, src_list): + db = report.database source = db.get_source_from_handle( handle) - BasePage.__init__(self, title, options, archive, media_list, - source.gramps_id) + BasePage.__init__(self, report, title, source.gramps_id) of = self.create_link_file('src', source.get_handle()) self.page_title = source.get_title() self.up = True - self.display_header(of, db, "%s - %s" % (_('Sources'), self.page_title)) + self.display_header(of, "%s - %s" % (_('Sources'), self.page_title)) media_list = source.get_media_list() - self.display_first_image_as_thumbnail(of, db, media_list) + self.display_first_image_as_thumbnail(of, media_list) of.write('\t<h2>%s:</h2>\n' % _('Sources')) of.write('\t<h3>%s</h3>\n\n' % html_escape(self.page_title.strip())) @@ -1714,24 +1692,23 @@ class SourcePage(BasePage): of.write('\t\t</table>\n') of.write('\t</div>\n\n') - self.display_additional_images_as_gallery(of, db, media_list) - self.display_note_list(of, db, source.get_note_list()) - self.display_references(of, db, src_list[source.handle]) - self.display_footer(of, db) + self.display_additional_images_as_gallery(of, media_list) + self.display_note_list(of, source.get_note_list()) + self.display_references(of, src_list[source.handle]) + + self.display_footer(of) self.close_file(of) -#------------------------------------------------------------------------ -# -# -# -#------------------------------------------------------------------------ class GalleryPage(BasePage): - def __init__(self, db, title, handle_set, options, archive, media_list): - BasePage.__init__(self, title, options, archive, media_list, "") + def __init__(self, report, title, handle_set): + BasePage.__init__(self, report, title) + # TODO. What to do with handle_set? + + db = report.database of = self.create_file("gallery") - self.display_header(of, db, _('Gallery')) + self.display_header(of, _('Gallery')) of.write('\t<h2>%s</h2>\n\n' % _('Gallery')) of.write('\t<p id="description">') @@ -1749,11 +1726,10 @@ class GalleryPage(BasePage): of.write('\t\t</tr>\n') of.write('\t</thead>\n') of.write('\t<tbody>\n') - self.db = db index = 1 - mlist = media_list.keys() - sort = Sort.Sort(self.db) + mlist = self.report.photo_list.keys() + sort = Sort.Sort(db) mlist.sort(sort.by_media_title) for handle in mlist: media = db.get_object_from_handle(handle) @@ -1777,54 +1753,44 @@ class GalleryPage(BasePage): of.write('\t</tbody>\n') of.write('\t</table>\n') - self.display_footer(of, db) + self.display_footer(of) self.close_file(of) -#------------------------------------------------------------------------ -# -# -# -#------------------------------------------------------------------------ class DownloadPage(BasePage): - def __init__(self, db, title, options, archive, media_list): - BasePage.__init__(self, title, options, archive, media_list, "") + def __init__(self, report, title): + BasePage.__init__(self, report, title) of = self.create_file("download") - self.display_header(of, db, _('Download')) + self.display_header(of, _('Download')) of.write('\t<h2>%s</h2>\n\n' % _('Download')) - self.display_footer(of, db) + self.display_footer(of) self.close_file(of) -#------------------------------------------------------------------------ -# -# -# -#------------------------------------------------------------------------ class ContactPage(BasePage): - def __init__(self, db, title, options, archive, media_list): - BasePage.__init__(self, title, options, archive, media_list, "") + def __init__(self, report, title): + BasePage.__init__(self, report, title) + db = report.database of = self.create_file("contact") - self.display_header(of, db, _('Contact')) + self.display_header(of, _('Contact')) of.write('\t<h2>%s</h2>\n\n' % _('Contact')) of.write('\t<div id="summaryarea">\n') - pic_id = options['contactimg'] + pic_id = report.options['contactimg'] if pic_id: obj = db.get_object_from_gramps_id(pic_id) mime_type = obj.get_mime_type() if mime_type and mime_type.startswith("image"): try: (newpath, thumb_path) = self.copy_media(obj, False) - self.store_file(archive, self.html_dir, - Utils.media_path_full(db, - obj.get_path()), - newpath) + self.report.store_file(Utils.media_path_full(db, + obj.get_path()), + newpath) of.write('\t\t<img height="200" ') of.write('src="%s" ' % newpath) of.write('alt="%s" />\n' % obj.get_description()) @@ -1850,7 +1816,7 @@ class ContactPage(BasePage): of.write('\t\t</div>\n') of.write('\t\t<div class="fullclear"></div>\n') - note_id = options['contactnote'] + note_id = report.options['contactnote'] if note_id: note_obj = db.get_note_from_gramps_id(note_id) text = note_obj.get() @@ -1862,14 +1828,9 @@ class ContactPage(BasePage): of.write('\t</div>\n') - self.display_footer(of, db) + self.display_footer(of) self.close_file(of) -#------------------------------------------------------------------------ -# -# -# -#------------------------------------------------------------------------ class IndividualPage(BasePage): """ This class is used to write HTML for an individual. @@ -1881,22 +1842,20 @@ class IndividualPage(BasePage): gen.lib.Person.UNKNOWN : _('unknown'), } - def __init__(self, db, person, title, ind_list, - place_list, src_list, options, archive, media_list): - BasePage.__init__(self, title, options, archive, media_list, - person.gramps_id) + def __init__(self, report, title, person, ind_list, place_list, src_list): + BasePage.__init__(self, report, title, person.gramps_id) self.person = person - self.db = db self.ind_list = ind_list - self.src_list = src_list + 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) + db = report.database of = self.create_link_file('ppl', person.handle) self.up = True - self.display_header(of, db, self.sort_name) + self.display_header(of, self.sort_name) self.display_ind_general(of) self.display_ind_events(of) @@ -1906,28 +1865,29 @@ class IndividualPage(BasePage): self.display_addresses(of) media_list = [] - photolist = self.person.get_media_list() - if len(photolist) > 1: - media_list = photolist[1:] + 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 = self.db.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 = self.db.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 = self.db.get_event_from_handle(evt_ref.ref) + event = db.get_event_from_handle(evt_ref.ref) if event: media_list += event.get_media_list() - self.display_additional_images_as_gallery(of, db, media_list) - self.display_note_list(of, db, self.person.get_note_list()) + self.display_additional_images_as_gallery(of, media_list) + self.display_note_list(of, self.person.get_note_list()) self.display_url_list(of, self.person.get_url_list()) self.display_ind_sources(of) self.display_ind_pedigree(of) if self.usegraph: self.display_tree(of) - self.display_footer(of, db) + + self.display_footer(of) self.close_file(of) def display_attr_list(self, of, attrlist=None): @@ -1989,7 +1949,8 @@ class IndividualPage(BasePage): def draw_connected_box(self, of, center1, center2, col, handle): if not handle: return None - person = self.db.get_person_from_handle(handle) + db = self.report.database + person = db.get_person_from_handle(handle) self.draw_box(of, center2, col, person) self.connect_line(of, center1, center2, col) return person @@ -2016,7 +1977,8 @@ class IndividualPage(BasePage): if gen > maxgen: return gen_offset = int(max_size / pow(2, gen+1)) - person = self.db.get_person_from_handle(phandle) + db = self.report.database + person = db.get_person_from_handle(phandle) if not person: return @@ -2034,7 +1996,7 @@ class IndividualPage(BasePage): self.extend_line(of, new_center, line_offset) gen = gen + 1 - family = self.db.get_family_from_handle(family_handle) + family = db.get_family_from_handle(family_handle) f_center = new_center-gen_offset f_handle = family.get_father_handle() @@ -2047,20 +2009,18 @@ class IndividualPage(BasePage): def display_ind_sources(self, of): for sref in self.person.get_source_references(): self.bibli.add_reference(sref) - if self.bibli.get_citation_count() == 0: - return - self.display_source_refs(of, self.db, self.bibli) + self.display_source_refs(of) def display_ind_pedigree(self, of): - + db = self.report.database parent_handle_list = self.person.get_parent_family_handle_list() if parent_handle_list: parent_handle = parent_handle_list[0] - family = self.db.get_family_from_handle(parent_handle) + family = db.get_family_from_handle(parent_handle) father_id = family.get_father_handle() mother_id = family.get_mother_handle() - mother = self.db.get_person_from_handle(mother_id) - father = self.db.get_person_from_handle(father_id) + mother = db.get_person_from_handle(mother_id) + father = db.get_person_from_handle(father_id) else: family = None father = None @@ -2104,7 +2064,7 @@ class IndividualPage(BasePage): of.write('\t\t\t\t\t\t\t</li>\n') else: of.write('\t\t\t\t\t\t\t') - child = self.db.get_person_from_handle(child_handle) + child = db.get_person_from_handle(child_handle) of.write('<li>') self.pedigree_person(of, child) of.write('</li>\n') @@ -2122,7 +2082,8 @@ class IndividualPage(BasePage): def display_ind_general(self, of): self.page_title = self.sort_name - self.display_first_image_as_thumbnail(of, self.db, + db = self.report.database + self.display_first_image_as_thumbnail(of, self.person.get_media_list()) of.write('\t<h2>Individuals:</h2>\n') @@ -2175,8 +2136,9 @@ class IndividualPage(BasePage): of.write('\t\t<h4>%s</h4>\n' % _('Events')) of.write('\t\t<table class="infolist">\n') + db = self.report.database for event_ref in evt_ref_list: - event = self.db.get_event_from_handle(event_ref.ref) + event = db.get_event_from_handle(event_ref.ref) if event: evt_name = str(event.get_type()) @@ -2219,7 +2181,8 @@ class IndividualPage(BasePage): of.write('\t</div>\n\n') def display_child_link(self, of, child_handle): - child = self.db.get_person_from_handle(child_handle) + db = self.report.database + child = db.get_person_from_handle(child_handle) gid = child.get_gramps_id() if child_handle in self.ind_list: of.write("\t\t\t\t\t\t<li>") @@ -2232,7 +2195,8 @@ class IndividualPage(BasePage): of.write(u"</li>\n") def display_parent(self, of, handle, title, rel): - person = self.db.get_person_from_handle(handle) + db = self.report.database + person = db.get_person_from_handle(handle) of.write('\t\t\t\t<td class="ColumnAttribute">%s</td>\n' % title) of.write('\t\t\t\t<td class="ColumnValue">') gid = person.gramps_id @@ -2255,10 +2219,11 @@ class IndividualPage(BasePage): of.write('\t\t<h4>%s</h4>\n' % _("Parents")) of.write('\t\t<table class="infolist">\n') + db = self.report.database first = True if parent_list: for family_handle in parent_list: - family = self.db.get_family_from_handle(family_handle) + family = db.get_family_from_handle(family_handle) # Get the mother and father relationships frel = "" @@ -2313,9 +2278,9 @@ class IndividualPage(BasePage): # 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) + father = 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) + family = db.get_family_from_handle(family_handle) for step_child_ref in family.get_child_ref_list(): step_child_handle = step_child_ref.ref if step_child_handle not in sibling: @@ -2325,9 +2290,9 @@ class IndividualPage(BasePage): # 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) + mother = 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) + family = db.get_family_from_handle(family_handle) for step_child_ref in family.get_child_ref_list(): step_child_handle = step_child_ref.ref if step_child_handle not in sibling: @@ -2358,9 +2323,10 @@ class IndividualPage(BasePage): of.write('\t\t<h4>%s</h4>\n' % _("Families")) of.write('\t\t<table class="infolist">\n') + db = self.report.database first = True for family_handle in family_list: - family = self.db.get_family_from_handle(family_handle) + family = db.get_family_from_handle(family_handle) self.display_spouse(of, family, first) first = False childlist = family.get_child_ref_list() @@ -2379,6 +2345,7 @@ class IndividualPage(BasePage): of.write('\t</div>\n\n') def display_spouse(self, of, family, first=True): + db = self.report.database gender = self.person.get_gender() reltype = family.get_relationship() @@ -2394,7 +2361,7 @@ class IndividualPage(BasePage): spouse_id = ReportUtils.find_spouse(self.person, family) if spouse_id: - spouse = self.db.get_person_from_handle(spouse_id) + spouse = db.get_person_from_handle(spouse_id) name = _nd.display(spouse) else: name = _("unknown") @@ -2415,7 +2382,7 @@ class IndividualPage(BasePage): of.write('\t\t\t</tr>\n') for event_ref in family.get_event_ref_list(): - event = self.db.get_event_from_handle(event_ref.ref) + event = db.get_event_from_handle(event_ref.ref) evtType = str(event.get_type()) of.write('\t\t\t<tr>\n') of.write('\t\t\t\t<td class="ColumnType"> </td>\n') @@ -2433,7 +2400,7 @@ class IndividualPage(BasePage): of.write('\t\t\t</tr>\n') notelist = family.get_note_list() for notehandle in notelist: - note = self.db.get_note_from_handle(notehandle) + note = db.get_note_from_handle(notehandle) if note: text = note.get() format = note.get_format() @@ -2460,11 +2427,12 @@ class IndividualPage(BasePage): of.write(person_name) def pedigree_family(self, of): + db = self.report.database for family_handle in self.person.get_family_handle_list(): - rel_family = self.db.get_family_from_handle(family_handle) + rel_family = db.get_family_from_handle(family_handle) spouse_handle = ReportUtils.find_spouse(self.person, rel_family) if spouse_handle: - spouse = self.db.get_person_from_handle(spouse_handle) + spouse = db.get_person_from_handle(spouse_handle) of.write('<li class="spouse">') self.pedigree_person(of, spouse) childlist = rel_family.get_child_ref_list() @@ -2473,7 +2441,7 @@ class IndividualPage(BasePage): of.write('\t\t\t\t\t\t\t\t\t\t<ol>\n') for child_ref in childlist: of.write('\t\t\t\t\t\t\t\t\t\t\t') - child = self.db.get_person_from_handle(child_ref.ref) + child = db.get_person_from_handle(child_ref.ref) of.write('<li>') self.pedigree_person(of, child) of.write('</li>\n') @@ -2482,6 +2450,7 @@ class IndividualPage(BasePage): of.write('</li>\n') def format_event(self, event, event_ref): + db = self.report.database lnk = (self.cur_fname, self.page_title, self.gid) descr = event.get_description() place_handle = event.get_place_handle() @@ -2493,7 +2462,7 @@ class IndividualPage(BasePage): self.place_list[place_handle] = [lnk] place = self.place_link_str(place_handle, - ReportUtils.place_name(self.db, place_handle), + ReportUtils.place_name(db, place_handle), up=True) else: place = u"" @@ -2533,7 +2502,7 @@ class IndividualPage(BasePage): notelist = event.get_note_list() notelist.extend(event_ref.get_note_list()) for notehandle in notelist: - note = self.db.get_note_from_handle(notehandle) + note = db.get_note_from_handle(notehandle) if note: note_text = note.get() format = note.get_format() @@ -2549,7 +2518,6 @@ class IndividualPage(BasePage): def get_citation_links(self, source_ref_list): gid_list = [] lnk = (self.cur_fname, self.page_title, self.gid) - text = "" for sref in source_ref_list: handle = sref.get_reference_handle() @@ -2561,6 +2529,7 @@ class IndividualPage(BasePage): else: self.src_list[handle] = [lnk] + text = "" if len(gid_list) > 0: text = text + " <sup>" for ref in gid_list: @@ -2571,12 +2540,8 @@ class IndividualPage(BasePage): return text -#------------------------------------------------------------------------ -# -# NavWebReport -# -#------------------------------------------------------------------------ class NavWebReport(Report): + def __init__(self, database, options): """ Create WebReport object that produces the report. @@ -2584,24 +2549,23 @@ class NavWebReport(Report): The arguments are: database - the GRAMPS database instance - person - currently selected person options - instance of the Options class for this report """ Report.__init__(self, database, options) menu = options.menu - self.opts = {} + self.options = {} for optname in menu.get_all_option_names(): menuopt = menu.get_option_by_name(optname) - self.opts[optname] = menuopt.get_value() + self.options[optname] = menuopt.get_value() - if not self.opts['incpriv']: + if not self.options['incpriv']: self.database = PrivateProxyDb(database) else: self.database = database - livinginfo = self.opts['living'] - yearsafterdeath = self.opts['yearsafterdeath'] + livinginfo = self.options['living'] + yearsafterdeath = self.options['yearsafterdeath'] if livinginfo == LivingProxyDb.MODE_EXCLUDE: self.database = LivingProxyDb(self.database, @@ -2617,29 +2581,27 @@ class NavWebReport(Report): filters_option = menu.get_option_by_name('filter') self.filter = filters_option.get_filter() - self.target_path = self.opts['target'] - self.copyright = self.opts['cright'] - # self.ext = self.opts['ext'] - # self.encoding = self.opts['encoding'] - self.css = self.opts['css'] - # self.noid = self.opts['nogid'] - # self.linkhome = self.opts['linkhome'] - # self.showbirth = self.opts['showbirth'] - # self.showdeath = self.opts['showdeath'] - # self.showspouse = self.opts['showspouse'] - # self.showparents = self.opts['showparents'] - # self.showhalfsiblings = self.opts['showhalfsiblings'] - self.title = self.opts['title'] - self.sort = Sort.Sort(self.database) - self.inc_gallery = self.opts['gallery'] - self.inc_contact = self.opts['contactnote'] != u""\ - or self.opts['contactimg'] != u"" - self.inc_download = self.opts['incdownload'] - self.use_archive = self.opts['archive'] - self.use_intro = self.opts['intronote'] != u""\ - or self.opts['introimg'] != u"" - self.use_home = self.opts['homenote'] != u"" or\ - self.opts['homeimg'] != u"" + self.target_path = self.options['target'] + self.copyright = self.options['cright'] + self.css = self.options['css'] + self.title = self.options['title'] + self.inc_gallery = self.options['gallery'] + self.inc_contact = self.options['contactnote'] != u"" or \ + self.options['contactimg'] != u"" + self.inc_download = self.options['incdownload'] + self.use_archive = self.options['archive'] + self.use_intro = self.options['intronote'] != u"" or \ + self.options['introimg'] != u"" + self.use_home = self.options['homenote'] != u"" or \ + self.options['homeimg'] != u"" + + self.archive = None + self.cur_fname = None # Internal use. The name of the output file, to be used for the tar archive. + if self.use_archive: + self.html_dir = None + else: + self.html_dir = self.target_path + self.warn_dir = True # Only give warning once. def write_report(self): if not self.use_archive: @@ -2680,14 +2642,13 @@ class NavWebReport(Report): ErrorDialog(_("Could not create the directory: %s") % \ image_dir_name) return - archive = None else: if os.path.isdir(self.target_path): ErrorDialog(_('Invalid file name'), _('The archive file must be a file, not a directory')) return try: - archive = tarfile.open(self.target_path, "w:gz") + self.archive = tarfile.open(self.target_path, "w:gz") except (OSError, IOError), value: ErrorDialog(_("Could not create %s") % self.target_path, value) @@ -2700,7 +2661,7 @@ class NavWebReport(Report): # Generate the CSS file if requested if self.css != '': - self.write_css(archive, self.target_path, self.css) + self.write_css(self.css) # Copy Mainz Style Images imgs = ["NWeb_Mainz_Bkgd.png", @@ -2717,28 +2678,28 @@ class NavWebReport(Report): for f in imgs: from_path = os.path.join(const.IMAGE_DIR, f) to_path = os.path.join("images", f) - self.store_file(archive, self.target_path, from_path, to_path) + self.store_file(from_path, to_path) place_list = {} source_list = {} self.photo_list = {} - self.base_pages(self.photo_list, archive) - self.person_pages(ind_list, place_list, source_list, archive) - self.surname_pages(ind_list, archive) - self.place_pages(place_list, source_list, archive) + self.base_pages() + self.person_pages(ind_list, place_list, source_list) + self.surname_pages(ind_list) + self.place_pages(place_list, source_list) if self.inc_gallery: - self.gallery_pages(self.photo_list, source_list, archive) - self.source_pages(source_list, self.photo_list, archive) + self.gallery_pages(source_list) + self.source_pages(source_list) - if archive: - archive.close() + if self.archive: + self.archive.close() self.progress.close() def build_person_list(self): """ Builds the person list. Gets all the handles from the database - and then applies the cosen filter: + and then applies the chosen filter: """ # gets the person list and applies the requested filter @@ -2747,41 +2708,38 @@ class NavWebReport(Report): ind_list = self.filter.apply(self.database, ind_list) return ind_list - def write_css(self, archive, html_dir, css_file): + def write_css(self, css_file): """ Copy the CSS file to the destination. """ - if archive: + + if self.archive: fname = os.path.join(const.DATA_DIR, css_file) - archive.add(fname, _NARRATIVE) + self.archive.add(fname, _NARRATIVE) gname = os.path.join(const.DATA_DIR, "NWeb-Print_Default.css") - archive.add(gname, _NARRATIVEPRINT) + self.archive.add(gname, _NARRATIVEPRINT) else: shutil.copyfile(os.path.join(const.DATA_DIR, css_file), - os.path.join(html_dir, _NARRATIVE)) + os.path.join(self.html_dir, _NARRATIVE)) shutil.copyfile(os.path.join(const.DATA_DIR, "NWeb-Print_Default.css"), - os.path.join(html_dir, _NARRATIVEPRINT)) + os.path.join(self.html_dir, _NARRATIVEPRINT)) - def person_pages(self, ind_list, place_list, source_list, archive): + def person_pages(self, ind_list, place_list, source_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, - self.opts, archive, self.photo_list) + IndividualListPage(self, self.title, ind_list) for person_handle in ind_list: self.progress.step() person = self.database.get_person_from_handle(person_handle) - IndividualPage( - self.database, person, self.title, ind_list, - place_list, source_list, self.opts, archive, self.photo_list) + IndividualPage(self, self.title, person, ind_list, place_list, source_list) - def surname_pages(self, ind_list, archive): + def surname_pages(self, ind_list): """ Generates the surname related pages from list of individual people. @@ -2795,52 +2753,41 @@ class NavWebReport(Report): else: defname = "index" - SurnameListPage( - self.database, self.title, ind_list, self.opts, archive, - self.photo_list, SurnameListPage.ORDER_BY_NAME, defname) + SurnameListPage(self, self.title, ind_list, SurnameListPage.ORDER_BY_NAME, defname) - SurnameListPage( - self.database, self.title, ind_list, self.opts, archive, - self.photo_list, SurnameListPage.ORDER_BY_COUNT, "surnames_count") + SurnameListPage(self, self.title, ind_list, SurnameListPage.ORDER_BY_COUNT, "surnames_count") for (surname, handle_list) in local_list: - SurnamePage(self.database, surname, handle_list, - self.opts, archive, self.photo_list) + SurnamePage(self, surname, handle_list) self.progress.step() - def source_pages(self, source_list, photo_list, archive): + def source_pages(self, source_list): self.progress.set_pass(_("Creating source pages"), len(source_list)) - SourcesPage(self.database, self.title, source_list.keys(), - self.opts, archive, photo_list) + SourcesPage(self, self.title, source_list.keys()) for key in list(source_list): - SourcePage(self.database, self.title, key, source_list, - self.opts, archive, photo_list) + SourcePage(self, self.title, key, source_list) self.progress.step() - def place_pages(self, place_list, source_list, archive): + def place_pages(self, place_list, source_list): self.progress.set_pass(_("Creating place pages"), len(place_list)) - PlaceListPage( - self.database, self.title, place_list, source_list, self.opts, - archive, self.photo_list) + PlaceListPage(self, self.title, place_list, source_list) for place in place_list.keys(): - PlacePage( - self.database, self.title, place, source_list, place_list, - self.opts, archive, self.photo_list) + PlacePage(self, self.title, place, source_list, place_list) self.progress.step() - def gallery_pages(self, photo_list, source_list, archive): + def gallery_pages(self, source_list): import gc - self.progress.set_pass(_("Creating media pages"), len(photo_list)) - GalleryPage(self.database, self.title, source_list, - self.opts, archive, self.photo_list) + self.progress.set_pass(_("Creating media pages"), len(self.photo_list)) + + GalleryPage(self, self.title, source_list) prev = None total = len(self.photo_list) @@ -2855,44 +2802,51 @@ class NavWebReport(Report): next = None else: next = photo_keys[index] - MediaPage(self.database, self.title, photo_handle, source_list, - self.opts, archive, self.photo_list[photo_handle], + # Notice. Here self.photo_list[photo_handle] is used not self.photo_list + MediaPage(self, self.title, photo_handle, source_list, self.photo_list[photo_handle], (prev, next, index, total)) self.progress.step() prev = photo_handle index += 1 - def base_pages(self, photo_list, archive): + def base_pages(self): if self.use_home: - HomePage(self.database, self.title, self.opts, archive, photo_list) + HomePage(self, self.title) if self.inc_contact: - ContactPage(self.database, self.title, self.opts, - archive, photo_list) + ContactPage(self, self.title) if self.inc_download: - DownloadPage(self.database, self.title, self.opts, - archive, photo_list) + DownloadPage(self, self.title) if self.use_intro: - IntroductionPage(self.database, self.title, self.opts, - archive, photo_list) + IntroductionPage(self, self.title) - def store_file(self, archive, html_dir, from_path, to_path): + def store_file(self, from_path, to_path): """ Store the file in the destination. """ - if archive: - archive.add(from_path, to_path) + if self.archive: + self.archive.add(str(from_path), str(to_path)) else: - shutil.copyfile(from_path, os.path.join(html_dir, to_path)) + dest = os.path.join(self.html_dir, to_path) + dirname = os.path.dirname(dest) + if not os.path.isdir(dirname): + os.makedirs(dirname) + if from_path != dest: + shutil.copyfile(from_path, dest) + elif self.warn_dir: + WarningDialog( + _("Possible destination error") + "\n" + + _("You appear to have set your target directory " + "to a directory used for data storage. This " + "could create problems with file management. " + "It is recommended that you consider using " + "a different directory to store your generated " + "web pages.")) + self.warn_dir = False -#------------------------------------------------------------------------ -# -# NavWebOptions -# -#------------------------------------------------------------------------ class NavWebOptions(MenuReportOptions): """ Defines options and provides handling interface. @@ -3169,6 +3123,7 @@ class NavWebOptions(MenuReportOptions): pass +# FIXME. Why do we need our own sorting? Why not use Sort.Sort? def sort_people(db, handle_list): sname_sub = {} sortnames = {} @@ -3199,11 +3154,6 @@ def sort_people(db, handle_list): sorted_lists.append((name, entries)) return sorted_lists -#------------------------------------------------------------------------- -# -# -# -#------------------------------------------------------------------------- register_report( name = 'navwebpage', category = CATEGORY_WEB,