Raise HandleError exception for bad handles
This commit is contained in:
parent
5d7343f10a
commit
5c958bd7fb
@ -522,9 +522,13 @@ def preset_name(basepers, name, sibling=False):
|
||||
def family_name(family, db, noname=_("unknown")):
|
||||
"""Builds a name for the family from the parents names"""
|
||||
|
||||
father = None
|
||||
mother = None
|
||||
father_handle = family.get_father_handle()
|
||||
mother_handle = family.get_mother_handle()
|
||||
if father_handle:
|
||||
father = db.get_person_from_handle(father_handle)
|
||||
if mother_handle:
|
||||
mother = db.get_person_from_handle(mother_handle)
|
||||
if father and mother:
|
||||
fname = name_displayer.display(father)
|
||||
|
@ -120,6 +120,7 @@ class FormattingHelper(object):
|
||||
""" Obtain a place name
|
||||
"""
|
||||
text = ""
|
||||
if place_handle:
|
||||
place = self.dbstate.db.get_place_from_handle(place_handle)
|
||||
if place:
|
||||
place_title = place_displayer.display(self.dbstate.db, place)
|
||||
|
@ -574,7 +574,10 @@ class DisplayState(Callback):
|
||||
|
||||
self.status.pop(self.status_id)
|
||||
|
||||
if active_handle:
|
||||
name, obj = navigation_label(dbstate.db, nav_type, active_handle)
|
||||
else:
|
||||
name = _('No active object')
|
||||
|
||||
# Append relationship to default person if funtionality is enabled.
|
||||
if nav_type == 'Person' and active_handle \
|
||||
|
@ -347,6 +347,8 @@ class EditPrimary(ManagedWindow, DbGUIElement):
|
||||
Return True if a duplicate GRAMPS ID has been detected.
|
||||
|
||||
"""
|
||||
original = None
|
||||
if self.obj.get_handle():
|
||||
original = self.get_from_handle(self.obj.get_handle())
|
||||
if original and original.get_gramps_id() == self.obj.get_gramps_id():
|
||||
return (False, 0)
|
||||
|
@ -199,8 +199,6 @@ class BaseSelector(ManagedWindow):
|
||||
id_list = self.get_selected_ids()
|
||||
if id_list and id_list[0]:
|
||||
result = self.get_from_handle_func()(id_list[0])
|
||||
if result is None and self.get_from_handle_func2:
|
||||
result = self.get_from_handle_func2()(id_list[0])
|
||||
self.close()
|
||||
elif val != Gtk.ResponseType.DELETE_EVENT:
|
||||
self.close()
|
||||
@ -233,9 +231,6 @@ class BaseSelector(ManagedWindow):
|
||||
def get_from_handle_func(self):
|
||||
assert False, "Must be defined in the subclass"
|
||||
|
||||
def get_from_handle_func2(self):
|
||||
return None
|
||||
|
||||
def set_show_search_bar(self, value):
|
||||
"""make the search bar at the top shown
|
||||
"""
|
||||
|
@ -78,7 +78,10 @@ class SelectCitation(BaseSelector):
|
||||
]
|
||||
|
||||
def get_from_handle_func(self):
|
||||
return self.db.get_source_from_handle
|
||||
return self.get_source_or_citation
|
||||
|
||||
def get_from_handle_func2(self):
|
||||
return self.db.get_citation_from_handle
|
||||
def get_source_or_citation(self, handle):
|
||||
if self.db.has_source_handle(handle):
|
||||
return self.db.get_source_from_handle(handle)
|
||||
else:
|
||||
return self.db.get_citation_from_handle(handle)
|
||||
|
@ -1067,9 +1067,12 @@ class FanChartWidget(FanChartBaseWidget):
|
||||
|
||||
def _fill_data_structures(self):
|
||||
self.set_generations()
|
||||
if not self.rootpersonh:
|
||||
return
|
||||
person = self.dbstate.db.get_person_from_handle(self.rootpersonh)
|
||||
if not person:
|
||||
name = None
|
||||
#nothing to do, just return
|
||||
return
|
||||
else:
|
||||
name = name_displayer.display(person)
|
||||
parents = self._have_parents(person)
|
||||
|
@ -167,6 +167,8 @@ class FanChartDescWidget(FanChartBaseWidget):
|
||||
|
||||
def _fill_data_structures(self):
|
||||
self.set_generations()
|
||||
if not self.rootpersonh:
|
||||
return
|
||||
person = self.dbstate.db.get_person_from_handle(self.rootpersonh)
|
||||
if not person:
|
||||
#nothing to do, just return
|
||||
|
@ -71,7 +71,7 @@ from gramps.gen.utils.callback import Callback
|
||||
from . import BsddbBaseCursor
|
||||
from gramps.gen.db.base import DbReadBase
|
||||
from gramps.gen.utils.id import create_id
|
||||
from gramps.gen.errors import DbError
|
||||
from gramps.gen.errors import DbError, HandleError
|
||||
from gramps.gen.constfunc import get_env_var
|
||||
from gramps.gen.const import GRAMPS_LOCALE as glocale
|
||||
_ = glocale.translation.gettext
|
||||
@ -683,7 +683,7 @@ class DbBsddbRead(DbReadBase, Callback):
|
||||
newobj = class_type()
|
||||
newobj.unserialize(data)
|
||||
return newobj
|
||||
return None
|
||||
raise HandleError('Handle %s not found' % handle.decode('utf-8'))
|
||||
|
||||
def get_from_name_and_handle(self, table_name, handle):
|
||||
"""
|
||||
|
@ -74,7 +74,7 @@ from gramps.gen.db.dbconst import *
|
||||
from gramps.gen.utils.callback import Callback
|
||||
from gramps.gen.utils.id import create_id
|
||||
from gramps.gen.updatecallback import UpdateCallback
|
||||
from gramps.gen.errors import DbError
|
||||
from gramps.gen.errors import DbError, HandleError
|
||||
from gramps.gen.constfunc import win, get_env_var
|
||||
from gramps.gen.const import HOME_DIR, GRAMPS_LOCALE as glocale
|
||||
_ = glocale.translation.gettext
|
||||
@ -2105,19 +2105,16 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback):
|
||||
def get_from_handle(self, handle, class_type, data_map):
|
||||
if isinstance(handle, str):
|
||||
handle = handle.encode('utf-8')
|
||||
try:
|
||||
if handle is None:
|
||||
raise HandleError('Handle is None')
|
||||
if not handle:
|
||||
raise HandleError('Handle is empty')
|
||||
data = data_map.get(handle, txn=self.txn)
|
||||
except:
|
||||
data = None
|
||||
# under certain circumstances during a database reload,
|
||||
# data_map can be none. If so, then don't report an error
|
||||
if data_map:
|
||||
_LOG.error("Failed to get from handle", exc_info=True)
|
||||
if data:
|
||||
newobj = class_type()
|
||||
newobj.unserialize(data)
|
||||
return newobj
|
||||
return None
|
||||
raise HandleError('Handle %s not found' % handle.decode('utf-8'))
|
||||
|
||||
@catch_db_error
|
||||
def transaction_begin(self, transaction):
|
||||
|
@ -152,11 +152,14 @@ class Ancestor(Gramplet):
|
||||
tooltip, person_handle], node=parent_id)
|
||||
|
||||
family_handle = person.get_main_parents_family_handle()
|
||||
if family_handle:
|
||||
family = self.dbstate.db.get_family_from_handle(family_handle)
|
||||
if family:
|
||||
if family.get_father_handle():
|
||||
self.add_to_tree(depth + 1, item_id, family.get_father_handle())
|
||||
if family.get_mother_handle():
|
||||
self.add_to_tree(depth + 1, item_id, family.get_mother_handle())
|
||||
father_handle = family.get_father_handle()
|
||||
if father_handle:
|
||||
self.add_to_tree(depth + 1, item_id, father_handle)
|
||||
mother_handle = family.get_mother_handle()
|
||||
if mother_handle:
|
||||
self.add_to_tree(depth + 1, item_id, mother_handle)
|
||||
|
||||
return item_id
|
||||
|
@ -105,6 +105,7 @@ class Citations(Gramplet, DbGUIElement):
|
||||
self.add_attribute_citations(event)
|
||||
self.add_mediaref_citations(event)
|
||||
place_handle = event.get_place_handle()
|
||||
if place_handle:
|
||||
place = self.dbstate.db.get_place_from_handle(place_handle)
|
||||
if place:
|
||||
self.add_place_citations(place)
|
||||
@ -202,6 +203,7 @@ class Citations(Gramplet, DbGUIElement):
|
||||
if self.check_mediaref_citations(event):
|
||||
return True
|
||||
place_handle = event.get_place_handle()
|
||||
if place_handle:
|
||||
place = self.dbstate.db.get_place_from_handle(place_handle)
|
||||
if place and self.check_place_citations(place):
|
||||
return True
|
||||
|
@ -170,9 +170,11 @@ class RelCalc(tool.Tool, ManagedWindow):
|
||||
if not iter_:
|
||||
return
|
||||
|
||||
other_person = None
|
||||
handle = model.get_handle_from_iter(iter_)
|
||||
if handle:
|
||||
other_person = self.db.get_person_from_handle(handle)
|
||||
if other_person is None :
|
||||
if other_person is None:
|
||||
self.textbuffer.set_text("")
|
||||
return
|
||||
|
||||
|
@ -312,12 +312,15 @@ class GeoClose(GeoGraphyView):
|
||||
information.
|
||||
"""
|
||||
active = self.get_active()
|
||||
if active:
|
||||
person = self.dbstate.db.get_person_from_handle(active)
|
||||
self.lifeway_layer.clear_ways()
|
||||
if person is None:
|
||||
self.goto_handle(None)
|
||||
else:
|
||||
self.goto_handle(handle=person)
|
||||
else:
|
||||
self.goto_handle(None)
|
||||
|
||||
def draw(self, menu, marks, color, reference):
|
||||
"""
|
||||
|
@ -300,8 +300,14 @@ class GeoFamClose(GeoGraphyView):
|
||||
information.
|
||||
"""
|
||||
active = self.get_active()
|
||||
if active:
|
||||
family = self.dbstate.db.get_family_from_handle(active)
|
||||
if family is None:
|
||||
self.goto_handle(None)
|
||||
else:
|
||||
self.goto_handle(handle=family)
|
||||
else:
|
||||
self.goto_handle(None)
|
||||
|
||||
def draw(self, menu, marks, color, reference):
|
||||
"""
|
||||
|
@ -355,20 +355,24 @@ class GeoFamily(GeoGraphyView):
|
||||
}
|
||||
self._createpersonmarkers(dbstate, person, comment, family_id)
|
||||
|
||||
def _createmap(self, family_x):
|
||||
def _createmap(self, handle):
|
||||
"""
|
||||
Create all markers for each people's event in the database which has
|
||||
a lat/lon.
|
||||
"""
|
||||
if not handle:
|
||||
return
|
||||
self.place_list = []
|
||||
self.place_without_coordinates = []
|
||||
self.minlat = self.maxlat = self.minlon = self.maxlon = 0.0
|
||||
self.minyear = 9999
|
||||
self.maxyear = 0
|
||||
self.message_layer.clear_messages()
|
||||
family = self.dbstate.db.get_family_from_handle(family_x)
|
||||
if family is None:
|
||||
person = self.dbstate.db.get_person_from_handle(self.uistate.get_active('Person'))
|
||||
if self.dbstate.db.has_family_handle(handle):
|
||||
family = self.dbstate.db.get_family_from_handle(handle)
|
||||
self._createmap_for_one_family(family)
|
||||
else:
|
||||
person = self.dbstate.db.get_person_from_handle(handle)
|
||||
if not person:
|
||||
return
|
||||
family_list = person.get_family_handle_list()
|
||||
@ -376,8 +380,6 @@ class GeoFamily(GeoGraphyView):
|
||||
family = self.dbstate.db.get_family_from_handle(family_hdl)
|
||||
if family is not None:
|
||||
self._createmap_for_one_family(family)
|
||||
else:
|
||||
self._createmap_for_one_family(family)
|
||||
self.sort = sorted(self.place_list,
|
||||
key=operator.itemgetter(3, 4, 6)
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user