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): 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.key_active_changed = self.dbstate.connect('active-changed',
self.goto_active_person) self.goto_active_person)
def set_inactive(self): def set_inactive(self):
""" """
Here when we go to another view. Set view inactive when switching to another view.
""" """
HtmlView.set_inactive(self) HtmlView.set_inactive(self)
self.dbstate.disconnect(self.key_active_changed) self.dbstate.disconnect(self.key_active_changed)
def get_stock(self): 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 This assumes that this icon has already been registered with
GNOME as a stock icon. GNOME as a stock icon.
""" """
@@ -689,7 +689,7 @@ class GeoView(HtmlView):
def change_map(self, usedmap): 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( self.renderer.execute_script(
"javascript:mapstraction.swap(map,'"+usedmap+"')") "javascript:mapstraction.swap(map,'"+usedmap+"')")
@@ -817,14 +817,14 @@ class GeoView(HtmlView):
def select_openstreetmap_map(self,handle): def select_openstreetmap_map(self,handle):
""" """
Specifies openstreetmap is the default map Make openstreetmap the default map.
""" """
self.usedmap = "openstreetmap" self.usedmap = "openstreetmap"
self.change_map("openstreetmap") self.change_map("openstreetmap")
def select_openlayers_map(self,handle): def select_openlayers_map(self,handle):
""" """
Specifies openstreetmap is the default map Make openstreetmap the default map.
""" """
self.usedmap = "openlayers" self.usedmap = "openlayers"
self.change_map("openlayers") self.change_map("openlayers")
@@ -838,21 +838,21 @@ class GeoView(HtmlView):
def select_yahoo_map(self,handle): def select_yahoo_map(self,handle):
""" """
Specifies yahoo map is the default map Make yahoo map the default map.
""" """
self.usedmap = "yahoo" self.usedmap = "yahoo"
self.change_map("yahoo") self.change_map("yahoo")
def select_microsoft_map(self,handle): def select_microsoft_map(self,handle):
""" """
Specifies microsoft is the default map Make microsoft the default map.
""" """
self.usedmap = "microsoft" self.usedmap = "microsoft"
self.change_map("microsoft") self.change_map("microsoft")
def createpageforplaceswithoutcoord(self): 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. page.
""" """
data = """ data = """
@@ -1048,7 +1048,7 @@ class GeoView(HtmlView):
def createmapstractiontrailer(self): 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(" </body>\n")
self.mapview.write("</html>\n") self.mapview.write("</html>\n")
@@ -1235,7 +1235,7 @@ class GeoView(HtmlView):
def append_to_places_without_coord(self, gid, place): 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.place_without_coordinates.append([gid, place])
self.without += 1 self.without += 1
@@ -1243,7 +1243,7 @@ class GeoView(HtmlView):
def append_to_places_list(self, place, evttype, name, lat, def append_to_places_list(self, place, evttype, name, lat,
longit, descr, center, year): 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, self.place_list.append([place, name, evttype, lat,
longit, descr, int(center), year]) longit, descr, int(center), year])
@@ -1294,7 +1294,7 @@ class GeoView(HtmlView):
def isyearnotinmarker(self, allyears, yeartosearch): 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 ret = 1
for year in allyears: for year in allyears:
@@ -1304,7 +1304,7 @@ class GeoView(HtmlView):
def create_markers(self, format, firstm, lastm): 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 margin = 10
self.mapview.write(" <div id=\"map\" style=\"width: %dpx; " % \ self.mapview.write(" <div id=\"map\" style=\"width: %dpx; " % \
@@ -1427,7 +1427,7 @@ class GeoView(HtmlView):
def createpersonmarkers(self, dbstate, person, comment): def createpersonmarkers(self, dbstate, person, comment):
""" """
This function create all markers for the specified person. Create all markers for the specified person.
""" """
latitude = "" latitude = ""
longitude = "" longitude = ""
@@ -1440,30 +1440,31 @@ class GeoView(HtmlView):
bplace_handle = birth.get_place_handle() bplace_handle = birth.get_place_handle()
if bplace_handle: if bplace_handle:
place = dbstate.db.get_place_from_handle(bplace_handle) place = dbstate.db.get_place_from_handle(bplace_handle)
longitude = place.get_longitude() if place:
latitude = place.get_latitude() longitude = place.get_longitude()
latitude, longitude = conv_lat_lon(latitude, latitude = place.get_latitude()
longitude, "D.D8") latitude, longitude = conv_lat_lon(latitude,
if comment: longitude, "D.D8")
descr1 = _("%(comment)s : birth place.") % { if comment:
'comment': comment} descr1 = _("%(comment)s : birth place.") % {
else: 'comment': comment}
descr1 = _("birth place.") else:
descr = place.get_title() descr1 = _("birth place.")
# place.get_longitude and place.get_latitude return descr = place.get_title()
# one string. We have coordinates when the two values # place.get_longitude and place.get_latitude return
# contains non null string. # one string. We have coordinates when the two values
if ( longitude and latitude ): # contains non null string.
self.append_to_places_list(descr, if ( longitude and latitude ):
gen.lib.EventType.BIRTH, self.append_to_places_list(descr,
_nd.display(person), gen.lib.EventType.BIRTH,
latitude, longitude, _nd.display(person),
descr1, int(self.center), latitude, longitude,
birthyear) descr1, int(self.center),
self.center = False birthyear)
else: self.center = False
self.append_to_places_without_coord(place.gramps_id, else:
descr) self.append_to_places_without_coord(place.gramps_id,
descr)
latitude = "" latitude = ""
longitude = "" longitude = ""
death_ref = person.get_death_ref() death_ref = person.get_death_ref()
@@ -1474,35 +1475,35 @@ class GeoView(HtmlView):
dplace_handle = death.get_place_handle() dplace_handle = death.get_place_handle()
if dplace_handle: if dplace_handle:
place = dbstate.db.get_place_from_handle(dplace_handle) place = dbstate.db.get_place_from_handle(dplace_handle)
longitude = place.get_longitude() if place:
latitude = place.get_latitude() longitude = place.get_longitude()
latitude, longitude = conv_lat_lon(latitude, latitude = place.get_latitude()
longitude, "D.D8") latitude, longitude = conv_lat_lon(latitude,
descr = place.get_title() longitude, "D.D8")
if comment: descr = place.get_title()
descr1 = _("%(comment)s : death place.") % { if comment:
'comment': comment} descr1 = _("%(comment)s : death place.") % {
else: 'comment': comment}
descr1 = _("death place.") else:
# place.get_longitude and place.get_latitude return descr1 = _("death place.")
# one string. We have coordinates when the two values # place.get_longitude and place.get_latitude return
# contains non null string. # one string. We have coordinates when the two values
if ( longitude and latitude ): # contains non null string.
self.append_to_places_list(descr, if ( longitude and latitude ):
gen.lib.EventType.DEATH, self.append_to_places_list(descr,
_nd.display(person), gen.lib.EventType.DEATH,
latitude, longitude, _nd.display(person),
descr1, int(self.center), latitude, longitude,
deathyear) descr1, int(self.center),
self.center = False deathyear)
else: self.center = False
self.append_to_places_without_coord(place.gramps_id, else:
descr) self.append_to_places_without_coord(place.gramps_id,
descr)
def createmapstractionplaces(self, dbstate): def createmapstractionplaces(self, dbstate):
""" """
This function create the marker for each place in the database Create the marker for each place in the database which has a lat/lon.
which has a lat/lon.
""" """
self.place_list = [] self.place_list = []
self.place_without_coordinates = [] self.place_without_coordinates = []
@@ -1545,7 +1546,7 @@ class GeoView(HtmlView):
def createmapstractionevents(self, dbstate): 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. which has a lat/lon.
""" """
self.place_list = [] self.place_list = []
@@ -1562,56 +1563,57 @@ class GeoView(HtmlView):
for event_handle in dbstate.db.get_event_handles(): for event_handle in dbstate.db.get_event_handles():
event = dbstate.db.get_event_from_handle( event_handle) event = dbstate.db.get_event_from_handle( event_handle)
if event: if event:
pl_id = event.get_place_handle() place_handle = event.get_place_handle()
eventdate = event.get_date_object() eventdate = event.get_date_object()
eventyear = eventdate.get_year() eventyear = eventdate.get_year()
descr1 = _("Id : %(id)s (%(year)s)") % { descr1 = _("Id : %(id)s (%(year)s)") % {
'id' : event.gramps_id, 'id' : event.gramps_id,
'year' : eventyear} 'year' : eventyear}
if pl_id: if place_handle:
place = dbstate.db.get_place_from_handle(pl_id) place = dbstate.db.get_place_from_handle(place_handle)
longitude = place.get_longitude() if place:
latitude = place.get_latitude() longitude = place.get_longitude()
latitude, longitude = conv_lat_lon(latitude, longitude, latitude = place.get_latitude()
"D.D8") latitude, longitude = conv_lat_lon(latitude, longitude,
city = place.get_main_location().get_city() "D.D8")
country = place.get_main_location().get_country() city = place.get_main_location().get_city()
descr2 = "%s; %s" % (city, country) country = place.get_main_location().get_country()
# place.get_longitude and place.get_latitude return descr2 = "%s; %s" % (city, country)
# one string. We have coordinates when the two values # place.get_longitude and place.get_latitude return
# contains non null string. # one string. We have coordinates when the two values
if ( longitude and latitude ): # contains non null string.
person_list = [dbstate.db.get_person_from_handle(ref_handle) if ( longitude and latitude ):
for (ref_type, ref_handle) in \ person_list = [dbstate.db.get_person_from_handle(ref_handle)
dbstate.db.find_backlink_handles(event_handle) for (ref_type, ref_handle) in \
if ref_type == 'Person' dbstate.db.find_backlink_handles(event_handle)
] if ref_type == 'Person'
if person_list: ]
descr = "<br>" if person_list:
for person in person_list: descr = "<br>"
descr = ("%(description)s%(name)s<br>") % { for person in person_list:
'description' : descr, descr = ("%(description)s%(name)s<br>") % {
'name' : _nd.display(person)} 'description' : descr,
descr = ("%(eventtype)s; %(place)s%(description)s" 'name' : _nd.display(person)}
) % { 'eventtype': gen.lib.EventType( descr = ("%(eventtype)s; %(place)s%(description)s"
event.get_type()), ) % { 'eventtype': gen.lib.EventType(
'place': place.get_title(), event.get_type()),
'description': descr} 'place': place.get_title(),
'description': descr}
else:
descr = ("%(eventtype)s; %(place)s<br>") % {
'eventtype': gen.lib.EventType(
event.get_type()),
'place': place.get_title()}
self.append_to_places_list(descr1, descr,
descr,
latitude, longitude,
descr2, self.center,
eventyear)
self.center = False
else: else:
descr = ("%(eventtype)s; %(place)s<br>") % { descr = place.get_title()
'eventtype': gen.lib.EventType( self.append_to_places_without_coord(place.gramps_id,
event.get_type()), descr)
'place': place.get_title()}
self.append_to_places_list(descr1, descr,
descr,
latitude, longitude,
descr2, self.center,
eventyear)
self.center = False
else:
descr = place.get_title()
self.append_to_places_without_coord(place.gramps_id,
descr)
if self.center: if self.center:
mess = _("Cannot center the map. No location with coordinates.") mess = _("Cannot center the map. No location with coordinates.")
else: else:
@@ -1621,7 +1623,7 @@ class GeoView(HtmlView):
def createmapstractionfamily(self, dbstate): 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. in the database which has a lat/lon.
""" """
self.place_list = [] self.place_list = []
@@ -1680,8 +1682,8 @@ class GeoView(HtmlView):
def createmapstractionperson(self, dbstate): def createmapstractionperson(self, dbstate):
""" """
This function create all markers for each people's event Create all markers for each people's event in the database which has
in the database which has a lat/lon. a lat/lon.
""" """
self.place_list = [] self.place_list = []
self.place_without_coordinates = [] self.place_without_coordinates = []
@@ -1711,28 +1713,29 @@ class GeoView(HtmlView):
place_handle = event.get_place_handle() place_handle = event.get_place_handle()
if place_handle: if place_handle:
place = dbstate.db.get_place_from_handle(place_handle) place = dbstate.db.get_place_from_handle(place_handle)
longitude = place.get_longitude() if place:
latitude = place.get_latitude() longitude = place.get_longitude()
latitude, longitude = conv_lat_lon(latitude, latitude = place.get_latitude()
longitude, "D.D8") latitude, longitude = conv_lat_lon(latitude,
descr = place.get_title() longitude, "D.D8")
evt = gen.lib.EventType(event.get_type()) descr = place.get_title()
descr1 = _("%(eventtype)s : %(name)s") % { evt = gen.lib.EventType(event.get_type())
'eventtype': evt, descr1 = _("%(eventtype)s : %(name)s") % {
'name': _nd.display(person)} 'eventtype': evt,
# place.get_longitude and place.get_latitude return 'name': _nd.display(person)}
# one string. We have coordinates when the two values # place.get_longitude and place.get_latitude return
# contains non null string. # one string. We have coordinates when the two values
if ( longitude and latitude ): # contains non null string.
self.append_to_places_list(descr, evt, if ( longitude and latitude ):
_nd.display(person), self.append_to_places_list(descr, evt,
latitude, longitude, _nd.display(person),
descr1, self.center, latitude, longitude,
eventyear) descr1, self.center,
self.center = False eventyear)
else: self.center = False
self.append_to_places_without_coord( else:
place.gramps_id, descr) self.append_to_places_without_coord(
place.gramps_id, descr)
if self.center: if self.center:
mess = _("Cannot center the map. No location with coordinates.") mess = _("Cannot center the map. No location with coordinates.")
if person is not None: if person is not None:
@@ -1747,7 +1750,7 @@ class GeoView(HtmlView):
def createmapnotimplemented(self): 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 ...")) self.mapview.write(" <H1>%s </H1>" % _("Not yet implemented ..."))

View File

@@ -40,7 +40,7 @@ class PrivateProxyDb(ProxyDbBase):
but all data marked private will be hidden from the user. but all data marked private will be hidden from the user.
""" """
def __init__(self,db): def __init__(self, db):
""" """
Create a new PrivateProxyDb instance. Create a new PrivateProxyDb instance.
""" """
@@ -53,7 +53,7 @@ class PrivateProxyDb(ProxyDbBase):
""" """
person = self.db.get_person_from_handle(handle) person = self.db.get_person_from_handle(handle)
if person and not person.get_privacy(): if person and not person.get_privacy():
return sanitize_person(self.db,person) return sanitize_person(self.db, person)
return None return None
def get_source_from_handle(self, handle): def get_source_from_handle(self, handle):
@@ -63,7 +63,7 @@ class PrivateProxyDb(ProxyDbBase):
""" """
source = self.db.get_source_from_handle(handle) source = self.db.get_source_from_handle(handle)
if source and not source.get_privacy(): if source and not source.get_privacy():
return sanitize_source(self.db,source) return sanitize_source(self.db, source)
return None return None
def get_object_from_handle(self, handle): def get_object_from_handle(self, handle):
@@ -73,7 +73,7 @@ class PrivateProxyDb(ProxyDbBase):
""" """
media = self.db.get_object_from_handle(handle) media = self.db.get_object_from_handle(handle)
if media and not media.get_privacy(): if media and not media.get_privacy():
return sanitize_media(self.db,media) return sanitize_media(self.db, media)
return None return None
def get_place_from_handle(self, handle): def get_place_from_handle(self, handle):
@@ -83,7 +83,7 @@ class PrivateProxyDb(ProxyDbBase):
""" """
place = self.db.get_place_from_handle(handle) place = self.db.get_place_from_handle(handle)
if place and not place.get_privacy(): if place and not place.get_privacy():
return sanitize_place(self.db,place) return sanitize_place(self.db, place)
return None return None
def get_event_from_handle(self, handle): def get_event_from_handle(self, handle):
@@ -93,7 +93,7 @@ class PrivateProxyDb(ProxyDbBase):
""" """
event = self.db.get_event_from_handle(handle) event = self.db.get_event_from_handle(handle)
if event and not event.get_privacy(): if event and not event.get_privacy():
return sanitize_event(self.db,event) return sanitize_event(self.db, event)
return None return None
def get_family_from_handle(self, handle): def get_family_from_handle(self, handle):
@@ -103,7 +103,7 @@ class PrivateProxyDb(ProxyDbBase):
""" """
family = self.db.get_family_from_handle(handle) family = self.db.get_family_from_handle(handle)
if family and not family.get_privacy(): if family and not family.get_privacy():
return sanitize_family(self.db,family) return sanitize_family(self.db, family)
return None return None
def get_repository_from_handle(self, handle): def get_repository_from_handle(self, handle):
@@ -113,7 +113,7 @@ class PrivateProxyDb(ProxyDbBase):
""" """
repository = self.db.get_repository_from_handle(handle) repository = self.db.get_repository_from_handle(handle)
if repository and not repository.get_privacy(): if repository and not repository.get_privacy():
return sanitize_repository(self.db,repository) return sanitize_repository(self.db, repository)
return None return None
def get_note_from_handle(self, handle): def get_note_from_handle(self, handle):
@@ -133,7 +133,7 @@ class PrivateProxyDb(ProxyDbBase):
""" """
person = self.db.get_person_from_gramps_id(val) person = self.db.get_person_from_gramps_id(val)
if not person.get_privacy(): if not person.get_privacy():
return sanitize_person(self.db,person) return sanitize_person(self.db, person)
return None return None
def get_family_from_gramps_id(self, val): def get_family_from_gramps_id(self, val):
@@ -143,7 +143,7 @@ class PrivateProxyDb(ProxyDbBase):
""" """
family = self.db.get_family_from_gramps_id(val) family = self.db.get_family_from_gramps_id(val)
if not family.get_privacy(): if not family.get_privacy():
return sanitize_family(self.db,family) return sanitize_family(self.db, family)
return None return None
def get_event_from_gramps_id(self, val): def get_event_from_gramps_id(self, val):
@@ -153,7 +153,7 @@ class PrivateProxyDb(ProxyDbBase):
""" """
event = self.db.get_event_from_gramps_id(val) event = self.db.get_event_from_gramps_id(val)
if not event.get_privacy(): if not event.get_privacy():
return sanitize_event(self.db,event) return sanitize_event(self.db, event)
return None return None
def get_place_from_gramps_id(self, val): def get_place_from_gramps_id(self, val):
@@ -163,7 +163,7 @@ class PrivateProxyDb(ProxyDbBase):
""" """
place = self.db.get_place_from_gramps_id(val) place = self.db.get_place_from_gramps_id(val)
if not place.get_privacy(): if not place.get_privacy():
return sanitize_place(self.db,place) return sanitize_place(self.db, place)
return None return None
def get_source_from_gramps_id(self, val): def get_source_from_gramps_id(self, val):
@@ -173,7 +173,7 @@ class PrivateProxyDb(ProxyDbBase):
""" """
source = self.db.get_source_from_gramps_id(val) source = self.db.get_source_from_gramps_id(val)
if not source.get_privacy(): if not source.get_privacy():
return sanitize_source(self.db,source) return sanitize_source(self.db, source)
return None return None
def get_object_from_gramps_id(self, val): def get_object_from_gramps_id(self, val):
@@ -181,9 +181,9 @@ class PrivateProxyDb(ProxyDbBase):
Finds a MediaObject in the database from the passed gramps' ID. Finds a MediaObject in the database from the passed gramps' ID.
If no such MediaObject exists, None is returned. If no such MediaObject exists, None is returned.
""" """
object = self.db.get_object_from_gramps_id(val) obj = self.db.get_object_from_gramps_id(val)
if not object.get_privacy(): if not obj.get_privacy():
return sanitize_media(self.db, object) return sanitize_media(self.db, obj)
return None return None
def get_repository_from_gramps_id(self, val): def get_repository_from_gramps_id(self, val):
@@ -193,7 +193,7 @@ class PrivateProxyDb(ProxyDbBase):
""" """
repository = self.db.get_repository_from_gramps_id(val) repository = self.db.get_repository_from_gramps_id(val)
if not repository.get_privacy(): if not repository.get_privacy():
return sanitize_repository(self.db,repository) return sanitize_repository(self.db, repository)
return None return None
def get_note_from_gramps_id(self, val): def get_note_from_gramps_id(self, val):
@@ -268,7 +268,7 @@ class PrivateProxyDb(ProxyDbBase):
"""returns the default Person of the database""" """returns the default Person of the database"""
person = self.db.get_default_person() person = self.db.get_default_person()
if person and not person.get_privacy(): if person and not person.get_privacy():
return sanitize_person(self.db,person) return sanitize_person(self.db, person)
return None return None
def get_default_handle(self): def get_default_handle(self):
@@ -286,7 +286,7 @@ class PrivateProxyDb(ProxyDbBase):
has_person = False has_person = False
person = self.db.get_person_from_handle() person = self.db.get_person_from_handle()
if person and not person.get_privacy(): if person and not person.get_privacy():
has_person = True has_person = True
return has_person return has_person
def has_event_handle(self, handle): def has_event_handle(self, handle):
@@ -296,7 +296,7 @@ class PrivateProxyDb(ProxyDbBase):
has_event = False has_event = False
event = self.db.get_event_from_handle() event = self.db.get_event_from_handle()
if event and not event.get_privacy(): if event and not event.get_privacy():
has_event = True has_event = True
return has_event return has_event
def has_source_handle(self, handle): def has_source_handle(self, handle):
@@ -306,7 +306,7 @@ class PrivateProxyDb(ProxyDbBase):
has_source = False has_source = False
source = self.db.get_source_from_handle() source = self.db.get_source_from_handle()
if source and not source.get_privacy(): if source and not source.get_privacy():
has_source = True has_source = True
return has_source return has_source
def has_place_handle(self, handle): def has_place_handle(self, handle):
@@ -316,53 +316,53 @@ class PrivateProxyDb(ProxyDbBase):
has_place = False has_place = False
place = self.db.get_place_from_handle() place = self.db.get_place_from_handle()
if place and not place.get_privacy(): if place and not place.get_privacy():
has_place = True has_place = True
return has_place return has_place
def has_family_handle(self, handle): 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 has_family = False
family = self.db.get_family_from_handle() family = self.db.get_family_from_handle()
if family and not family.get_privacy(): if family and not family.get_privacy():
has_family = True has_family = True
return has_family return has_family
def has_object_handle(self, handle): 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 has_object = False
object = self.db.get_object_from_handle() object = self.db.get_object_from_handle()
if object and not object.get_privacy(): if object and not object.get_privacy():
has_object = True has_object = True
return has_object return has_object
def has_repository_handle(self, handle): 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 has_repository = False
repository = self.db.get_repository_from_handle() repository = self.db.get_repository_from_handle()
if repository and not repository.get_privacy(): if repository and not repository.get_privacy():
has_repository = True has_repository = True
return has_repository return has_repository
def has_note_handle(self, handle): 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 has_note = False
note = self.db.get_note_from_handle() note = self.db.get_note_from_handle()
if note and not note.get_privacy(): if note and not note.get_privacy():
has_note = True has_note = True
return has_note return has_note
def find_backlink_handles(self, handle, include_classes=None): def find_backlink_handles(self, handle, include_classes=None):
""" """
Find all objects that hold a reference to the object handle. 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. @param handle: handle of the object to search for.
@type handle: database handle @type handle: database handle
@@ -370,7 +370,7 @@ class PrivateProxyDb(ProxyDbBase):
Default: None means include all classes. Default: None means include all classes.
@type include_classes: list of class names @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 the primary object databases and is very slow. Backends can
override this method to provide much faster implementations that override this method to provide much faster implementations that
make use of additional capabilities of the backend. make use of additional capabilities of the backend.
@@ -411,7 +411,7 @@ class PrivateProxyDb(ProxyDbBase):
return return
def copy_media_ref_list(db, original_obj,clean_obj): def copy_media_ref_list(db, original_obj, clean_obj):
""" """
Copies media references from one object to another - excluding private Copies media references from one object to another - excluding private
references and references to private objects. references and references to private objects.
@@ -431,7 +431,7 @@ def copy_media_ref_list(db, original_obj,clean_obj):
if not media_object.get_privacy(): if not media_object.get_privacy():
clean_obj.add_media_reference(sanitize_media_ref(db, media_ref)) clean_obj.add_media_reference(sanitize_media_ref(db, media_ref))
def copy_source_ref_list(db, original_obj,clean_obj): def copy_source_ref_list(db, original_obj, clean_obj):
""" """
Copies source references from one object to another - excluding private Copies source references from one object to another - excluding private
references and references to private objects. references and references to private objects.
@@ -451,7 +451,7 @@ def copy_source_ref_list(db, original_obj,clean_obj):
if not source.get_privacy(): if not source.get_privacy():
clean_obj.add_source_reference(sanitize_source_ref(db, ref)) clean_obj.add_source_reference(sanitize_source_ref(db, ref))
def copy_notes(db, original_obj,clean_obj): def copy_notes(db, original_obj, clean_obj):
""" """
Copies notes from one object to another - excluding references to private Copies notes from one object to another - excluding references to private
notes. notes.
@@ -469,7 +469,7 @@ def copy_notes(db, original_obj,clean_obj):
if not note.get_privacy(): if not note.get_privacy():
clean_obj.add_note(note_handle) clean_obj.add_note(note_handle)
def copy_attributes(db, original_obj,clean_obj): def copy_attributes(db, original_obj, clean_obj):
""" """
Copies attributes from one object to another - excluding references to Copies attributes from one object to another - excluding references to
private attributes. private attributes.
@@ -487,11 +487,11 @@ def copy_attributes(db, original_obj,clean_obj):
new_attribute = Attribute() new_attribute = Attribute()
new_attribute.set_type(attribute.get_type()) new_attribute.set_type(attribute.get_type())
new_attribute.set_value(attribute.get_value()) new_attribute.set_value(attribute.get_value())
copy_notes(db,attribute, new_attribute) copy_notes(db, attribute, new_attribute)
copy_source_ref_list(db,attribute, new_attribute) copy_source_ref_list(db, attribute, new_attribute)
clean_obj.add_attribute(new_attribute) clean_obj.add_attribute(new_attribute)
def copy_urls(db, original_obj,clean_obj): def copy_urls(db, original_obj, clean_obj):
""" """
Copies urls from one object to another - excluding references to Copies urls from one object to another - excluding references to
private urls. private urls.
@@ -508,7 +508,7 @@ def copy_urls(db, original_obj,clean_obj):
if not url.get_privacy(): if not url.get_privacy():
clean_obj.add_url(url) clean_obj.add_url(url)
def copy_lds_ords(db, original_obj,clean_obj): def copy_lds_ords(db, original_obj, clean_obj):
""" """
Copies LDS ORDs from one object to another - excluding references to Copies LDS ORDs from one object to another - excluding references to
private LDS ORDs. private LDS ORDs.
@@ -525,7 +525,7 @@ def copy_lds_ords(db, original_obj,clean_obj):
if not lds_ord.get_privacy(): if not lds_ord.get_privacy():
clean_obj.add_lds_ord(sanitize_lds_ord(db, lds_ord)) clean_obj.add_lds_ord(sanitize_lds_ord(db, lds_ord))
def copy_addresses(db, original_obj,clean_obj): def copy_addresses(db, original_obj, clean_obj):
""" """
Copies addresses from one object to another - excluding references to Copies addresses from one object to another - excluding references to
private addresses. private addresses.
@@ -704,12 +704,12 @@ def sanitize_event_ref(db, event_ref):
new_ref.set_reference_handle(event_ref.get_reference_handle()) new_ref.set_reference_handle(event_ref.get_reference_handle())
new_ref.set_role(event_ref.get_role()) new_ref.set_role(event_ref.get_role())
copy_notes(db,event_ref, new_ref) copy_notes(db, event_ref, new_ref)
copy_attributes(db,event_ref, new_ref) copy_attributes(db, event_ref, new_ref)
return new_ref return new_ref
def sanitize_person(db,person): def sanitize_person(db, person):
""" """
Create a new Person instance based off the passed Person Create a new Person instance based off the passed Person
instance. The returned instance has all private records instance. The returned instance has all private records
@@ -769,35 +769,35 @@ def sanitize_person(db,person):
for event_ref in person.get_event_ref_list(): for event_ref in person.get_event_ref_list():
if event_ref and not event_ref.get_privacy(): if event_ref and not event_ref.get_privacy():
event = db.get_event_from_handle(event_ref.ref) 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)) new_person.add_event_ref(sanitize_event_ref(db, event_ref))
# Copy birth and death after event list to maintain the order. # Copy birth and death after event list to maintain the order.
# copy birth event # copy birth event
event_ref = person.get_birth_ref() event_ref = person.get_birth_ref()
if event_ref and not event_ref.get_privacy(): if event_ref and not event_ref.get_privacy():
event = db.get_event_from_handle(event_ref.ref) 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)) new_person.set_birth_ref(sanitize_event_ref(db, event_ref))
# copy death event # copy death event
event_ref = person.get_death_ref() event_ref = person.get_death_ref()
if event_ref and not event_ref.get_privacy(): if event_ref and not event_ref.get_privacy():
event = db.get_event_from_handle(event_ref.ref) 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)) new_person.set_death_ref(sanitize_event_ref(db, event_ref))
copy_addresses(db,person, new_person) copy_addresses(db, person, new_person)
copy_attributes(db,person, new_person) copy_attributes(db, person, new_person)
copy_source_ref_list(db,person, new_person) copy_source_ref_list(db, person, new_person)
copy_urls(db,person, new_person) copy_urls(db, person, new_person)
copy_media_ref_list(db,person, new_person) copy_media_ref_list(db, person, new_person)
copy_lds_ords(db,person, new_person) copy_lds_ords(db, person, new_person)
copy_notes(db,person, new_person) copy_notes(db, person, new_person)
return new_person return new_person
def sanitize_source(db,source): def sanitize_source(db, source):
""" """
Create a new Source instance based off the passed Source Create a new Source instance based off the passed Source
instance. The returned instance has all private records instance. The returned instance has all private records
@@ -829,12 +829,12 @@ def sanitize_source(db,source):
if not repo.get_privacy(): if not repo.get_privacy():
new_source.add_repo_reference(RepoRef(repo_ref)) new_source.add_repo_reference(RepoRef(repo_ref))
copy_media_ref_list(db,source, new_source) copy_media_ref_list(db, source, new_source)
copy_notes(db,source, new_source) copy_notes(db, source, new_source)
return new_source return new_source
def sanitize_media(db,media): def sanitize_media(db, media):
""" """
Create a new MediaObject instance based off the passed Media Create a new MediaObject instance based off the passed Media
instance. The returned instance has all private records instance. The returned instance has all private records
@@ -858,13 +858,13 @@ def sanitize_media(db,media):
new_media.set_date_object(media.get_date_object()) new_media.set_date_object(media.get_date_object())
new_media.set_marker(media.get_marker()) new_media.set_marker(media.get_marker())
copy_source_ref_list(db,media, new_media) copy_source_ref_list(db, media, new_media)
copy_attributes(db,media, new_media) copy_attributes(db, media, new_media)
copy_notes(db,media, new_media) copy_notes(db, media, new_media)
return new_media return new_media
def sanitize_place(db,place): def sanitize_place(db, place):
""" """
Create a new Place instance based off the passed Place Create a new Place instance based off the passed Place
instance. The returned instance has all private records instance. The returned instance has all private records
@@ -889,10 +889,10 @@ def sanitize_place(db,place):
new_place.set_alternate_locations(place.get_alternate_locations()) new_place.set_alternate_locations(place.get_alternate_locations())
new_place.set_marker(place.get_marker()) new_place.set_marker(place.get_marker())
copy_source_ref_list(db,place, new_place) copy_source_ref_list(db, place, new_place)
copy_notes(db,place, new_place) copy_notes(db, place, new_place)
copy_media_ref_list(db,place, new_place) copy_media_ref_list(db, place, new_place)
copy_urls(db,place, new_place) copy_urls(db, place, new_place)
return new_place return new_place
@@ -919,10 +919,10 @@ def sanitize_event(db,event):
new_event.set_date_object(event.get_date_object()) new_event.set_date_object(event.get_date_object())
new_event.set_marker(event.get_marker()) new_event.set_marker(event.get_marker())
copy_source_ref_list(db,event, new_event) copy_source_ref_list(db, event, new_event)
copy_notes(db,event, new_event) copy_notes(db, event, new_event)
copy_media_ref_list(db,event, new_event) copy_media_ref_list(db, event, new_event)
copy_attributes(db,event, new_event) copy_attributes(db, event, new_event)
place_handle = event.get_place_handle() place_handle = event.get_place_handle()
place = db.get_place_from_handle(place_handle) place = db.get_place_from_handle(place_handle)
@@ -931,7 +931,7 @@ def sanitize_event(db,event):
return new_event return new_event
def sanitize_family(db,family): def sanitize_family(db, family):
""" """
Create a new Family instance based off the passed Family Create a new Family instance based off the passed Family
instance. The returned instance has all private records instance. The returned instance has all private records
@@ -963,7 +963,7 @@ def sanitize_family(db,family):
mother_handle = family.get_mother_handle() mother_handle = family.get_mother_handle()
if mother_handle: if mother_handle:
mother = db.get_person_from_handle(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) new_family.set_mother_handle(mother_handle)
# Copy child references. # Copy child references.
@@ -979,26 +979,26 @@ def sanitize_family(db,family):
new_ref.set_reference_handle(child_ref.get_reference_handle()) new_ref.set_reference_handle(child_ref.get_reference_handle())
new_ref.set_father_relation(child_ref.get_father_relation()) new_ref.set_father_relation(child_ref.get_father_relation())
new_ref.set_mother_relation(child_ref.get_mother_relation()) new_ref.set_mother_relation(child_ref.get_mother_relation())
copy_notes(db,child_ref, new_ref) copy_notes(db, child_ref, new_ref)
copy_source_ref_list(db,child_ref, new_ref) copy_source_ref_list(db, child_ref, new_ref)
new_family.add_child_ref(new_ref) new_family.add_child_ref(new_ref)
# Copy event ref list. # Copy event ref list.
for event_ref in family.get_event_ref_list(): for event_ref in family.get_event_ref_list():
if event_ref and not event_ref.get_privacy(): if event_ref and not event_ref.get_privacy():
event = db.get_event_from_handle(event_ref.ref) 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)) new_family.add_event_ref(sanitize_event_ref(db, event_ref))
copy_source_ref_list(db,family, new_family) copy_source_ref_list(db, family, new_family)
copy_notes(db,family, new_family) copy_notes(db, family, new_family)
copy_media_ref_list(db,family, new_family) copy_media_ref_list(db, family, new_family)
copy_attributes(db,family, new_family) copy_attributes(db, family, new_family)
copy_lds_ords(db,family, new_family) copy_lds_ords(db, family, new_family)
return new_family return new_family
def sanitize_repository(db,repository): def sanitize_repository(db, repository):
""" """
Create a new Repository instance based off the passed Repository Create a new Repository instance based off the passed Repository
instance. The returned instance has all private records instance. The returned instance has all private records
@@ -1006,7 +1006,7 @@ def sanitize_repository(db,repository):
@param db: GRAMPS database to which the Person object belongs @param db: GRAMPS database to which the Person object belongs
@type db: GrampsDbBase @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 privacy records removed
@type repository: Repository @type repository: Repository
@returns: 'cleansed' Repository object @returns: 'cleansed' Repository object
@@ -1020,8 +1020,8 @@ def sanitize_repository(db,repository):
new_repository.set_handle(repository.get_handle()) new_repository.set_handle(repository.get_handle())
new_repository.set_marker(repository.get_marker()) new_repository.set_marker(repository.get_marker())
copy_notes(db,repository, new_repository) copy_notes(db, repository, new_repository)
copy_addresses(db,repository, new_repository) copy_addresses(db, repository, new_repository)
copy_urls(db,repository, new_repository) copy_urls(db, repository, new_repository)
return new_repository return new_repository