Note LINK support for merge of other objects
This commit is contained in:
parent
1d29196344
commit
18c61c3e1b
@ -170,6 +170,28 @@ class Note(BasicPrimaryObject):
|
||||
reflist.extend(self.get_referenced_tag_handles())
|
||||
return reflist
|
||||
|
||||
def has_handle_reference(self, classname, handle):
|
||||
"""
|
||||
Return True if the object has reference to a given handle of given
|
||||
primary object type.
|
||||
|
||||
:param classname: The name of the primary object class.
|
||||
:type classname: str
|
||||
:param handle: The handle to be checked.
|
||||
:type handle: str
|
||||
|
||||
:returns:
|
||||
Returns whether the object has reference to this handle of
|
||||
this object type.
|
||||
|
||||
:rtype: bool
|
||||
"""
|
||||
for dom, obj, prop, hndl in self.get_links():
|
||||
if dom == "gramps" and prop == "handle" and \
|
||||
obj == classname and hndl == handle:
|
||||
return True
|
||||
return False
|
||||
|
||||
def remove_handle_references(self, classname, handle_list):
|
||||
"""
|
||||
Remove all references in this object to object handles in the list.
|
||||
@ -193,6 +215,26 @@ class Note(BasicPrimaryObject):
|
||||
tags.append(styledtext_tag)
|
||||
self.text.set_tags(tags)
|
||||
|
||||
def replace_handle_reference(self, classname, old_handle, new_handle):
|
||||
"""
|
||||
Replace all references to old handle with those to the new handle.
|
||||
|
||||
:param classname: The name of the primary object class.
|
||||
:type classname: str
|
||||
:param old_handle: The handle to be replaced.
|
||||
:type old_handle: str
|
||||
:param new_handle: The handle to replace the old one with.
|
||||
:type new_handle: str
|
||||
"""
|
||||
for styledtext_tag in self.text.get_tags():
|
||||
if(styledtext_tag.name == StyledTextTagType.LINK and
|
||||
styledtext_tag.value.startswith("gramps://")):
|
||||
obj, prop, value = styledtext_tag.value[9:].split("/", 2)
|
||||
if(obj == classname and prop == 'handle' and
|
||||
value == old_handle):
|
||||
styledtext_tag.value = styledtext_tag.value.replace(
|
||||
old_handle, new_handle)
|
||||
|
||||
def merge(self, acquisition):
|
||||
"""
|
||||
Merge the content of acquisition into this note.
|
||||
|
@ -28,8 +28,8 @@ Provide merge capabilities for citations.
|
||||
# Gramps modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from ..lib import (Person, Family, Event, Place,
|
||||
Media, Repository, Citation, Source)
|
||||
from ..lib import (Person, Family, Event, Place, Media, Repository,
|
||||
Citation, Source, Note)
|
||||
from ..db import DbTxn
|
||||
from ..const import GRAMPS_LOCALE as glocale
|
||||
_ = glocale.translation.sgettext
|
||||
@ -105,6 +105,12 @@ class MergeCitationQuery:
|
||||
source.replace_citation_references(old_handle,
|
||||
new_handle)
|
||||
self.database.commit_source(source, trans)
|
||||
elif class_name == Note.__name__:
|
||||
note = self.database.get_note_from_handle(handle)
|
||||
assert(note.has_handle_reference('Citation', old_handle))
|
||||
note.replace_handle_reference(
|
||||
'Citation', old_handle, new_handle)
|
||||
self.database.commit_note(note, trans)
|
||||
else:
|
||||
raise MergeError("Encounter an object of type %s that has "
|
||||
"a citation reference." % class_name)
|
||||
|
@ -27,7 +27,7 @@ Provide merge capabilities for events.
|
||||
# Gramps modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from ..lib import Person, Family
|
||||
from ..lib import Person, Family, Note
|
||||
from ..db import DbTxn
|
||||
from ..const import GRAMPS_LOCALE as glocale
|
||||
_ = glocale.translation.sgettext
|
||||
@ -88,6 +88,12 @@ class MergeEventQuery:
|
||||
family.replace_handle_reference("Event", old_handle,
|
||||
new_handle)
|
||||
self.database.commit_family(family, trans)
|
||||
elif class_name == Note.__name__:
|
||||
note = self.database.get_note_from_handle(handle)
|
||||
assert(note.has_handle_reference('Event', old_handle))
|
||||
note.replace_handle_reference(
|
||||
'Event', old_handle, new_handle)
|
||||
self.database.commit_note(note, trans)
|
||||
else:
|
||||
raise MergeError("Encounter an object of type %s that has "
|
||||
"an event reference." % class_name)
|
||||
|
@ -194,12 +194,17 @@ class MergeFamilyQuery:
|
||||
if phoenix_mother:
|
||||
phoenix_mother.remove_family_handle(old_handle)
|
||||
self.database.commit_person(phoenix_mother, trans)
|
||||
# replace the family in lds ordinances
|
||||
for (dummy, person_handle) in self.database.find_backlink_handles(
|
||||
old_handle, ['Person']):
|
||||
if person_handle in (self.titanic_fh, self.titanic_mh):
|
||||
# replace the family in lds ordinances and notes
|
||||
for (ref_obj, ref_handle) in self.database.find_backlink_handles(
|
||||
old_handle, ['Person', 'Note']):
|
||||
if ref_handle in (self.titanic_fh, self.titanic_mh):
|
||||
continue
|
||||
person = self.database.get_person_from_handle(person_handle)
|
||||
person.replace_handle_reference('Family', old_handle,new_handle)
|
||||
self.database.commit_person(person, trans)
|
||||
obj = self.database.method(
|
||||
"get_%s_from_handle", ref_obj)(ref_handle)
|
||||
assert obj.has_handle_reference('Family', old_handle)
|
||||
obj.replace_handle_reference(
|
||||
'Family', old_handle, new_handle)
|
||||
if ref_handle != old_handle:
|
||||
self.database.method("commit_%s", ref_obj)(obj, trans)
|
||||
|
||||
self.database.remove_family(old_handle, trans)
|
||||
|
@ -27,7 +27,7 @@ Provide merge capabilities for media objects.
|
||||
# Gramps modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from ..lib import Person, Family, Event, Source, Citation, Place
|
||||
from ..lib import Person, Family, Event, Source, Citation, Place, Note
|
||||
from ..db import DbTxn
|
||||
from ..const import GRAMPS_LOCALE as glocale
|
||||
_ = glocale.translation.sgettext
|
||||
@ -90,6 +90,12 @@ class MergeMediaQuery:
|
||||
assert(place.has_media_reference(old_handle))
|
||||
place.replace_media_references(old_handle, new_handle)
|
||||
self.database.commit_place(place, trans)
|
||||
elif class_name == Note.__name__:
|
||||
note = self.database.get_note_from_handle(handle)
|
||||
assert(note.has_handle_reference('Media', old_handle))
|
||||
note.replace_handle_reference(
|
||||
'Media', old_handle, new_handle)
|
||||
self.database.commit_note(note, trans)
|
||||
else:
|
||||
raise MergeError("Encounter an object of type % s that has "
|
||||
"a media object reference." % class_name)
|
||||
|
@ -28,7 +28,7 @@ Provide merge capabilities for notes.
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from ..lib import (Person, Family, Event, Place, Source, Citation, Repository,
|
||||
Media)
|
||||
Media, Note)
|
||||
from ..db import DbTxn
|
||||
from ..const import GRAMPS_LOCALE as glocale
|
||||
_ = glocale.translation.sgettext
|
||||
@ -99,6 +99,12 @@ class MergeNoteQuery:
|
||||
assert(repo.has_note_reference(old_handle))
|
||||
repo.replace_note_references(old_handle, new_handle)
|
||||
self.database.commit_repository(repo, trans)
|
||||
elif class_name == Note.__name__:
|
||||
note = self.database.get_note_from_handle(handle)
|
||||
assert(note.has_handle_reference('Note', old_handle))
|
||||
note.replace_handle_reference(
|
||||
'Note', old_handle, new_handle)
|
||||
self.database.commit_note(note, trans)
|
||||
else:
|
||||
raise MergeError("Encounter object of type %s that has "
|
||||
"a note reference." % class_name)
|
||||
|
@ -100,14 +100,16 @@ class MergePersonQuery:
|
||||
spouse.remove_family_handle(family_handle)
|
||||
self.database.commit_person(spouse, trans)
|
||||
# replace the family in lds ordinances
|
||||
for (dummy, person_handle) in self.database.find_backlink_handles(
|
||||
family_handle, ['Person']):
|
||||
if person_handle == old_handle:
|
||||
for (ref_obj, ref_handle) in self.database.find_backlink_handles(
|
||||
family_handle, ['Person', 'Note']):
|
||||
if ref_handle == old_handle:
|
||||
continue
|
||||
person = self.database.get_person_from_handle(person_handle)
|
||||
person.replace_handle_reference('Family', family_handle,
|
||||
main_family_handle)
|
||||
self.database.commit_person(person, trans)
|
||||
obj = self.database.method(
|
||||
"get_%s_from_handle", ref_obj)(ref_handle)
|
||||
assert obj.has_handle_reference('Family', family_handle)
|
||||
obj.replace_handle_reference('Family', family_handle,
|
||||
main_family_handle)
|
||||
self.database.method("commit_%s", ref_obj)(obj, trans)
|
||||
self.database.remove_family(family_handle, trans)
|
||||
self.database.commit_family(main_family, trans)
|
||||
|
||||
@ -133,13 +135,15 @@ class MergePersonQuery:
|
||||
self.phoenix.merge(self.titanic)
|
||||
self.database.commit_person(self.phoenix, trans)
|
||||
|
||||
for (dummy, person_handle) in self.database.find_backlink_handles(
|
||||
old_handle, ['Person']):
|
||||
person = self.database.get_person_from_handle(person_handle)
|
||||
assert person.has_handle_reference('Person', old_handle)
|
||||
person.replace_handle_reference('Person', old_handle, new_handle)
|
||||
if person_handle != old_handle:
|
||||
self.database.commit_person(person, trans)
|
||||
for (ref_obj, handle) in self.database.find_backlink_handles(
|
||||
old_handle, ['Person', 'Note']):
|
||||
obj = self.database.method(
|
||||
"get_%s_from_handle", ref_obj)(handle)
|
||||
assert obj.has_handle_reference('Person', old_handle)
|
||||
obj.replace_handle_reference(
|
||||
'Person', old_handle, new_handle)
|
||||
if handle != old_handle:
|
||||
self.database.method("commit_%s", ref_obj)(obj, trans)
|
||||
|
||||
for family_handle in self.phoenix.get_parent_family_handle_list():
|
||||
family = self.database.get_family_from_handle(family_handle)
|
||||
|
@ -28,7 +28,7 @@ Provide merge capabilities for places.
|
||||
# Gramps modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from ..lib import Person, Family, Event, Place
|
||||
from ..lib import Person, Family, Event, Place, Note
|
||||
from ..db import DbTxn
|
||||
from ..const import GRAMPS_LOCALE as glocale
|
||||
_ = glocale.translation.sgettext
|
||||
@ -85,6 +85,12 @@ class MergePlaceQuery:
|
||||
place.replace_handle_reference('Place', old_handle,
|
||||
new_handle)
|
||||
self.database.commit_place(place, trans)
|
||||
elif class_name == Note.__name__:
|
||||
note = self.database.get_note_from_handle(handle)
|
||||
assert(note.has_handle_reference('Place', old_handle))
|
||||
note.replace_handle_reference('Place', old_handle,
|
||||
new_handle)
|
||||
self.database.commit_note(note, trans)
|
||||
else:
|
||||
raise MergeError("Encounter an object of type %s that has "
|
||||
"a place reference." % class_name)
|
||||
|
@ -27,7 +27,7 @@ Provide merge capabilities for repositories.
|
||||
# Gramps modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from ..lib import Source
|
||||
from ..lib import Source, Note
|
||||
from ..db import DbTxn
|
||||
from ..const import GRAMPS_LOCALE as glocale
|
||||
_ = glocale.translation.sgettext
|
||||
@ -65,6 +65,12 @@ class MergeRepositoryQuery:
|
||||
assert source.has_handle_reference('Repository', old_handle)
|
||||
source.replace_repo_references(old_handle, new_handle)
|
||||
self.database.commit_source(source, trans)
|
||||
elif class_name == Note.__name__:
|
||||
note = self.database.get_note_from_handle(handle)
|
||||
assert(note.has_handle_reference('Repository', old_handle))
|
||||
note.replace_handle_reference(
|
||||
'Repository', old_handle, new_handle)
|
||||
self.database.commit_note(note, trans)
|
||||
else:
|
||||
raise MergeError("Encounter an object of type %s that has "
|
||||
"a repository reference." % class_name)
|
||||
|
@ -29,8 +29,7 @@ Provide merge capabilities for sources.
|
||||
# Gramps modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from ..lib import (Person, Family, Event, Place, Source, Repository,
|
||||
Media, Citation)
|
||||
from ..lib import (Citation, Note)
|
||||
from ..db import DbTxn
|
||||
from ..const import GRAMPS_LOCALE as glocale
|
||||
_ = glocale.translation.sgettext
|
||||
@ -68,6 +67,12 @@ class MergeSourceQuery:
|
||||
assert(citation.get_reference_handle() == old_handle)
|
||||
citation.set_reference_handle(new_handle)
|
||||
self.database.commit_citation(citation, trans)
|
||||
elif class_name == Note.__name__:
|
||||
note = self.database.get_note_from_handle(handle)
|
||||
assert(note.has_handle_reference('Source', old_handle))
|
||||
note.replace_handle_reference(
|
||||
'Source', old_handle, new_handle)
|
||||
self.database.commit_note(note, trans)
|
||||
else:
|
||||
raise MergeError("Encounter an object of type %s that has "
|
||||
"a source reference." % class_name)
|
||||
|
Loading…
Reference in New Issue
Block a user