0003102: Can't run Narrative Website report

Added checks for NoneType Objects.
pep8 fixes 


svn: r12939
This commit is contained in:
Raphael Ackermann
2009-08-09 22:46:55 +00:00
parent ee0f901718
commit 7bb8efc479
2 changed files with 228 additions and 225 deletions

View File

@@ -667,21 +667,21 @@ class GeoView(HtmlView):
def set_active(self):
"""
Here when we enter in this view.
Set view active when we enter into this view.
"""
self.key_active_changed = self.dbstate.connect('active-changed',
self.goto_active_person)
def set_inactive(self):
"""
Here when we go to another view.
Set view inactive when switching to another view.
"""
HtmlView.set_inactive(self)
self.dbstate.disconnect(self.key_active_changed)
def get_stock(self):
"""
Returns the name of the stock icon to use for the display.
Return the name of the stock icon to use for the display.
This assumes that this icon has already been registered with
GNOME as a stock icon.
"""
@@ -689,7 +689,7 @@ class GeoView(HtmlView):
def change_map(self, usedmap):
"""
Ask to the browser to change the current map.
Tell the browser to change the current map.
"""
self.renderer.execute_script(
"javascript:mapstraction.swap(map,'"+usedmap+"')")
@@ -817,14 +817,14 @@ class GeoView(HtmlView):
def select_openstreetmap_map(self,handle):
"""
Specifies openstreetmap is the default map
Make openstreetmap the default map.
"""
self.usedmap = "openstreetmap"
self.change_map("openstreetmap")
def select_openlayers_map(self,handle):
"""
Specifies openstreetmap is the default map
Make openstreetmap the default map.
"""
self.usedmap = "openlayers"
self.change_map("openlayers")
@@ -838,21 +838,21 @@ class GeoView(HtmlView):
def select_yahoo_map(self,handle):
"""
Specifies yahoo map is the default map
Make yahoo map the default map.
"""
self.usedmap = "yahoo"
self.change_map("yahoo")
def select_microsoft_map(self,handle):
"""
Specifies microsoft is the default map
Make microsoft the default map.
"""
self.usedmap = "microsoft"
self.change_map("microsoft")
def createpageforplaceswithoutcoord(self):
"""
This command creates a page with the list of all places without coordinates
Create a page with the list of all places without coordinates
page.
"""
data = """
@@ -1048,7 +1048,7 @@ class GeoView(HtmlView):
def createmapstractiontrailer(self):
"""
Add the last directives for the html page
Add the last directives for the html page.
"""
self.mapview.write(" </body>\n")
self.mapview.write("</html>\n")
@@ -1235,7 +1235,7 @@ class GeoView(HtmlView):
def append_to_places_without_coord(self, gid, place):
"""
Create a list of places without coordinates
Create a list of places without coordinates.
"""
self.place_without_coordinates.append([gid, place])
self.without += 1
@@ -1243,7 +1243,7 @@ class GeoView(HtmlView):
def append_to_places_list(self, place, evttype, name, lat,
longit, descr, center, year):
"""
Create a list of places with coordinates
Create a list of places with coordinates.
"""
self.place_list.append([place, name, evttype, lat,
longit, descr, int(center), year])
@@ -1294,7 +1294,7 @@ class GeoView(HtmlView):
def isyearnotinmarker(self, allyears, yeartosearch):
"""
This function is used to find if a year is in a list
Find if a year is in a list.
"""
ret = 1
for year in allyears:
@@ -1304,7 +1304,7 @@ class GeoView(HtmlView):
def create_markers(self, format, firstm, lastm):
"""
This function create all markers for the specified person.
Create all markers for the specified person.
"""
margin = 10
self.mapview.write(" <div id=\"map\" style=\"width: %dpx; " % \
@@ -1427,7 +1427,7 @@ class GeoView(HtmlView):
def createpersonmarkers(self, dbstate, person, comment):
"""
This function create all markers for the specified person.
Create all markers for the specified person.
"""
latitude = ""
longitude = ""
@@ -1440,6 +1440,7 @@ class GeoView(HtmlView):
bplace_handle = birth.get_place_handle()
if bplace_handle:
place = dbstate.db.get_place_from_handle(bplace_handle)
if place:
longitude = place.get_longitude()
latitude = place.get_latitude()
latitude, longitude = conv_lat_lon(latitude,
@@ -1474,6 +1475,7 @@ class GeoView(HtmlView):
dplace_handle = death.get_place_handle()
if dplace_handle:
place = dbstate.db.get_place_from_handle(dplace_handle)
if place:
longitude = place.get_longitude()
latitude = place.get_latitude()
latitude, longitude = conv_lat_lon(latitude,
@@ -1501,8 +1503,7 @@ class GeoView(HtmlView):
def createmapstractionplaces(self, dbstate):
"""
This function create the marker for each place in the database
which has a lat/lon.
Create the marker for each place in the database which has a lat/lon.
"""
self.place_list = []
self.place_without_coordinates = []
@@ -1545,7 +1546,7 @@ class GeoView(HtmlView):
def createmapstractionevents(self, dbstate):
"""
This function create one marker for each place associated with an event in the database
Create one marker for each place associated with an event in the database
which has a lat/lon.
"""
self.place_list = []
@@ -1562,14 +1563,15 @@ class GeoView(HtmlView):
for event_handle in dbstate.db.get_event_handles():
event = dbstate.db.get_event_from_handle( event_handle)
if event:
pl_id = event.get_place_handle()
place_handle = event.get_place_handle()
eventdate = event.get_date_object()
eventyear = eventdate.get_year()
descr1 = _("Id : %(id)s (%(year)s)") % {
'id' : event.gramps_id,
'year' : eventyear}
if pl_id:
place = dbstate.db.get_place_from_handle(pl_id)
if place_handle:
place = dbstate.db.get_place_from_handle(place_handle)
if place:
longitude = place.get_longitude()
latitude = place.get_latitude()
latitude, longitude = conv_lat_lon(latitude, longitude,
@@ -1621,7 +1623,7 @@ class GeoView(HtmlView):
def createmapstractionfamily(self, dbstate):
"""
This function create all markers for each people of a family
Create all markers for each people of a family
in the database which has a lat/lon.
"""
self.place_list = []
@@ -1680,8 +1682,8 @@ class GeoView(HtmlView):
def createmapstractionperson(self, dbstate):
"""
This function create all markers for each people's event
in the database which has a lat/lon.
Create all markers for each people's event in the database which has
a lat/lon.
"""
self.place_list = []
self.place_without_coordinates = []
@@ -1711,6 +1713,7 @@ class GeoView(HtmlView):
place_handle = event.get_place_handle()
if place_handle:
place = dbstate.db.get_place_from_handle(place_handle)
if place:
longitude = place.get_longitude()
latitude = place.get_latitude()
latitude, longitude = conv_lat_lon(latitude,
@@ -1747,7 +1750,7 @@ class GeoView(HtmlView):
def createmapnotimplemented(self):
"""
This function is used to inform the user this work is not implemented.
Inform the user this work is not implemented.
"""
self.mapview.write(" <H1>%s </H1>" % _("Not yet implemented ..."))

View File

@@ -181,9 +181,9 @@ class PrivateProxyDb(ProxyDbBase):
Finds a MediaObject in the database from the passed gramps' ID.
If no such MediaObject exists, None is returned.
"""
object = self.db.get_object_from_gramps_id(val)
if not object.get_privacy():
return sanitize_media(self.db, object)
obj = self.db.get_object_from_gramps_id(val)
if not obj.get_privacy():
return sanitize_media(self.db, obj)
return None
def get_repository_from_gramps_id(self, val):
@@ -321,7 +321,7 @@ class PrivateProxyDb(ProxyDbBase):
def has_family_handle(self, handle):
"""
returns True if the handle exists in the current Family database.
Return True if the handle exists in the current Family database.
"""
has_family = False
family = self.db.get_family_from_handle()
@@ -331,7 +331,7 @@ class PrivateProxyDb(ProxyDbBase):
def has_object_handle(self, handle):
"""
returns True if the handle exists in the current MediaObjectdatabase.
Return True if the handle exists in the current MediaObjectdatabase.
"""
has_object = False
object = self.db.get_object_from_handle()
@@ -341,7 +341,7 @@ class PrivateProxyDb(ProxyDbBase):
def has_repository_handle(self, handle):
"""
returns True if the handle exists in the current Repository database.
Return True if the handle exists in the current Repository database.
"""
has_repository = False
repository = self.db.get_repository_from_handle()
@@ -351,7 +351,7 @@ class PrivateProxyDb(ProxyDbBase):
def has_note_handle(self, handle):
"""
returns True if the handle exists in the current Note database.
Return True if the handle exists in the current Note database.
"""
has_note = False
note = self.db.get_note_from_handle()
@@ -362,7 +362,7 @@ class PrivateProxyDb(ProxyDbBase):
def find_backlink_handles(self, handle, include_classes=None):
"""
Find all objects that hold a reference to the object handle.
Returns an interator over alist of (class_name, handle) tuples.
Returns an iterator over a list of (class_name, handle) tuples.
@param handle: handle of the object to search for.
@type handle: database handle
@@ -370,7 +370,7 @@ class PrivateProxyDb(ProxyDbBase):
Default: None means include all classes.
@type include_classes: list of class names
This default implementation does a sequencial scan through all
This default implementation does a sequential scan through all
the primary object databases and is very slow. Backends can
override this method to provide much faster implementations that
make use of additional capabilities of the backend.
@@ -769,7 +769,7 @@ def sanitize_person(db,person):
for event_ref in person.get_event_ref_list():
if event_ref and not event_ref.get_privacy():
event = db.get_event_from_handle(event_ref.ref)
if not event.get_privacy():
if event and not event.get_privacy():
new_person.add_event_ref(sanitize_event_ref(db, event_ref))
# Copy birth and death after event list to maintain the order.
@@ -777,14 +777,14 @@ def sanitize_person(db,person):
event_ref = person.get_birth_ref()
if event_ref and not event_ref.get_privacy():
event = db.get_event_from_handle(event_ref.ref)
if not event.get_privacy():
if event and not event.get_privacy():
new_person.set_birth_ref(sanitize_event_ref(db, event_ref))
# copy death event
event_ref = person.get_death_ref()
if event_ref and not event_ref.get_privacy():
event = db.get_event_from_handle(event_ref.ref)
if not event.get_privacy():
if event and not event.get_privacy():
new_person.set_death_ref(sanitize_event_ref(db, event_ref))
copy_addresses(db, person, new_person)
@@ -963,7 +963,7 @@ def sanitize_family(db,family):
mother_handle = family.get_mother_handle()
if mother_handle:
mother = db.get_person_from_handle(mother_handle)
if not mother.get_privacy():
if mother and not mother.get_privacy():
new_family.set_mother_handle(mother_handle)
# Copy child references.
@@ -987,7 +987,7 @@ def sanitize_family(db,family):
for event_ref in family.get_event_ref_list():
if event_ref and not event_ref.get_privacy():
event = db.get_event_from_handle(event_ref.ref)
if not event.get_privacy():
if event and not event.get_privacy():
new_family.add_event_ref(sanitize_event_ref(db, event_ref))
copy_source_ref_list(db, family, new_family)
@@ -1006,7 +1006,7 @@ def sanitize_repository(db,repository):
@param db: GRAMPS database to which the Person object belongs
@type db: GrampsDbBase
@param repository: source Repsitory object that will be copied with
@param repository: source Repository object that will be copied with
privacy records removed
@type repository: Repository
@returns: 'cleansed' Repository object