bug 9765; fix citation tree view for HandleError exceptions
This commit is contained in:
parent
19201eed67
commit
00b2bff6d0
@ -51,7 +51,7 @@ from gramps.gui.views.listview import ListView
|
|||||||
from gramps.gen.utils.db import (get_source_and_citation_referents,
|
from gramps.gen.utils.db import (get_source_and_citation_referents,
|
||||||
get_citation_referents)
|
get_citation_referents)
|
||||||
from gramps.gui.views.bookmarks import CitationBookmarks
|
from gramps.gui.views.bookmarks import CitationBookmarks
|
||||||
from gramps.gen.errors import WindowActiveError
|
from gramps.gen.errors import WindowActiveError, HandleError
|
||||||
from gramps.gui.ddtargets import DdTargets
|
from gramps.gui.ddtargets import DdTargets
|
||||||
from gramps.gui.dialog import ErrorDialog
|
from gramps.gui.dialog import ErrorDialog
|
||||||
from gramps.gui.editors import EditCitation, DeleteCitationQuery, EditSource, \
|
from gramps.gui.editors import EditCitation, DeleteCitationQuery, EditSource, \
|
||||||
@ -157,9 +157,10 @@ class CitationTreeView(ListView):
|
|||||||
# Override change_active from NavigationView, so that only Citations can be
|
# Override change_active from NavigationView, so that only Citations can be
|
||||||
# put in the history list for the CitationTreeView
|
# put in the history list for the CitationTreeView
|
||||||
def change_active(self, handle):
|
def change_active(self, handle):
|
||||||
if self.dbstate.db.get_citation_from_handle(handle):
|
try:
|
||||||
|
self.dbstate.db.get_citation_from_handle(handle)
|
||||||
super(CitationTreeView, self).change_active(handle)
|
super(CitationTreeView, self).change_active(handle)
|
||||||
else:
|
except HandleError:
|
||||||
# FIXME: See http://www.gramps-project.org/bugs/view.php?id=6352 a
|
# FIXME: See http://www.gramps-project.org/bugs/view.php?id=6352 a
|
||||||
# more comprehensive solution is needed in the long term. See also
|
# more comprehensive solution is needed in the long term. See also
|
||||||
# add in Bookmarks.CitationBookmarks
|
# add in Bookmarks.CitationBookmarks
|
||||||
@ -178,8 +179,7 @@ class CitationTreeView(ListView):
|
|||||||
|
|
||||||
def _print_handles(self, text, handle_list):
|
def _print_handles(self, text, handle_list):
|
||||||
for handle in handle_list:
|
for handle in handle_list:
|
||||||
source = self.dbstate.db.get_source_from_handle(handle)
|
source, citation = self.get_source_or_citation(handle, False)
|
||||||
citation = self.dbstate.db.get_citation_from_handle(handle)
|
|
||||||
_LOG.debug("\n\n\n")
|
_LOG.debug("\n\n\n")
|
||||||
if source:
|
if source:
|
||||||
_LOG.debug("---- %s -- source %s" %
|
_LOG.debug("---- %s -- source %s" %
|
||||||
@ -238,11 +238,13 @@ class CitationTreeView(ListView):
|
|||||||
# to return SOURCE_LINK.
|
# to return SOURCE_LINK.
|
||||||
|
|
||||||
selection = self.selected_handles()
|
selection = self.selected_handles()
|
||||||
if len(selection) == 1 and \
|
if len(selection) == 1:
|
||||||
self.dbstate.db.get_source_from_handle(selection[0]):
|
try:
|
||||||
|
self.dbstate.db.get_source_from_handle(selection[0])
|
||||||
return DdTargets.SOURCE_LINK
|
return DdTargets.SOURCE_LINK
|
||||||
else:
|
except HandleError:
|
||||||
return DdTargets.CITATION_LINK
|
pass
|
||||||
|
return DdTargets.CITATION_LINK
|
||||||
|
|
||||||
def get_stock(self):
|
def get_stock(self):
|
||||||
return 'gramps-citation'
|
return 'gramps-citation'
|
||||||
@ -416,12 +418,10 @@ class CitationTreeView(ListView):
|
|||||||
"""
|
"""
|
||||||
for handle in self.selected_handles():
|
for handle in self.selected_handles():
|
||||||
# The handle will either be a Source handle or a Citation handle
|
# The handle will either be a Source handle or a Citation handle
|
||||||
source = self.dbstate.db.get_source_from_handle(handle)
|
source, citation = self.get_source_or_citation(handle)
|
||||||
citation = self.dbstate.db.get_citation_from_handle(handle)
|
|
||||||
if (not source and not citation) or (source and citation):
|
|
||||||
raise ValueError("selection must be either source or citation")
|
|
||||||
if not source:
|
if not source:
|
||||||
source = self.dbstate.db.get_source_from_handle(citation.get_reference_handle())
|
source = self.dbstate.db.get_source_from_handle(
|
||||||
|
citation.get_reference_handle())
|
||||||
try:
|
try:
|
||||||
EditCitation(self.dbstate, self.uistate, [],
|
EditCitation(self.dbstate, self.uistate, [],
|
||||||
Citation(), source)
|
Citation(), source)
|
||||||
@ -436,27 +436,22 @@ class CitationTreeView(ListView):
|
|||||||
|
|
||||||
def remove_object_from_handle(self, handle):
|
def remove_object_from_handle(self, handle):
|
||||||
# The handle will either be a Source handle or a Citation handle
|
# The handle will either be a Source handle or a Citation handle
|
||||||
source = self.dbstate.db.get_source_from_handle(handle)
|
source, citation = self.get_source_or_citation(handle)
|
||||||
citation = self.dbstate.db.get_citation_from_handle(handle)
|
|
||||||
if (not source and not citation) or (source and citation):
|
|
||||||
raise ValueError("selection must be either source or citation")
|
|
||||||
if citation:
|
if citation:
|
||||||
the_lists = get_citation_referents(handle, self.dbstate.db)
|
the_lists = get_citation_referents(handle, self.dbstate.db)
|
||||||
object = self.dbstate.db.get_citation_from_handle(handle)
|
query = DeleteCitationQuery(self.dbstate, self.uistate, citation,
|
||||||
query = DeleteCitationQuery(self.dbstate, self.uistate, object,
|
|
||||||
the_lists)
|
the_lists)
|
||||||
is_used = any(the_lists)
|
is_used = any(the_lists)
|
||||||
return (query, is_used, object)
|
return (query, is_used, citation)
|
||||||
else:
|
else:
|
||||||
the_lists = get_source_and_citation_referents(handle,
|
the_lists = get_source_and_citation_referents(handle,
|
||||||
self.dbstate.db)
|
self.dbstate.db)
|
||||||
LOG.debug('the_lists %s' % [the_lists])
|
LOG.debug('the_lists %s' % [the_lists])
|
||||||
|
|
||||||
object = self.dbstate.db.get_source_from_handle(handle)
|
query = DeleteSrcQuery(self.dbstate, self.uistate, source,
|
||||||
query = DeleteSrcQuery(self.dbstate, self.uistate, object,
|
|
||||||
the_lists)
|
the_lists)
|
||||||
is_used = any(the_lists)
|
is_used = any(the_lists)
|
||||||
return (query, is_used, object)
|
return (query, is_used, source)
|
||||||
|
|
||||||
def edit(self, obj):
|
def edit(self, obj):
|
||||||
"""
|
"""
|
||||||
@ -464,16 +459,13 @@ class CitationTreeView(ListView):
|
|||||||
"""
|
"""
|
||||||
for handle in self.selected_handles():
|
for handle in self.selected_handles():
|
||||||
# The handle will either be a Source handle or a Citation handle
|
# The handle will either be a Source handle or a Citation handle
|
||||||
source = self.dbstate.db.get_source_from_handle(handle)
|
source, citation = self.get_source_or_citation(handle)
|
||||||
citation = self.dbstate.db.get_citation_from_handle(handle)
|
|
||||||
if (not source and not citation) or (source and citation):
|
|
||||||
raise ValueError("selection must be either source or citation")
|
|
||||||
if citation:
|
if citation:
|
||||||
try:
|
try:
|
||||||
EditCitation(self.dbstate, self.uistate, [], citation)
|
EditCitation(self.dbstate, self.uistate, [], citation)
|
||||||
except WindowActiveError:
|
except WindowActiveError:
|
||||||
pass
|
pass
|
||||||
else: # FIXME need try block here
|
else:
|
||||||
try:
|
try:
|
||||||
EditSource(self.dbstate, self.uistate, [], source)
|
EditSource(self.dbstate, self.uistate, [], source)
|
||||||
except WindowActiveError:
|
except WindowActiveError:
|
||||||
@ -516,15 +508,8 @@ class CitationTreeView(ListView):
|
|||||||
"citation.")
|
"citation.")
|
||||||
ErrorDialog(msg, msg2, parent=self.uistate.window)
|
ErrorDialog(msg, msg2, parent=self.uistate.window)
|
||||||
else:
|
else:
|
||||||
source1 = self.dbstate.db.get_source_from_handle(mlist[0])
|
source1, citation1 = self.get_source_or_citation(mlist[0])
|
||||||
citation1 = self.dbstate.db.get_citation_from_handle(mlist[0])
|
source2, citation2 = self.get_source_or_citation(mlist[1])
|
||||||
if (not source1 and not citation1) or (source1 and citation1):
|
|
||||||
raise ValueError("selection must be either source or citation")
|
|
||||||
|
|
||||||
source2 = self.dbstate.db.get_source_from_handle(mlist[1])
|
|
||||||
citation2 = self.dbstate.db.get_citation_from_handle(mlist[1])
|
|
||||||
if (not source2 and not citation2) or (source2 and citation2):
|
|
||||||
raise ValueError("selection must be either source or citation")
|
|
||||||
|
|
||||||
if citation1 and citation2:
|
if citation1 and citation2:
|
||||||
if not citation1.get_reference_handle() == \
|
if not citation1.get_reference_handle() == \
|
||||||
@ -547,6 +532,7 @@ class CitationTreeView(ListView):
|
|||||||
"both must be sources, or both must be "
|
"both must be sources, or both must be "
|
||||||
"citations.")
|
"citations.")
|
||||||
ErrorDialog(msg, msg2, parent=self.uistate.window)
|
ErrorDialog(msg, msg2, parent=self.uistate.window)
|
||||||
|
self.object_build()
|
||||||
|
|
||||||
def get_handle_from_gramps_id(self, gid):
|
def get_handle_from_gramps_id(self, gid):
|
||||||
obj = self.dbstate.db.get_citation_from_gramps_id(gid)
|
obj = self.dbstate.db.get_citation_from_gramps_id(gid)
|
||||||
@ -555,6 +541,23 @@ class CitationTreeView(ListView):
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def get_source_or_citation(self, handle, check=True):
|
||||||
|
"""
|
||||||
|
Get one of source or citation from the passed handle. There must be
|
||||||
|
exactly one, or we will rain an exception.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
source = self.dbstate.db.get_source_from_handle(handle)
|
||||||
|
except HandleError:
|
||||||
|
source = None
|
||||||
|
try:
|
||||||
|
citation = self.dbstate.db.get_citation_from_handle(handle)
|
||||||
|
except HandleError:
|
||||||
|
citation = None
|
||||||
|
if check and ((not source and not citation) or (source and citation)):
|
||||||
|
raise ValueError("selection must be either source or citation")
|
||||||
|
return source, citation
|
||||||
|
|
||||||
def tag_updated(self, handle_list):
|
def tag_updated(self, handle_list):
|
||||||
"""
|
"""
|
||||||
Update tagged rows when a tag color changes.
|
Update tagged rows when a tag color changes.
|
||||||
@ -571,12 +574,11 @@ class CitationTreeView(ListView):
|
|||||||
"""
|
"""
|
||||||
Add the given tag to the given source or citation.
|
Add the given tag to the given source or citation.
|
||||||
"""
|
"""
|
||||||
citation = self.dbstate.db.get_citation_from_handle(handle)
|
source, citation = self.get_source_or_citation(handle)
|
||||||
if citation:
|
if citation:
|
||||||
citation.add_tag(tag_handle)
|
citation.add_tag(tag_handle)
|
||||||
self.dbstate.db.commit_citation(citation, transaction)
|
self.dbstate.db.commit_citation(citation, transaction)
|
||||||
else:
|
else:
|
||||||
source = self.dbstate.db.get_source_from_handle(handle)
|
|
||||||
source.add_tag(tag_handle)
|
source.add_tag(tag_handle)
|
||||||
self.dbstate.db.commit_source(source, transaction)
|
self.dbstate.db.commit_source(source, transaction)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user