6960: fix merging citations batch tool; sources
Back-port from gramps40 of r22971. svn: r22972
This commit is contained in:
parent
4ee02a80af
commit
e5d995517a
@ -31,7 +31,7 @@ Provide merge capabilities for citations.
|
|||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
from gen.lib import (Person, Family, Event, Place,
|
from gen.lib import (Person, Family, Event, Place,
|
||||||
MediaObject, Repository, Citation)
|
MediaObject, Repository, Citation, Source)
|
||||||
from gen.db import DbTxn
|
from gen.db import DbTxn
|
||||||
from gen.ggettext import sgettext as _
|
from gen.ggettext import sgettext as _
|
||||||
import const
|
import const
|
||||||
@ -232,6 +232,12 @@ class MergeCitationQuery(object):
|
|||||||
citation.replace_citation_references(old_handle,
|
citation.replace_citation_references(old_handle,
|
||||||
new_handle)
|
new_handle)
|
||||||
self.database.commit_citation(citation, trans)
|
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:
|
else:
|
||||||
raise MergeError("Encounter an object of type %s that has "
|
raise MergeError("Encounter an object of type %s that has "
|
||||||
"a citation reference." % class_name)
|
"a citation reference." % class_name)
|
||||||
|
@ -60,6 +60,7 @@ 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)
|
Repository)
|
||||||
from Errors import MergeError
|
from Errors import MergeError
|
||||||
|
from Merge import MergeCitationQuery
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -186,38 +187,39 @@ class MergeCitations(tool.BatchTool,ManagedWindow.ManagedWindow):
|
|||||||
db.disable_signals()
|
db.disable_signals()
|
||||||
num_merges = 0
|
num_merges = 0
|
||||||
for handle in db.iter_source_handles():
|
for handle in db.iter_source_handles():
|
||||||
with DbTxn(_("Merge Citation"), db) as trans:
|
dict = {}
|
||||||
dict = {}
|
citation_handle_list = list(db.find_backlink_handles(handle))
|
||||||
citation_handle_list = list(db.find_backlink_handles(handle))
|
for (class_name, citation_handle) in citation_handle_list:
|
||||||
for (class_name, citation_handle) in citation_handle_list:
|
if class_name <> Citation.__name__:
|
||||||
if class_name <> Citation.__name__:
|
raise MergeError("Encountered an object of type %s "
|
||||||
raise MergeError("Encountered an object of type %s "
|
"that has a citation reference." % class_name)
|
||||||
"that has a citation reference." % class_name)
|
|
||||||
|
|
||||||
citation = db.get_citation_from_handle(citation_handle)
|
citation = db.get_citation_from_handle(citation_handle)
|
||||||
key = citation.get_page()
|
key = citation.get_page()
|
||||||
if fields <> IGNORE_DATE and fields <> IGNORE_BOTH:
|
if fields <> IGNORE_DATE and fields <> IGNORE_BOTH:
|
||||||
key += "\n" + DateHandler.get_date(citation)
|
key += "\n" + DateHandler.get_date(citation)
|
||||||
if fields <> IGNORE_CONFIDENCE and fields <> IGNORE_BOTH:
|
if fields <> IGNORE_CONFIDENCE and fields <> IGNORE_BOTH:
|
||||||
key += "\n" + \
|
key += "\n" + \
|
||||||
confidence[citation.get_confidence_level()]
|
confidence[citation.get_confidence_level()]
|
||||||
if key in dict and \
|
if key in dict and \
|
||||||
(not dont_merge_notes or len(citation.note_list) == 0):
|
(not dont_merge_notes or len(citation.note_list) == 0):
|
||||||
citation_match_handle = dict[key]
|
citation_match_handle = dict[key]
|
||||||
citation_match = \
|
citation_match = \
|
||||||
db.get_citation_from_handle(citation_match_handle)
|
db.get_citation_from_handle(citation_match_handle)
|
||||||
try:
|
try:
|
||||||
self.Merge(db, citation_match, citation, trans)
|
query = MergeCitationQuery(
|
||||||
except AssertionError:
|
self.dbstate, citation_match, citation)
|
||||||
print "Tool/Family Tree processing/MergeCitations", \
|
query.execute()
|
||||||
"citation1 gramps_id", citation_match.get_gramps_id(), \
|
except AssertionError:
|
||||||
"citation2 gramps_id", citation.get_gramps_id() , \
|
print "Tool/Family Tree processing/MergeCitations", \
|
||||||
"citation backlink handles", \
|
"citation1 gramps_id", citation_match.get_gramps_id(), \
|
||||||
list(db.find_backlink_handles(citation.get_handle()))
|
"citation2 gramps_id", citation.get_gramps_id() , \
|
||||||
num_merges += 1
|
"citation backlink handles", \
|
||||||
elif (not dont_merge_notes or len(citation.note_list) == 0):
|
list(db.find_backlink_handles(citation.get_handle()))
|
||||||
dict[key] = citation_handle
|
num_merges += 1
|
||||||
self.progress.step()
|
elif (not dont_merge_notes or len(citation.note_list) == 0):
|
||||||
|
dict[key] = citation_handle
|
||||||
|
self.progress.step()
|
||||||
db.enable_signals()
|
db.enable_signals()
|
||||||
db.request_rebuild()
|
db.request_rebuild()
|
||||||
self.progress.close()
|
self.progress.close()
|
||||||
@ -226,54 +228,7 @@ class MergeCitations(tool.BatchTool,ManagedWindow.ManagedWindow):
|
|||||||
ngettext("%(num)d citation merged",
|
ngettext("%(num)d citation merged",
|
||||||
"%(num)d citations merged", num_merges) % {'num': num_merges})
|
"%(num)d citations merged", num_merges) % {'num': num_merges})
|
||||||
self.close(obj)
|
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