6960: Error merging citations
Reapply from trunk these commits: commit 1594f61ea2dbd9eddb44a800c26f170ff5702491 Author: vassilii <vassilii@4ae1f11a-8b86-4847-b8af-ab372f36d1fd> Date: Fri Aug 30 22:33:58 2013 +0000 6960: Bless Source with an IndirectCitationBase git-svn-id: svn+ssh://svn.code.sf.net/p/gramps/code/trunk@22970 4ae1f11a-8b86-4847-b8af-ab372f36d1fd commit 6ec4b56d6530bd98638cb66365e6205d057f48ca Author: vassilii <vassilii@4ae1f11a-8b86-4847-b8af-ab372f36d1fd> Date: Fri Aug 30 22:03:14 2013 +0000 6960: mergecitations has broken copy of MCQ The MergeCitations batch tool had a cut-and-pasted code replicating MergeCitationQuery logic. Naturally, it diverged :-) Removed MergeCitations.Merge and use MergeCitationQuery instead. git-svn-id: svn+ssh://svn.code.sf.net/p/gramps/code/trunk@22969 4ae1f11a-8b86-4847-b8af-ab372f36d1fd svn: r22971
This commit is contained in:
parent
21fd8f2cfb
commit
314bbe6ca0
@ -37,13 +37,14 @@ from .notebase import NoteBase
|
||||
from .reporef import RepoRef
|
||||
from .const import DIFFERENT, EQUAL, IDENTICAL
|
||||
from ..constfunc import cuni
|
||||
from .citationbase import IndirectCitationBase
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Source class
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class Source(MediaBase, NoteBase, PrimaryObject):
|
||||
class Source(MediaBase, NoteBase, IndirectCitationBase, PrimaryObject):
|
||||
"""A record of a source of information."""
|
||||
|
||||
def __init__(self):
|
||||
|
@ -31,7 +31,7 @@ Provide merge capabilities for citations.
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from ..lib import (Person, Family, Event, Place,
|
||||
MediaObject, Repository, Citation)
|
||||
MediaObject, Repository, Citation, Source)
|
||||
from ..db import DbTxn
|
||||
from ..const import GRAMPS_LOCALE as glocale
|
||||
_ = glocale.translation.sgettext
|
||||
@ -101,6 +101,12 @@ class MergeCitationQuery(object):
|
||||
citation.replace_citation_references(old_handle,
|
||||
new_handle)
|
||||
self.database.commit_citation(citation, trans)
|
||||
elif class_name == Source.__name__:
|
||||
source = self.database.get_source_from_handle(handle)
|
||||
assert(source.has_citation_reference(old_handle))
|
||||
source.replace_citation_references(old_handle,
|
||||
new_handle)
|
||||
self.database.commit_source(source, trans)
|
||||
else:
|
||||
raise MergeError("Encounter an object of type %s that has "
|
||||
"a citation reference." % class_name)
|
||||
|
@ -56,6 +56,7 @@ from gramps.gui.display import display_help
|
||||
from gramps.gen.datehandler import get_date
|
||||
from gramps.gui.managedwindow import ManagedWindow
|
||||
from gramps.gen.const import GRAMPS_LOCALE as glocale
|
||||
from gramps.gen.merge import MergeCitationQuery
|
||||
_ = glocale.translation.sgettext
|
||||
|
||||
from gramps.gui.glade import Glade
|
||||
@ -189,7 +190,6 @@ class MergeCitations(tool.BatchTool,ManagedWindow):
|
||||
db.disable_signals()
|
||||
num_merges = 0
|
||||
for handle in db.iter_source_handles():
|
||||
with DbTxn(_("Merge Citation"), db) as trans:
|
||||
dict = {}
|
||||
citation_handle_list = list(db.find_backlink_handles(handle))
|
||||
for (class_name, citation_handle) in citation_handle_list:
|
||||
@ -210,7 +210,9 @@ class MergeCitations(tool.BatchTool,ManagedWindow):
|
||||
citation_match = \
|
||||
db.get_citation_from_handle(citation_match_handle)
|
||||
try:
|
||||
self.Merge(db, citation_match, citation, trans)
|
||||
query = MergeCitationQuery(
|
||||
self.dbstate, citation_match, citation)
|
||||
query.execute()
|
||||
except AssertionError:
|
||||
print("Tool/Family Tree processing/MergeCitations", \
|
||||
"citation1 gramps_id", citation_match.get_gramps_id(), \
|
||||
@ -230,53 +232,6 @@ class MergeCitations(tool.BatchTool,ManagedWindow):
|
||||
"%(num)d citations merged", num_merges) % {'num': num_merges})
|
||||
self.close(obj)
|
||||
|
||||
def Merge (self, db, citation1, citation2, trans):
|
||||
"""
|
||||
Merges two citations into a single citation.
|
||||
"""
|
||||
new_handle = citation1.get_handle()
|
||||
old_handle = citation2.get_handle()
|
||||
|
||||
citation1.merge(citation2)
|
||||
|
||||
db.commit_citation(citation1, trans)
|
||||
for (class_name, handle) in db.find_backlink_handles(
|
||||
old_handle):
|
||||
if class_name == Person.__name__:
|
||||
person = db.get_person_from_handle(handle)
|
||||
assert(person.has_citation_reference(old_handle))
|
||||
person.replace_citation_references(old_handle, new_handle)
|
||||
db.commit_person(person, trans)
|
||||
elif class_name == Family.__name__:
|
||||
family = db.get_family_from_handle(handle)
|
||||
assert(family.has_citation_reference(old_handle))
|
||||
family.replace_citation_references(old_handle, new_handle)
|
||||
db.commit_family(family, trans)
|
||||
elif class_name == Event.__name__:
|
||||
event = db.get_event_from_handle(handle)
|
||||
assert(event.has_citation_reference(old_handle))
|
||||
event.replace_citation_references(old_handle, new_handle)
|
||||
db.commit_event(event, trans)
|
||||
elif class_name == Place.__name__:
|
||||
place = db.get_place_from_handle(handle)
|
||||
assert(place.has_citation_reference(old_handle))
|
||||
place.replace_citation_references(old_handle, new_handle)
|
||||
db.commit_place(place, trans)
|
||||
elif class_name == MediaObject.__name__:
|
||||
obj = db.get_object_from_handle(handle)
|
||||
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)
|
||||
db.remove_citation(old_handle, trans)
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
#
|
||||
|
Loading…
Reference in New Issue
Block a user