diff --git a/src/gen/db/upgrade.py b/src/gen/db/upgrade.py index ea84ca2db..424317150 100644 --- a/src/gen/db/upgrade.py +++ b/src/gen/db/upgrade.py @@ -126,9 +126,11 @@ def gramps_upgrade_16(self): if person_ref_list: person_ref_list = upgrade_person_ref_list_16( self, person_ref_list) + if event_ref_list: + event_ref_list = upgrade_event_ref_list_16(self, event_ref_list) if primary_name or alternate_names or address_list or \ media_list or attribute_list or lds_seal_list or source_list or \ - person_ref_list: + person_ref_list or event_ref_list: new_person = (handle, gramps_id, gender, primary_name, alternate_names, death_ref_index, birth_ref_index, event_ref_list, family_list, @@ -244,12 +246,14 @@ def gramps_upgrade_16(self): if attribute_list: attribute_list = upgrade_attribute_list_16( self, attribute_list) + if event_ref_list: + event_ref_list = upgrade_event_ref_list_16(self, event_ref_list) if source_list or media_list or child_ref_list or \ - attribute_list or lds_seal_list: + attribute_list or lds_seal_list or event_ref_list: new_family = (handle, gramps_id, father_handle, mother_handle, child_ref_list, the_type, event_ref_list, media_list, - attribute_list, lds_seal_list, new_citation_list, note_list, - change, tag_list, private) + attribute_list, lds_seal_list, new_citation_list, + note_list, change, tag_list, private) with BSDDBTxn(self.env, self.family_map) as txn: txn.put(str(handle), new_family) self.update() @@ -503,6 +507,16 @@ def upgrade_person_ref_list_16(self, person_ref_list): new_person_ref_list.append((new_person_ref)) return new_person_ref_list +def upgrade_event_ref_list_16(self, event_ref_list): + new_event_ref_list = [] + for event_ref in event_ref_list: + (privacy, note_list, attribute_list, ref, role) = event_ref + new_attribute_list = upgrade_attribute_list_16( + self, attribute_list) + new_event_ref = (privacy, note_list, new_attribute_list, ref, role) + new_event_ref_list.append((new_event_ref)) + return new_event_ref_list + def convert_source_list_to_citation_list_16(self, source_list): citation_list = [] for source in source_list: diff --git a/src/gen/lib/baseobj.py b/src/gen/lib/baseobj.py index fc37230b5..b64325677 100644 --- a/src/gen/lib/baseobj.py +++ b/src/gen/lib/baseobj.py @@ -166,10 +166,13 @@ class BaseObject(object): :rtype: list """ ret = self.get_referenced_handles() + # FIXME: remove this print "Directly referenced primary objects from", self, ret + #print self.get_handle_referents() # Run through child objects for obj in self.get_handle_referents(): ret += obj.get_referenced_handles_recursively() + #print "cummulative refs", ret return ret def merge(self, acquisition): diff --git a/src/gen/lib/citationbase.py b/src/gen/lib/citationbase.py index c600f0092..58332538d 100644 --- a/src/gen/lib/citationbase.py +++ b/src/gen/lib/citationbase.py @@ -93,7 +93,7 @@ class CitationBase(object): self.citation_list.append(handle) return True - def remove_citation_refs(self, citation_handle_list): + def remove_citation_references(self, citation_handle_list): """ Remove the specified handles from the list of citation handles, and all secondary child objects. @@ -111,7 +111,7 @@ class CitationBase(object): LOG.debug('get_citation_child_list %s' % self.get_citation_child_list()) for item in self.get_citation_child_list(): - item.remove_citation_refs(citation_handle_list) + item.remove_citation_references(citation_handle_list) def get_citation_child_list(self): """ @@ -166,6 +166,7 @@ class CitationBase(object): if citation_ref == citation_handle: return True + LOG.debug("citation child list %s" % self.get_citation_child_list()) for item in self.get_citation_child_list(): if item.has_citation_reference(citation_handle): return True diff --git a/src/gen/lib/eventref.py b/src/gen/lib/eventref.py index 46cb364c2..e5f97b1b4 100644 --- a/src/gen/lib/eventref.py +++ b/src/gen/lib/eventref.py @@ -152,6 +152,47 @@ 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 diff --git a/src/gen/lib/family.py b/src/gen/lib/family.py index a81acd021..cf0eb5a67 100644 --- a/src/gen/lib/family.py +++ b/src/gen/lib/family.py @@ -284,7 +284,8 @@ class Family(CitationBase, NoteBase, MediaBase, AttributeBase, LdsOrdBase, :rtype: list """ check_list = self.media_list + self.attribute_list + \ - self.lds_ord_list + self.child_ref_list + self.lds_ord_list + self.child_ref_list + \ + self.event_ref_list return check_list def get_note_child_list(self): diff --git a/src/gen/lib/person.py b/src/gen/lib/person.py index b91562090..fb1a92850 100644 --- a/src/gen/lib/person.py +++ b/src/gen/lib/person.py @@ -389,7 +389,8 @@ class Person(CitationBase, NoteBase, AttributeBase, MediaBase, self.address_list + self.attribute_list + self.lds_ord_list + - self.person_ref_list + self.person_ref_list + + self.event_ref_list ) def get_note_child_list(self): @@ -433,7 +434,7 @@ class Person(CitationBase, NoteBase, AttributeBase, MediaBase, :returns: Returns the list of objects referencing primary objects. :rtype: list """ - return (self.get_citation_child_list() + self.event_ref_list) + return (self.get_citation_child_list()) def merge(self, acquisition): """ diff --git a/src/gui/editors/editcitation.py b/src/gui/editors/editcitation.py index 2fecf76a9..636731fd9 100644 --- a/src/gui/editors/editcitation.py +++ b/src/gui/editors/editcitation.py @@ -234,8 +234,6 @@ class EditCitation(EditPrimary): necessary to connect to the source- rebuild signal for similar reasons. """ - # FIXME: Should this be modified so that the 'close' routines - # are executed not only for the 'Citation', bit also for the 'Source' self._add_db_signal('citation-rebuild', self._do_close) self._add_db_signal('citation-delete', self.check_for_close) @@ -292,7 +290,7 @@ class EditCitation(EditPrimary): self.source_privacy = PrivacyButton( self.glade.get_object("private"), - self.obj, self.db.readonly) + self.source, self.db.readonly) self.abbrev = MonitoredEntry( self.glade.get_object('abbrev'), self.source.set_abbreviation, @@ -453,37 +451,37 @@ class DeleteCitationQuery(object): for handle in person_list: person = self.db.get_person_from_handle(handle) - person.remove_citation_refs(ctn_handle_list) + person.remove_citation_references(ctn_handle_list) self.db.commit_person(person, trans) for handle in family_list: family = self.db.get_family_from_handle(handle) - family.remove_citation_refs(ctn_handle_list) + family.remove_citation_references(ctn_handle_list) self.db.commit_family(family, trans) for handle in event_list: event = self.db.get_event_from_handle(handle) - event.remove_citation_refs(ctn_handle_list) + event.remove_citation_references(ctn_handle_list) self.db.commit_event(event, trans) for handle in place_list: place = self.db.get_place_from_handle(handle) - place.remove_citation_refs(ctn_handle_list) + place.remove_citation_references(ctn_handle_list) self.db.commit_place(place, trans) for handle in source_list: source = self.db.get_source_from_handle(handle) - source.remove_citation_refs(ctn_handle_list) + source.remove_citation_references(ctn_handle_list) self.db.commit_source(source, trans) for handle in media_list: media = self.db.get_object_from_handle(handle) - media.remove_citation_refs(ctn_handle_list) + media.remove_citation_references(ctn_handle_list) self.db.commit_media_object(media, trans) for handle in repo_list: repo = self.db.get_repository_from_handle(handle) - repo.remove_citation_refs(ctn_handle_list) + repo.remove_citation_references(ctn_handle_list) self.db.commit_repository(repo, trans) self.db.enable_signals() diff --git a/src/gui/editors/editsource.py b/src/gui/editors/editsource.py index b5dbfed8f..acc894812 100644 --- a/src/gui/editors/editsource.py +++ b/src/gui/editors/editsource.py @@ -246,37 +246,37 @@ class DeleteSrcQuery(object): for handle in person_list: person = self.db.get_person_from_handle(handle) - person.remove_citation_refs(ctn_handle_list) + person.remove_citation_references(ctn_handle_list) self.db.commit_person(person, trans) for handle in family_list: family = self.db.get_family_from_handle(handle) - family.remove_citation_refs(ctn_handle_list) + family.remove_citation_references(ctn_handle_list) self.db.commit_family(family, trans) for handle in event_list: event = self.db.get_event_from_handle(handle) - event.remove_citation_refs(ctn_handle_list) + event.remove_citation_references(ctn_handle_list) self.db.commit_event(event, trans) for handle in place_list: place = self.db.get_place_from_handle(handle) - place.remove_citation_refs(ctn_handle_list) + place.remove_citation_references(ctn_handle_list) self.db.commit_place(place, trans) for handle in source_list: source = self.db.get_source_from_handle(handle) - source.remove_citation_refs(ctn_handle_list) + source.remove_citation_references(ctn_handle_list) self.db.commit_source(source, trans) for handle in media_list: media = self.db.get_object_from_handle(handle) - media.remove_citation_refs(ctn_handle_list) + media.remove_citation_references(ctn_handle_list) self.db.commit_media_object(media, trans) for handle in repo_list: repo = self.db.get_repository_from_handle(handle) - repo.remove_citation_refs(ctn_handle_list) + repo.remove_citation_references(ctn_handle_list) self.db.commit_repository(repo, trans) # (2) delete the actual citations diff --git a/src/plugins/tool/Check.py b/src/plugins/tool/Check.py index 1b627dfbb..27a8a8b74 100644 --- a/src/plugins/tool/Check.py +++ b/src/plugins/tool/Check.py @@ -1022,7 +1022,7 @@ class CheckIntegrity(object): if item[0] == 'Citation' and item[1] not in known_handles ] if bad_handles: - person.remove_citation_refs(bad_handles) + person.remove_citation_references(bad_handles) self.db.commit_person(person,self.trans) new_bad_handles = [handle for handle in bad_handles if handle not in self.invalid_citation_references] @@ -1038,7 +1038,7 @@ class CheckIntegrity(object): if item[0] == 'Citation' and item[1] not in known_handles ] if bad_handles: - family.remove_citation_refs(bad_handles) + family.remove_citation_references(bad_handles) self.db.commit_family(family, self.trans) new_bad_handles = [handle for handle in bad_handles if handle not in self.invalid_citation_references] @@ -1054,7 +1054,7 @@ class CheckIntegrity(object): if item[0] == 'Citation' and item[1] not in known_handles ] if bad_handles: - place.remove_citation_refs(bad_handles) + place.remove_citation_references(bad_handles) self.db.commit_place(place,self.trans) new_bad_handles = [handle for handle in bad_handles if handle not in self.invalid_citation_references] @@ -1070,7 +1070,7 @@ class CheckIntegrity(object): if item[0] == 'Citation' and item[1] not in known_handles ] if bad_handles: - repo.remove_citation_refs(bad_handles) + repo.remove_citation_references(bad_handles) self.db.commit_repository(repo, self.trans) new_bad_handles = [handle for handle in bad_handles if handle not in self.invalid_citation_references] @@ -1087,7 +1087,7 @@ class CheckIntegrity(object): if item[0] == 'Citation' and item[1] not in known_handles ] if bad_handles: - citation.remove_citation_refs(bad_handles) + citation.remove_citation_references(bad_handles) self.db.commit_citation(citation, self.trans) new_bad_handles = [handle for handle in bad_handles if handle not in self.invalid_citation_references] @@ -1103,7 +1103,7 @@ class CheckIntegrity(object): if item[0] == 'Citation' and item[1] not in known_handles ] if bad_handles: - obj.remove_citation_refs(bad_handles) + obj.remove_citation_references(bad_handles) self.db.commit_media_object(obj, self.trans) new_bad_handles = [handle for handle in bad_handles if handle not in self.invalid_citation_references] @@ -1119,7 +1119,7 @@ class CheckIntegrity(object): if item[0] == 'Citation' and item[1] not in known_handles ] if bad_handles: - event.remove_citation_refs(bad_handles) + event.remove_citation_references(bad_handles) self.db.commit_event(event, self.trans) new_bad_handles = [handle for handle in bad_handles if handle not in self.invalid_citation_references]