Tweaks using list comprehensions
svn: r13670
This commit is contained in:
parent
9698b0306f
commit
e572a41566
@ -412,14 +412,13 @@ class BasePage(object):
|
|||||||
if format == 1:
|
if format == 1:
|
||||||
#preformatted, retain whitespace.
|
#preformatted, retain whitespace.
|
||||||
#so use \n\n for paragraph detection
|
#so use \n\n for paragraph detection
|
||||||
#FIXME: following split should be regex to match \n\s*\n instead?
|
htmllist += Html("pre", indent=None) + markuptext.split('\n')
|
||||||
htmllist += Html("pre", indent=None) + \
|
|
||||||
(l + str(Html('br')) for l in markuptext.split('\n'))
|
|
||||||
|
|
||||||
elif format == 0:
|
elif format == 0:
|
||||||
#flowed
|
#flowed, use \n\n for paragraph detection
|
||||||
#FIXME: following split should be regex to match \n\s*\n instead?
|
htmllist.extend(
|
||||||
htmllist.extend(Html('p') + para for para in markuptext.split("\n\n"))
|
(Html('p') + para.split('\n'))
|
||||||
|
for para in markuptext.split("\n\n"))
|
||||||
|
|
||||||
return htmllist
|
return htmllist
|
||||||
|
|
||||||
@ -751,8 +750,9 @@ class BasePage(object):
|
|||||||
addr_data_row.append(["Sources", self.get_citation_links(
|
addr_data_row.append(["Sources", self.get_citation_links(
|
||||||
address.get_source_references() )])
|
address.get_source_references() )])
|
||||||
|
|
||||||
trow.extend(Html("td", v or " ", class_="Column" + c, inline=True)
|
trow.extend(
|
||||||
for c, v in addr_data_row)
|
Html("td", value or " ", class_="Column" + colclass, inline=True)
|
||||||
|
for colclass, value in addr_data_row)
|
||||||
|
|
||||||
# address: notelist
|
# address: notelist
|
||||||
if showsrc is not None:
|
if showsrc is not None:
|
||||||
@ -1223,11 +1223,6 @@ class BasePage(object):
|
|||||||
|
|
||||||
if note:
|
if note:
|
||||||
note_text = self.get_note_format(note)
|
note_text = self.get_note_format(note)
|
||||||
try:
|
|
||||||
note_text = unicode(note_text)
|
|
||||||
except UnicodeDecodeError:
|
|
||||||
print "unicode(note_text) exception"
|
|
||||||
note_text = unicode(str(note_text), errors='replace')
|
|
||||||
|
|
||||||
# add section title
|
# add section title
|
||||||
section += Html("h4", _("Narrative"), inline=True)
|
section += Html("h4", _("Narrative"), inline=True)
|
||||||
@ -1666,7 +1661,7 @@ class IndividualListPage(BasePage):
|
|||||||
trow.attr = 'class = "BeginSurname"'
|
trow.attr = 'class = "BeginSurname"'
|
||||||
if surname:
|
if surname:
|
||||||
tcell += Html("a", surname, name = letter,
|
tcell += Html("a", surname, name = letter,
|
||||||
title = "Surname with letter %s" % letter)
|
title = "Surname with letter " + letter)
|
||||||
else:
|
else:
|
||||||
tcell += " "
|
tcell += " "
|
||||||
else:
|
else:
|
||||||
@ -2638,8 +2633,7 @@ class MediaPage(BasePage):
|
|||||||
|
|
||||||
def display_media_sources(self, photo):
|
def display_media_sources(self, photo):
|
||||||
|
|
||||||
for sref in photo.get_source_references():
|
map(self.bibli.add_reference, photo.get_source_references())
|
||||||
self.bibli.add_reference(sref)
|
|
||||||
sourcerefs = self.display_source_refs(self.bibli)
|
sourcerefs = self.display_source_refs(self.bibli)
|
||||||
|
|
||||||
# return source references to its callers
|
# return source references to its callers
|
||||||
@ -2761,9 +2755,8 @@ class SurnameListPage(BasePage):
|
|||||||
index_val = "%90d_%s" % (999999999-len(data_list), surname)
|
index_val = "%90d_%s" % (999999999-len(data_list), surname)
|
||||||
temp_list[index_val] = (surname, data_list)
|
temp_list[index_val] = (surname, data_list)
|
||||||
|
|
||||||
person_handle_list = []
|
person_handle_list = (temp_list[key]
|
||||||
for key in sorted(temp_list, key = locale.strxfrm):
|
for key in sorted(temp_list, key = locale.strxfrm))
|
||||||
person_handle_list.append(temp_list[key])
|
|
||||||
|
|
||||||
last_letter = ''
|
last_letter = ''
|
||||||
last_surname = ''
|
last_surname = ''
|
||||||
@ -2782,7 +2775,7 @@ class SurnameListPage(BasePage):
|
|||||||
|
|
||||||
tcell = ( Html("td", class_ = "ColumnLetter") +
|
tcell = ( Html("td", class_ = "ColumnLetter") +
|
||||||
Html("a", last_letter, name = last_letter,
|
Html("a", last_letter, name = last_letter,
|
||||||
title = "Surnames with letter %s" % last_letter, inline = True)
|
title = "Surnames with letter " + last_letter, inline = True)
|
||||||
)
|
)
|
||||||
trow += tcell
|
trow += tcell
|
||||||
|
|
||||||
@ -2928,13 +2921,14 @@ class SourceListPage(BasePage):
|
|||||||
trow = Html("tr")
|
trow = Html("tr")
|
||||||
thead += trow
|
thead += trow
|
||||||
|
|
||||||
for (label, colclass) in [
|
header_row = [
|
||||||
(None, "RowLabel"),
|
(None, "RowLabel"),
|
||||||
(_("Source Name|Name"), "Name") ]:
|
(_("Source Name|Name"), "Name") ]
|
||||||
|
|
||||||
label = label or " "
|
trow.extend(
|
||||||
trow += Html("th", label, class_ = "Column%s" % colclass, inline = True)
|
Html("th", label or " ", class_ = "Column" + colclass, inline = True)
|
||||||
|
for (label, colclass) in header_row)
|
||||||
|
|
||||||
# begin table body
|
# begin table body
|
||||||
tbody = Html("tbody")
|
tbody = Html("tbody")
|
||||||
table += tbody
|
table += tbody
|
||||||
@ -3168,12 +3162,15 @@ class DownloadPage(BasePage):
|
|||||||
trow = Html("tr")
|
trow = Html("tr")
|
||||||
thead += trow
|
thead += trow
|
||||||
|
|
||||||
for (label, colclass) in [
|
header_row = [
|
||||||
(_("File Name"), "Filename"),
|
(_("File Name"), "Filename"),
|
||||||
(DESCRHEAD, "Description"),
|
(DESCRHEAD, "Description"),
|
||||||
(_("License"), "License"),
|
(_("License"), "License"),
|
||||||
(_("Last Modified"), "Modified") ]:
|
(_("Last Modified"), "Modified") ]
|
||||||
trow += Html("th", label, class_ = colclass, inline = True)
|
|
||||||
|
trow.extend(
|
||||||
|
Html("th", label, class_ = colclass, inline = True)
|
||||||
|
for (label, colclass) in header_row)
|
||||||
|
|
||||||
# if dlfname1 is not None, show it???
|
# if dlfname1 is not None, show it???
|
||||||
if dlfname1:
|
if dlfname1:
|
||||||
@ -3575,8 +3572,7 @@ class IndividualPage(BasePage):
|
|||||||
will create the "Source References" section for a person
|
will create the "Source References" section for a person
|
||||||
"""
|
"""
|
||||||
|
|
||||||
for sref in self.person.get_source_references():
|
map(self.bibli.add_reference, self.person.get_source_references())
|
||||||
self.bibli.add_reference(sref)
|
|
||||||
sourcerefs = self.display_source_refs(self.bibli)
|
sourcerefs = self.display_source_refs(self.bibli)
|
||||||
|
|
||||||
# return to its callers
|
# return to its callers
|
||||||
@ -3601,13 +3597,13 @@ class IndividualPage(BasePage):
|
|||||||
thead += trow
|
thead += trow
|
||||||
|
|
||||||
assoc_row = [
|
assoc_row = [
|
||||||
(_('Relationship'), 'Relationship'),
|
(_('Relationship'), 'Relationship'),
|
||||||
(SHEAD, 'Sources'),
|
(SHEAD, 'Sources'),
|
||||||
(NHEAD, 'Notes') ]
|
(NHEAD, 'Notes') ]
|
||||||
|
|
||||||
for (label, colclass) in assoc_row:
|
trow.extend(
|
||||||
trow += Html("th", label, class_ = "Column%s" % colclass,
|
Html("th", label, class_="Column" + colclass, inline=True)
|
||||||
inline = True)
|
for (label, colclass) in assoc_row)
|
||||||
|
|
||||||
tbody = Html("tbody")
|
tbody = Html("tbody")
|
||||||
table += tbody
|
table += tbody
|
||||||
@ -3626,7 +3622,7 @@ class IndividualPage(BasePage):
|
|||||||
# get colclass from assoc_row
|
# get colclass from assoc_row
|
||||||
colclass = assoc_row[index][1]
|
colclass = assoc_row[index][1]
|
||||||
|
|
||||||
trow += Html("td", data, class_ = "Column%s" % colclass,
|
trow += Html("td", data, class_ = "Column" + colclass,
|
||||||
inline = True)
|
inline = True)
|
||||||
index += 1
|
index += 1
|
||||||
|
|
||||||
@ -4023,9 +4019,7 @@ class IndividualPage(BasePage):
|
|||||||
first = False
|
first = False
|
||||||
if len(child_ref_list) > 1:
|
if len(child_ref_list) > 1:
|
||||||
childlist = [child_ref.ref for child_ref in child_ref_list]
|
childlist = [child_ref.ref for child_ref in child_ref_list]
|
||||||
for child_handle in childlist:
|
sibling.update(childlist)
|
||||||
sibling.add(child_handle) # remember that
|
|
||||||
# we've already "seen" this child
|
|
||||||
|
|
||||||
# now that we have all natural siblings, display them...
|
# now that we have all natural siblings, display them...
|
||||||
if sibling:
|
if sibling:
|
||||||
@ -4041,18 +4035,17 @@ class IndividualPage(BasePage):
|
|||||||
tcell += ordered
|
tcell += ordered
|
||||||
|
|
||||||
if birthorder:
|
if birthorder:
|
||||||
kids = []
|
|
||||||
kids = sorted(add_birthdate(db, sibling))
|
kids = sorted(add_birthdate(db, sibling))
|
||||||
|
ordered.extend(
|
||||||
for birth_date, child_handle in kids:
|
self.display_child_link(child_handle)
|
||||||
if child_handle != self.person.handle:
|
for birth_date, child_handle in kids
|
||||||
ordered += self.display_child_link(child_handle)
|
if child_handle != self.person.handle)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
ordered.extend(
|
||||||
for child_handle in sibling:
|
self.display_child_link(child_handle)
|
||||||
if child_handle != self.person.handle:
|
for child_handle in sibling
|
||||||
ordered += self.display_child_link(child_handle)
|
if child_handle != self.person.handle)
|
||||||
|
|
||||||
# Also try to identify half-siblings
|
# Also try to identify half-siblings
|
||||||
half_siblings = set()
|
half_siblings = set()
|
||||||
@ -4100,16 +4093,13 @@ class IndividualPage(BasePage):
|
|||||||
tcell += ordered
|
tcell += ordered
|
||||||
|
|
||||||
if birthorder:
|
if birthorder:
|
||||||
kids = []
|
|
||||||
kids = sorted(add_birthdate(db, half_siblings))
|
kids = sorted(add_birthdate(db, half_siblings))
|
||||||
|
|
||||||
for birth_date, child_handle in kids:
|
ordered.extend(
|
||||||
ordered += self.display_child_link(child_handle)
|
self.display_child_link(child_handle)
|
||||||
|
for birth_date, child_handle in kids)
|
||||||
else:
|
else:
|
||||||
|
ordered += map(self.display_child_link, half_siblings)
|
||||||
for child_handle in half_siblings:
|
|
||||||
ordered += self.display_child_link(child_handle)
|
|
||||||
|
|
||||||
# get step-siblings
|
# get step-siblings
|
||||||
if showallsiblings:
|
if showallsiblings:
|
||||||
@ -4195,13 +4185,13 @@ class IndividualPage(BasePage):
|
|||||||
kids = []
|
kids = []
|
||||||
kids = sorted(add_birthdate(db, step_siblings))
|
kids = sorted(add_birthdate(db, step_siblings))
|
||||||
|
|
||||||
for birth_date, child_handle in kids:
|
ordered.extend(
|
||||||
ordered += self.display_child_link(child_handle)
|
self.display_child_link(child_handle)
|
||||||
|
for birth_date, child_handle in kids)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
ordered += map(self.display_child_link,
|
||||||
for child_handle in step_siblings:
|
step_siblings)
|
||||||
ordered += self.display_child_link(child_handle)
|
|
||||||
|
|
||||||
# return parents division to its caller
|
# return parents division to its caller
|
||||||
return section
|
return section
|
||||||
@ -4246,15 +4236,13 @@ class IndividualPage(BasePage):
|
|||||||
childlist = [child_ref.ref for child_ref in childlist]
|
childlist = [child_ref.ref for child_ref in childlist]
|
||||||
|
|
||||||
if self.report.options['birthorder']:
|
if self.report.options['birthorder']:
|
||||||
kids = []
|
|
||||||
kids = sorted(add_birthdate(db, childlist))
|
kids = sorted(add_birthdate(db, childlist))
|
||||||
|
|
||||||
for birth_date, child_handle in kids:
|
ordered.extend(
|
||||||
ordered += self.display_child_link(child_handle)
|
self.display_child_link(child_handle)
|
||||||
|
for birth_date, child_handle in kids)
|
||||||
else:
|
else:
|
||||||
|
ordered += map(self.display_child_link, childlist)
|
||||||
for child_handle in childlist:
|
|
||||||
ordered += self.display_child_link(child_handle)
|
|
||||||
|
|
||||||
# family LDS ordinance list
|
# family LDS ordinance list
|
||||||
famldslist = family.lds_ord_list
|
famldslist = family.lds_ord_list
|
||||||
@ -4401,8 +4389,9 @@ class IndividualPage(BasePage):
|
|||||||
event_header_row.append((NHEAD, "Notes"))
|
event_header_row.append((NHEAD, "Notes"))
|
||||||
|
|
||||||
trow = Html("tr")
|
trow = Html("tr")
|
||||||
for (label, colclass) in event_header_row:
|
trow.extend(
|
||||||
trow += Html("th", label, class_ = "Column%s" % colclass, inline = True)
|
Html("th", label, class_ = "Column" + colclass, inline = True)
|
||||||
|
for (label, colclass) in event_header_row)
|
||||||
|
|
||||||
# return header row to its callers
|
# return header row to its callers
|
||||||
return trow
|
return trow
|
||||||
@ -4627,13 +4616,16 @@ class AddressBookListPage(BasePage):
|
|||||||
trow = Html("tr")
|
trow = Html("tr")
|
||||||
thead += trow
|
thead += trow
|
||||||
|
|
||||||
for (label, colclass) in [
|
header_row = [
|
||||||
[" ", "RowLabel"],
|
[" ", "RowLabel"],
|
||||||
[_("Name"), "Name"],
|
[_("Name"), "Name"],
|
||||||
[_("Address"), "Address"],
|
[_("Address"), "Address"],
|
||||||
[_("Residence"), "Residence"],
|
[_("Residence"), "Residence"],
|
||||||
[_("Web Links"), "WebLinks"] ]:
|
[_("Web Links"), "WebLinks"] ]
|
||||||
trow += Html("th", label, class_ = "Column%s" % colclass, inline = True)
|
|
||||||
|
trow.extend(
|
||||||
|
Html("th", label, class_="Column" + colclass, inline=True)
|
||||||
|
for (label, colclass) in header_row)
|
||||||
|
|
||||||
tbody = Html("tbody")
|
tbody = Html("tbody")
|
||||||
table += tbody
|
table += tbody
|
||||||
@ -4674,15 +4666,17 @@ class AddressBookListPage(BasePage):
|
|||||||
trow = Html("tr")
|
trow = Html("tr")
|
||||||
tbody += trow
|
tbody += trow
|
||||||
|
|
||||||
for (colclass, data) in [
|
header_row = [
|
||||||
["RowLabel", index],
|
["RowLabel", index],
|
||||||
["Name", self.addressbook_link(person_handle)],
|
["Name", self.addressbook_link(person_handle)],
|
||||||
["Address", address],
|
["Address", address],
|
||||||
["Residence", residence],
|
["Residence", residence],
|
||||||
["WebLinks", weblinks] ]:
|
["WebLinks", weblinks] ]
|
||||||
data = data or " "
|
|
||||||
|
|
||||||
trow += Html("td", data, class_ = "Column%s" % colclass, inline = True)
|
trow.extend(
|
||||||
|
Html("td", data or " ",
|
||||||
|
class_="Column" + colclass, inline=True)
|
||||||
|
for (colclass, data) in header_row)
|
||||||
|
|
||||||
# create totals row for table
|
# create totals row for table
|
||||||
trow = Html("tr", class_ = "Totals") + (
|
trow = Html("tr", class_ = "Totals") + (
|
||||||
@ -5265,10 +5259,7 @@ class NavWebReport(Report):
|
|||||||
index = 1
|
index = 1
|
||||||
for photo_handle in photo_keys:
|
for photo_handle in photo_keys:
|
||||||
gc.collect() # Reduce memory usage when there are many images.
|
gc.collect() # Reduce memory usage when there are many images.
|
||||||
if index == total:
|
next = None if index == total else photo_keys[index]
|
||||||
next = None
|
|
||||||
else:
|
|
||||||
next = photo_keys[index]
|
|
||||||
# Notice. Here self.photo_list[photo_handle] is used not self.photo_list
|
# 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],
|
MediaPage(self, self.title, photo_handle, source_list, self.photo_list[photo_handle],
|
||||||
(prev, next, index, total))
|
(prev, next, index, total))
|
||||||
@ -6119,11 +6110,7 @@ def _has_webpage_extension(url):
|
|||||||
|
|
||||||
url = filename to be checked
|
url = filename to be checked
|
||||||
"""
|
"""
|
||||||
|
return any(url.endswith(ext) for ext in _WEB_EXT)
|
||||||
for ext in _WEB_EXT:
|
|
||||||
if url.endswith(ext):
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
def get_event_type(event, event_ref):
|
def get_event_type(event, event_ref):
|
||||||
""" return the type of an event """
|
""" return the type of an event """
|
||||||
|
Loading…
Reference in New Issue
Block a user