Tidy up media pages - remove unused parameters, use list of media items generated in first pass. Should fix bugs 2365, 5905 and 6009.

svn: r20655
This commit is contained in:
Tim G L Lyons 2012-11-13 15:51:25 +00:00
parent 69fc354f06
commit a35ad26696

View File

@ -4282,12 +4282,6 @@ class SourcePages(BasePage):
@param: source_list -- a dictionary object containg source handles as @param: source_list -- a dictionary object containg source handles as
the key and (backlink filename, backlink page_title, backlink gid) as the key and (backlink filename, backlink page_title, backlink gid) as
values -- now replaced by self.source_dict values -- now replaced by self.source_dict
@param: ppl_handle_list -- list of Person handles that are included in
the web site -- no longer used
@param: database_handles_list -- tuple containg lists of persons,
families, events, places repositories and media that are included in
the web site -- no longer used
""" """
# FIXME: Perhaps report and title should just be passed in to the class # FIXME: Perhaps report and title should just be passed in to the class
log.debug("source_dict") log.debug("source_dict")
@ -4573,10 +4567,15 @@ class MediaPages(BasePage):
citation_handle, media_fname, citation_handle, media_fname,
media_name, media.gramps_id) media_name, media.gramps_id)
def display_pages(self, report, title, db_media_handles, source_list): def display_pages(self, report, title):
# FIXME: Most of the parameters should be removed. report is passed to """
# __init__, title appears not to be used and db_media_handles and Generate and output the pages under the Media tab, namely the media
# source_list violate modularity and should be removed. index and the individual media pages.
@param: report -- the instance of the main report class for this report
@param: title -- the web site title
"""
# FIXME: Perhaps report and title should just be passed in to the class
log.debug("media_dict") log.debug("media_dict")
for item in self.media_dict.iteritems(): for item in self.media_dict.iteritems():
log.debug(" %s" % str(item)) log.debug(" %s" % str(item))
@ -4590,31 +4589,35 @@ class MediaPages(BasePage):
_("Creating media pages"), _("Creating media pages"),
len(report.photo_list) + 1) len(report.photo_list) + 1)
# When display_pages is called, db_media_handles = [] It is populated by sort = Sort.Sort(report.database)
# MediaListPage from sorted report.photo_list. It is subsequently used sorted_media_handles = sorted(self.media_dict,
# in various places to determine whether data has been written key=sort.by_media_title_key)
self.MediaListPage(report, report.title, db_media_handles) self.MediaListPage(report, report.title, sorted_media_handles)
prev = None prev = None
total = len(report.photo_list) total = len(self.media_dict)
sort = Sort.Sort(report.database)
photo_keys = sorted(report.photo_list, key =sort.by_media_title_key)
index = 1 index = 1
for photo_handle in photo_keys: for handle in sorted_media_handles:
gc.collect() # Reduce memory usage when there are many images. gc.collect() # Reduce memory usage when there are many images.
next = None if index == total else photo_keys[index] next = None if index == total else sorted_media_handles[index]
# Notice. Here report.photo_list[photo_handle] is used not # Notice. Here report.photo_list[photo_handle] is used not
# report.photo_list # report.photo_list
report.user.step_progress() report.user.step_progress()
self.MediaPage(report, title, photo_handle, source_list, self.MediaPage(report, title, (handle, self.media_dict[handle]),
report.photo_list[photo_handle],
(prev, next, index, total)) (prev, next, index, total))
prev = photo_handle prev = handle
index += 1 index += 1
report.user.end_progress() report.user.end_progress()
def MediaListPage(self, report, title, db_media_handles): def MediaListPage(self, report, title, sorted_media_handles):
"""
Generate and output the Media index page.
@param: report -- the instance of the main report class for this report
@param: title -- the web site title
@param: sorted_media_handles -- a list of the handles of the media to be
displayed sorted by the media title
"""
self.dbase_ = report.database self.dbase_ = report.database
BasePage.__init__(self, report, title) BasePage.__init__(self, report, title)
@ -4658,10 +4661,7 @@ class MediaPages(BasePage):
table += tbody table += tbody
index = 1 index = 1
sort = Sort.Sort(self.dbase_) for media_handle in sorted_media_handles:
mlist = sorted(self.report.photo_list, key = sort.by_media_title_key)
for media_handle in mlist:
media = self.dbase_.get_object_from_handle(media_handle) media = self.dbase_.get_object_from_handle(media_handle)
if media: if media:
title = media.get_description() or "[untitled]" title = media.get_description() or "[untitled]"
@ -4681,7 +4681,6 @@ class MediaPages(BasePage):
) )
index += 1 index += 1
db_media_handles.append(media_handle)
# add footer section # add footer section
# add clearline for proper styling # add clearline for proper styling
@ -4706,7 +4705,19 @@ class MediaPages(BasePage):
# return hyperlink to its callers # return hyperlink to its callers
return hyper return hyper
def MediaPage(self, report, title, handle, src_list, my_media_list, info): def MediaPage(self, report, title, item, info):
"""
Generate and output an individual Media page.
@param: report -- the instance of the main report class for this report
@param: title -- the web site title
@param: item -- a tuple containing the source handle and a list of
back-references
@param: info -- a tuple containing the media handle for the next and
previous media, the current page number, and the total number of
media pages
"""
(handle, my_media_list) = item
(prev, next, page_number, total_pages) = info (prev, next, page_number, total_pages) = info
self.dbase_ = report.database self.dbase_ = report.database
@ -4720,7 +4731,7 @@ class MediaPages(BasePage):
of, sio = self.report.create_file(handle, "img") of, sio = self.report.create_file(handle, "img")
self.up = True self.up = True
self.src_list = src_list # self.src_list = src_list
self.bibli = Bibliography() self.bibli = Bibliography()
# get media type to be used primarily with "img" tags # get media type to be used primarily with "img" tags
@ -7567,8 +7578,7 @@ class NavWebReport(Report):
db_media_handles = [] db_media_handles = []
if self.inc_gallery: if self.inc_gallery:
if not self.create_thumbs_only: if not self.create_thumbs_only:
self.tab["Media"].display_pages(self, self.title, self.tab["Media"].display_pages(self, self.title)
db_media_handles, source_list)
# self.media_pages(source_list, db_media_handles) # self.media_pages(source_list, db_media_handles)
# build Thumbnail Preview Page... # build Thumbnail Preview Page...