Fix merge citations for repositories

svn: r18343
This commit is contained in:
Tim G L Lyons 2011-10-18 16:38:18 +00:00
parent 5e0c4d074a
commit 2c89d2e0b2
3 changed files with 53 additions and 2 deletions

View File

@ -30,7 +30,7 @@ Provide merge capabilities for citations.
# Gramps modules
#
#-------------------------------------------------------------------------
from gen.lib import (Person, Family, Event, Place, MediaObject)
from gen.lib import (Person, Family, Event, Place, MediaObject, Repository)
from gen.db import DbTxn
from gen.ggettext import sgettext as _
import const
@ -219,6 +219,12 @@ class MergeCitationQuery(object):
assert(obj.has_citation_reference(old_handle))
obj.replace_citation_references(old_handle, new_handle)
self.database.commit_media_object(obj, trans)
elif class_name == Repository.__name__:
repository = self.database.get_repository_from_handle(handle)
assert(repository.has_citation_reference(old_handle))
repository.replace_citation_references(old_handle,
new_handle)
self.database.commit_repository(repository, trans)
else:
raise MergeError("Encounter an object of type %s that has "
"a citation reference." % class_name)

View File

@ -139,6 +139,45 @@ 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 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 has_source_reference(self, src_handle) :
"""
Return True if any of the child objects has reference to this source

View File

@ -56,7 +56,8 @@ import ManagedWindow
from gen.ggettext import sgettext as _
from glade import Glade
from gen.db import DbTxn
from gen.lib import (Person, Family, Event, Place, MediaObject, Citation)
from gen.lib import (Person, Family, Event, Place, MediaObject, Citation,
Repository)
from Errors import MergeError
#-------------------------------------------------------------------------
@ -254,6 +255,11 @@ class MergeCitations(tool.BatchTool,ManagedWindow.ManagedWindow):
assert(obj.has_citation_reference(old_handle))
obj.replace_citation_references(old_handle, new_handle)
db.commit_media_object(obj, trans)
elif class_name == Repository.__name__:
repository = db.get_repository_from_handle(handle)
assert(repository.has_citation_reference(old_handle))
repository.replace_citation_references(old_handle, new_handle)
db.commit_repository(repository, trans)
else:
raise MergeError("Encountered an object of type %s that has "
"a citation reference." % class_name)