diff --git a/gramps/gen/lib/citation.py b/gramps/gen/lib/citation.py index 4a3598fa0..56d366a6f 100644 --- a/gramps/gen/lib/citation.py +++ b/gramps/gen/lib/citation.py @@ -45,6 +45,7 @@ from .notebase import NoteBase from .datebase import DateBase from .tagbase import TagBase from .attrbase import SrcAttributeBase +from .citationbase import IndirectCitationBase from ..constfunc import cuni from .handle import Handle @@ -53,7 +54,8 @@ from .handle import Handle # Citation class # #------------------------------------------------------------------------- -class Citation(MediaBase, NoteBase, SrcAttributeBase, PrimaryObject, DateBase): +class Citation(MediaBase, NoteBase, SrcAttributeBase, IndirectCitationBase, + DateBase, PrimaryObject): """ A record of a citation of a source of information. @@ -266,43 +268,6 @@ class Citation(MediaBase, NoteBase, SrcAttributeBase, PrimaryObject, DateBase): ret += [('Source', self.get_reference_handle())] return ret - def has_citation_reference(self, citation_handle) : - """ - Return True if any of the child objects has reference to this citation - handle. - - HACK cut and paste from Repository.has_citation_reference - - :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. - - HACK cut and paste from Repository.has_citation_reference - - 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 merge(self, acquisition): """ Merge the content of acquisition into this source. diff --git a/gramps/gen/lib/citationbase.py b/gramps/gen/lib/citationbase.py index 233faa6e2..f568a423d 100644 --- a/gramps/gen/lib/citationbase.py +++ b/gramps/gen/lib/citationbase.py @@ -263,3 +263,56 @@ class CitationBase(object): for item in self.get_citation_child_list(): item.replace_citation_references(old_handle, new_handle) + +class IndirectCitationBase(object): + """ + Citation management logic for objects that don't have citations + for the primary objects, but only for the child (secondary) ones. + + The derived class must implement get_citation_child_list method + to return the list of child secondary objects that may refer + citations. + + Note: for most objects, this functionality is inherited from + CitationBase, which checks both the object and the child objects. + """ + 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 replace_citation_references(self, old_handle, new_handle): + """ + Replace references to citation handles in + 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 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) diff --git a/gramps/gen/lib/eventref.py b/gramps/gen/lib/eventref.py index 33f93a69f..872b97800 100644 --- a/gramps/gen/lib/eventref.py +++ b/gramps/gen/lib/eventref.py @@ -38,13 +38,15 @@ from .attrbase import AttributeBase from .refbase import RefBase from .eventroletype import EventRoleType from .const import IDENTICAL, EQUAL, DIFFERENT +from .citationbase import IndirectCitationBase #------------------------------------------------------------------------- # # Event References for Person/Family # #------------------------------------------------------------------------- -class EventRef(SecondaryObject, PrivacyBase, NoteBase, AttributeBase, RefBase): +class EventRef(PrivacyBase, NoteBase, AttributeBase, RefBase, + IndirectCitationBase, SecondaryObject): """ Event reference class. @@ -180,47 +182,6 @@ 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/gramps/gen/lib/repo.py b/gramps/gen/lib/repo.py index 89dd5d0e4..3695d2e9f 100644 --- a/gramps/gen/lib/repo.py +++ b/gramps/gen/lib/repo.py @@ -39,13 +39,15 @@ from .tagbase import TagBase from .repotype import RepositoryType from ..constfunc import cuni from .handle import Handle +from .citationbase import IndirectCitationBase #------------------------------------------------------------------------- # # Repository class # #------------------------------------------------------------------------- -class Repository(NoteBase, AddressBase, UrlBase, PrimaryObject): +class Repository(NoteBase, AddressBase, UrlBase, + IndirectCitationBase, PrimaryObject): """A location where collections of Sources are found.""" def __init__(self): @@ -176,59 +178,6 @@ class Repository(NoteBase, AddressBase, UrlBase, PrimaryObject): return (self.get_referenced_note_handles() + self.get_referenced_tag_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 remove_citation_references(self, citation_handle_list): - """ - Remove references to all citation handles in the list in all child - objects. - - Note: the same comment about citationbase in has_citation_reference - applies here too. - - :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. - - 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 merge(self, acquisition): """ Merge the content of acquisition into this repository.