Update database proxies to include tag objects

svn: r15950
This commit is contained in:
Nick Hall 2010-10-03 00:05:21 +00:00
parent 8c180108f7
commit b733d9e306
5 changed files with 85 additions and 0 deletions

View File

@ -282,5 +282,6 @@ class LivingProxyDb(ProxyDbBase):
new_person.set_family_handle_list(person.get_family_handle_list()) new_person.set_family_handle_list(person.get_family_handle_list())
new_person.set_parent_family_handle_list( new_person.set_parent_family_handle_list(
person.get_parent_family_handle_list() ) person.get_parent_family_handle_list() )
new_person.set_tag_list(person.get_tag_list())
return new_person return new_person

View File

@ -816,6 +816,9 @@ def sanitize_person(db, person):
copy_notes(db, person, new_person) copy_notes(db, person, new_person)
copy_associations(db, person, new_person) copy_associations(db, person, new_person)
# copy tags
new_person.set_tag_list(person.get_tag_list())
return new_person return new_person
def sanitize_source(db, source): def sanitize_source(db, source):

View File

@ -99,6 +99,7 @@ class ProxyDbBase(DbReadBase):
include_media_object = \ include_media_object = \
include_repository = \ include_repository = \
include_note = \ include_note = \
include_tag = \
None None
def get_person_handles(self, sort_handles=True): def get_person_handles(self, sort_handles=True):
@ -181,6 +182,16 @@ class ProxyDbBase(DbReadBase):
else: else:
return [] return []
def get_tag_handles(self, sort_handles=True):
"""
Return a list of database handles, one handle for each Tag in
the database.
"""
if self.db.is_open:
return list(self.iter_tag_handles())
else:
return []
def get_default_person(self): def get_default_person(self):
"""returns the default Person of the database""" """returns the default Person of the database"""
return self.db.get_default_person() return self.db.get_default_person()
@ -245,6 +256,13 @@ class ProxyDbBase(DbReadBase):
""" """
return ifilter(self.include_note, self.db.iter_note_handles()) return ifilter(self.include_note, self.db.iter_note_handles())
def iter_tag_handles(self):
"""
Return an iterator over database handles, one handle for each Tag in
the database.
"""
return ifilter(self.include_tag, self.db.iter_tag_handles())
@staticmethod @staticmethod
def __iter_object(filter, method): def __iter_object(filter, method):
""" Helper function to return an iterator over an object class """ """ Helper function to return an iterator over an object class """
@ -301,6 +319,12 @@ class ProxyDbBase(DbReadBase):
""" """
return self.__iter_object(self.include_note, self.db.iter_notes) return self.__iter_object(self.include_note, self.db.iter_notes)
def iter_tags(self):
"""
Return an iterator over Tag objects in the database
"""
return self.__iter_object(self.include_tag, self.db.iter_tags)
@staticmethod @staticmethod
def gfilter(predicate, obj): def gfilter(predicate, obj):
""" """
@ -398,6 +422,14 @@ class ProxyDbBase(DbReadBase):
return self.gfilter(self.include_note, return self.gfilter(self.include_note,
self.db.get_note_from_handle(handle)) self.db.get_note_from_handle(handle))
def get_tag_from_handle(self, handle):
"""
Finds a Tag in the database from the passed gramps handle.
If no such Tag exists, None is returned.
"""
return self.gfilter(self.include_tag,
self.db.get_tag_from_handle(handle))
def get_person_from_gramps_id(self, val): def get_person_from_gramps_id(self, val):
""" """
Finds a Person in the database from the passed GRAMPS ID. Finds a Person in the database from the passed GRAMPS ID.
@ -462,6 +494,14 @@ class ProxyDbBase(DbReadBase):
return self.gfilter(self.include_note, return self.gfilter(self.include_note,
self.db.get_note_from_gramps_id(val)) self.db.get_note_from_gramps_id(val))
def get_tag_from_name(self, val):
"""
Finds a Tag in the database from the passed tag name.
If no such Tag exists, None is returned.
"""
return self.gfilter(self.include_tag,
self.db.get_tag_from_name(val))
def get_name_group_mapping(self, name): def get_name_group_mapping(self, name):
""" """
Return the default grouping name for a surname Return the default grouping name for a surname
@ -528,6 +568,12 @@ class ProxyDbBase(DbReadBase):
""" """
return self.db.get_number_of_notes() return self.db.get_number_of_notes()
def get_number_of_tags(self):
"""
Return the number of tags currently in the database.
"""
return self.db.get_number_of_tags()
def get_save_path(self): def get_save_path(self):
"""returns the save path of the file, or "" if one does not exist""" """returns the save path of the file, or "" if one does not exist"""
return self.db.get_save_path() return self.db.get_save_path()
@ -625,6 +671,9 @@ class ProxyDbBase(DbReadBase):
def get_raw_note_data(self, handle): def get_raw_note_data(self, handle):
return self.db.get_raw_note_data(handle) return self.db.get_raw_note_data(handle)
def get_raw_tag_data(self, handle):
return self.db.get_raw_tag_data(handle)
def has_person_handle(self, handle): def has_person_handle(self, handle):
""" """
Returns True if the handle exists in the current Person database. Returns True if the handle exists in the current Person database.
@ -681,6 +730,13 @@ class ProxyDbBase(DbReadBase):
return self.gfilter(self.include_note, return self.gfilter(self.include_note,
self.db.get_note_from_gramps_id(val)) is not None self.db.get_note_from_gramps_id(val)) is not None
def has_tag_handle(self, handle):
"""
returns True if the handle exists in the current Tag database.
"""
return self.gfilter(self.include_tag,
self.db.get_tag_from_handle(handle)) is not None
def get_mediapath(self): def get_mediapath(self):
"""returns the default media path of the database""" """returns the default media path of the database"""
return self.db.get_mediapath() return self.db.get_mediapath()

View File

@ -49,6 +49,7 @@ class ReferencedProxyDb(ProxyDbBase):
self.unreferenced_repositories = set() self.unreferenced_repositories = set()
self.unreferenced_media_objects = set() self.unreferenced_media_objects = set()
self.unreferenced_notes = set() self.unreferenced_notes = set()
self.unreferenced_tags = set()
# Build lists of unreferenced objects # Build lists of unreferenced objects
self.__find_unreferenced_objects() self.__find_unreferenced_objects()
@ -89,6 +90,12 @@ class ReferencedProxyDb(ProxyDbBase):
""" """
return handle not in self.unreferenced_notes return handle not in self.unreferenced_notes
def include_tag(self, handle):
"""
Filter for tags
"""
return handle not in self.unreferenced_tags
def find_backlink_handles(self, handle, include_classes=None): def find_backlink_handles(self, handle, include_classes=None):
""" """
Find all objects that hold a reference to the object handle. Find all objects that hold a reference to the object handle.
@ -155,6 +162,7 @@ class ReferencedProxyDb(ProxyDbBase):
(self.unreferenced_media_objects, (self.unreferenced_media_objects,
self.get_media_object_handles), self.get_media_object_handles),
(self.unreferenced_notes, self.get_note_handles), (self.unreferenced_notes, self.get_note_handles),
(self.unreferenced_tags, self.get_tag_handles),
) )
last_count = 0 last_count = 0

View File

@ -86,6 +86,7 @@ class ReferencedBySelectionProxyDb(ProxyDbBase):
"Repository": set(), "Repository": set(),
"MediaObject": set(), "MediaObject": set(),
"Note": set(), "Note": set(),
"Tag": set(),
} }
def process_object(self, class_name, handle): def process_object(self, class_name, handle):
@ -179,6 +180,7 @@ class ReferencedBySelectionProxyDb(ProxyDbBase):
self.process_lds_ords(person) self.process_lds_ords(person)
self.process_notes(person) self.process_notes(person)
self.process_associations(person) self.process_associations(person)
self.process_tags(person)
def process_family(self, family): def process_family(self, family):
""" """
@ -302,6 +304,15 @@ class ReferencedBySelectionProxyDb(ProxyDbBase):
# -------------------------------------------- # --------------------------------------------
def process_tags(self, original_obj):
"""
Record the tags referenced by the primary object.
"""
for tag_handle in original_obj.get_tag_list():
self.referenced["Tag"].add(tag_handle)
# --------------------------------------------
def process_name(self, name): def process_name(self, name):
""" Find all of the primary objects referred to """ """ Find all of the primary objects referred to """
self.process_source_ref_list(name) self.process_source_ref_list(name)
@ -446,6 +457,12 @@ class ReferencedBySelectionProxyDb(ProxyDbBase):
""" """
return handle in self.referenced["Note"] return handle in self.referenced["Note"]
def include_tag(self, handle):
"""
Filter for tags
"""
return handle in self.referenced["Tag"]
def find_backlink_handles(self, handle, include_classes=None): def find_backlink_handles(self, handle, include_classes=None):
""" """
Return appropriate backlink handles for this proxy. Return appropriate backlink handles for this proxy.