6960: Error merging citations

Merge back to gramps40 my work on the bug fix.

svn: r22962
This commit is contained in:
Vassilii Khachaturov 2013-08-30 19:00:39 +00:00
parent dacf5f4d3b
commit d9eab10013
4 changed files with 62 additions and 96 deletions

View File

@ -256,3 +256,56 @@ class CitationBase(object):
for item in self.get_citation_child_list():
item.replace_citation_references(old_handle, new_handle)
class IndirectCitationBase(object):
"""
Citation management logic for objects that don't have citations
for the primary objects, but only for the child (secondary) ones.
The derived class must implement get_citation_child_list method
to return the list of child secondary objects that may refer
citations.
Note: for most objects, this functionality is inherited from
CitationBase, which checks both the object and the child objects.
"""
def has_citation_reference(self, citation_handle):
"""
Return True if any of the child objects has reference to this citation
handle.
:param citation_handle: The citation handle to be checked.
:type citation_handle: str
:returns: Returns whether any of it's child objects has reference to
this citation handle.
:rtype: bool
"""
for item in self.get_citation_child_list():
if item.has_citation_reference(citation_handle):
return True
return False
def replace_citation_references(self, old_handle, new_handle):
"""
Replace references to citation handles in
all child objects and merge equivalent entries.
:param old_handle: The citation handle to be replaced.
:type old_handle: str
:param new_handle: The citation handle to replace the old one with.
:type new_handle: str
"""
for item in self.get_citation_child_list():
item.replace_citation_references(old_handle, new_handle)
def remove_citation_references(self, citation_handle_list):
"""
Remove references to all citation handles in the list in all child
objects.
:param citation_handle_list: The list of citation handles to be removed.
:type citation_handle_list: list
"""
for item in self.get_citation_child_list():
item.remove_citation_references(citation_handle_list)

View File

@ -38,13 +38,15 @@ from .attrbase import AttributeBase
from .refbase import RefBase
from .eventroletype import EventRoleType
from .const import IDENTICAL, EQUAL, DIFFERENT
from .citationbase import IndirectCitationBase
#-------------------------------------------------------------------------
#
# Event References for Person/Family
#
#-------------------------------------------------------------------------
class EventRef(SecondaryObject, PrivacyBase, NoteBase, AttributeBase, RefBase):
class EventRef(PrivacyBase, NoteBase, AttributeBase, RefBase,
IndirectCitationBase, SecondaryObject):
"""
Event reference class.
@ -180,47 +182,6 @@ class EventRef(SecondaryObject, PrivacyBase, NoteBase, AttributeBase, RefBase):
"""
return self.get_citation_child_list()
def has_citation_reference(self, citation_handle) :
"""
Return True if any of the child objects has reference to this citation
handle.
:param citation_handle: The citation handle to be checked.
:type citation_handle: str
:returns: Returns whether any of it's child objects has reference to
this citation handle.
:rtype: bool
"""
for item in self.get_citation_child_list():
if item.has_citation_reference(citation_handle):
return True
return False
def remove_citation_references(self, citation_handle_list):
"""
Remove references to all citation handles in the list in all child
objects.
:param citation_handle_list: The list of citation handles to be removed.
:type citation_handle_list: list
"""
for item in self.get_citation_child_list():
item.remove_citation_references(citation_handle_list)
def replace_citation_references(self, old_handle, new_handle):
"""
Replace references to citation handles in the list in this object and
all child objects and merge equivalent entries.
:param old_handle: The citation handle to be replaced.
:type old_handle: str
:param new_handle: The citation handle to replace the old one with.
:type new_handle: str
"""
for item in self.get_citation_child_list():
item.replace_citation_references(old_handle, new_handle)
def is_equivalent(self, other):
"""
Return if this eventref is equivalent, that is agrees in handle and

View File

@ -37,13 +37,15 @@ from .addressbase import AddressBase
from .urlbase import UrlBase
from .repotype import RepositoryType
from ..constfunc import cuni
from .citationbase import IndirectCitationBase
#-------------------------------------------------------------------------
#
# Repository class
#
#-------------------------------------------------------------------------
class Repository(NoteBase, AddressBase, UrlBase, PrimaryObject):
class Repository(NoteBase, AddressBase, UrlBase,
IndirectCitationBase, PrimaryObject):
"""A location where collections of Sources are found."""
def __init__(self):
@ -171,59 +173,6 @@ class Repository(NoteBase, AddressBase, UrlBase, PrimaryObject):
"""
return self.get_referenced_note_handles()
def has_citation_reference(self, citation_handle) :
"""
Return True if any of the child objects has reference to this citation
handle.
Note: for most objects, this is inherited from citationbase, which
checks both the object and the child objects. However, uniquely,
Repositories do not have citations for the primary object, but only for
child (secondary) objects. Hence, this function has to be implemented
directly in the primary object; it only checks the child objects.
:param citation_handle: The citation handle to be checked.
:type citation_handle: str
:returns: Returns whether any of it's child objects has reference to
this citation handle.
:rtype: bool
"""
for item in self.get_citation_child_list():
if item.has_citation_reference(citation_handle):
return True
return False
def remove_citation_references(self, citation_handle_list):
"""
Remove references to all citation handles in the list in all child
objects.
Note: the same comment about citationbase in has_citation_reference
applies here too.
:param citation_handle_list: The list of citation handles to be removed.
:type citation_handle_list: list
"""
for item in self.get_citation_child_list():
item.remove_citation_references(citation_handle_list)
def replace_citation_references(self, old_handle, new_handle):
"""
Replace references to citation handles in the list in this object and
all child objects and merge equivalent entries.
Note: the same comment about citationbase in has_citation_reference
applies here too.
:param old_handle: The citation handle to be replaced.
:type old_handle: str
:param new_handle: The citation handle to replace the old one with.
:type new_handle: str
"""
for item in self.get_citation_child_list():
item.replace_citation_references(old_handle, new_handle)
def merge(self, acquisition):
"""
Merge the content of acquisition into this repository.

View File

@ -139,6 +139,9 @@ class BaseMergeCheck(unittest.TestCase):
if test_error_str:
self.assertIn(test_error_str, err_str)
return
else:
if "Traceback (most recent call last):" in err_str:
raise Exception(err_str)
if debug:
print('input :', self.canonicalize(input_doc))
print('result:', self.canonicalize(result_str))