Proxy databases:

1. Provide default methods in proxybase.py for get_<object>_handles and iter_<object>_handles
2. Implement callouts in iter_<object>_handles to determine if handles should be included or not
3. Added new methods to dbbase.py raising NotImplementedError for the new iter_<object>_handles methods
4. Implemented new methods in living.py, private.py and referenced.py
5. Changed filter.py to use iter_person_handles instead of get_person_handles
6. Removed duplicate methods from children of ProxyDbBase


svn: r12783
This commit is contained in:
Gerald Britton 2009-07-10 19:24:43 +00:00
parent 01492a1974
commit 56c79b6fa4
6 changed files with 316 additions and 388 deletions

View File

@ -608,13 +608,20 @@ class DbBase(object):
"""
raise NotImplementedError
def iter_person_handles(self):
def get_family_handles(self):
"""
Return an iterator over database handles, one handle for each Person in
the database. If sort_handles is True, the list is sorted by surnames
Return a list of database handles, one handle for each Family in
the database.
"""
raise NotImplementedError
def get_event_handles(self):
"""
Return a list of database handles, one handle for each Event in
the database.
"""
raise NotImplementedError
def get_place_handles(self, sort_handles=True):
"""
Return a list of database handles, one handle for each Place in
@ -638,20 +645,6 @@ class DbBase(object):
"""
raise NotImplementedError
def get_event_handles(self):
"""
Return a list of database handles, one handle for each Event in
the database.
"""
raise NotImplementedError
def get_family_handles(self):
"""
Return a list of database handles, one handle for each Family in
the database.
"""
raise NotImplementedError
def get_repository_handles(self):
"""
Return a list of database handles, one handle for each Repository in
@ -666,6 +659,62 @@ class DbBase(object):
"""
raise NotImplementedError
def iter_person_handles(self):
"""
Return an iterator over database handles, one handle for each Person in
the database.
"""
raise NotImplementedError
def iter_family_handles(self):
"""
Return an iterator over database handles, one handle for each Family in
the database.
"""
raise NotImplementedError
def iter_event_handles(self):
"""
Return an iterator over database handles, one handle for each Event in
the database.
"""
raise NotImplementedError
def iter_source_handles(self):
"""
Return an iterator over database handles, one handle for each Source in
the database.
"""
raise NotImplementedError
def iter_place_handles(self):
"""
Return an iterator over database handles, one handle for each Place in
the database.
"""
raise NotImplementedError
def iter_media_object_handles(self):
"""
Return an iterator over database handles, one handle for each Media
Object in the database.
"""
raise NotImplementedError
def iter_repository_handles(self):
"""
Return an iterator over database handles, one handle for each
Repository in the database.
"""
raise NotImplementedError
def iter_note_handles(self):
"""
Return an iterator over database handles, one handle for each Note in
the database.
"""
raise NotImplementedError
def get_gramps_ids(self, obj_key):
raise NotImplementedError

View File

@ -51,21 +51,21 @@ class FilterProxyDb(ProxyDbBase):
if person_filter:
self.plist = set(person_filter.apply(
self.db, self.db.get_person_handles(sort_handles=False)))
self.db, self.db.iter_person_handles()))
else:
self.plist = self.db.get_person_handles(sort_handles=False)
self.plist = self.db.iter_person_handles()
if event_filter:
self.elist = set(event_filter.apply(
self.db, self.db.get_event_handles()))
self.db, self.db.iter_event_handles()))
else:
self.elist = self.db.get_event_handles()
self.elist = self.db.iter_event_handles()
if note_filter:
self.nlist = set(note_filter.apply(
self.db, self.db.get_note_handles()))
self.db, self.db.iter_note_handles()))
else:
self.nlist = self.db.get_note_handles()
self.nlist = self.db.iter_note_handles()
self.flist = set()
for handle in list(self.plist):
@ -284,40 +284,10 @@ class FilterProxyDb(ProxyDbBase):
def iter_person_handles(self):
"""
Return an iterator over database handles, one handle for each Person in
the database. If sort_handles is True, the list is sorted by surnames
the database.
"""
# FIXME: plist is not a sorted list of handles
return (h for h in self.plist)
def get_place_handles(self, sort_handles=True):
"""
Return a list of database handles, one handle for each Place in
the database. If sort_handles is True, the list is sorted by
Place title.
"""
return self.db.get_place_handles(sort_handles)
def iter_place_handles(self):
"""
Return an iterator database handles, one handle for each Place in
the database.
"""
return self.db.iter_place_handles(sort_handles)
def get_source_handles(self, sort_handles=True):
"""
Return a list of database handles, one handle for each Source in
the database. If sort_handles is True, the list is sorted by
Source title.
"""
return self.db.get_source_handles(sort_handles)
def get_media_object_handles(self, sort_handles=True):
"""
Return a list of database handles, one handle for each MediaObject in
the database. If sort_handles is True, the list is sorted by title.
"""
return self.db.get_media_object_handles(sort_handles)
return self.plist
def get_event_handles(self):
"""
@ -333,13 +303,6 @@ class FilterProxyDb(ProxyDbBase):
"""
return list(self.flist)
def get_repository_handles(self):
"""
Return a list of database handles, one handle for each Repository in
the database.
"""
return self.db.get_repository_handles()
def get_note_handles(self):
"""
Return a list of database handles, one handle for each Note in
@ -347,11 +310,6 @@ class FilterProxyDb(ProxyDbBase):
"""
return list(self.nlist)
def get_researcher(self):
"""returns the Researcher instance, providing information about
the owner of the database"""
return self.db.get_researcher()
def get_default_person(self):
"""returns the default Person of the database"""
person = self.db.get_default_person()

View File

@ -212,105 +212,13 @@ class LivingProxyDb(ProxyDbBase):
"""
return self.db.get_note_from_gramps_id(val)
def get_person_handles(self, sort_handles=True):
"""
Return a list of database handles, one handle for each Person in
the database. If sort_handles is True, the list is sorted by surnames
"""
handles = []
def person_predicate(self, handle):
if self.mode == self.MODE_EXCLUDE_ALL:
for handle in self.db.get_person_handles(sort_handles):
person = self.db.get_person_from_handle(handle)
if not self.__is_living(person):
handles.append(handle)
else:
handles = self.db.get_person_handles(sort_handles)
return handles
def iter_person_handles(self):
"""
Return an iterator over database handles, one handle for each Person in
the database.
"""
if self.mode == self.MODE_EXCLUDE_ALL:
for handle in self.db.iter_person_handles():
person = self.db.get_person_from_handle(handle)
if self.mode == self.MODE_EXCLUDE_ALL:
if not self.__is_living(person):
yield handle
else:
yield handle
def get_place_handles(self, sort_handles=True):
"""
Return a list of database handles, one handle for each Place in
the database. If sort_handles is True, the list is sorted by
Place title.
"""
return self.db.get_place_handles(sort_handles)
def iter_place_handles(self):
"""
Return an iterator over database handles, one handle for each Place in
the database.
"""
return self.db.get_place_handles(sort_handles)
def get_source_handles(self, sort_handles=True):
"""
Return a list of database handles, one handle for each Source in
the database. If sort_handles is True, the list is sorted by
Source title.
"""
return self.db.get_source_handles(sort_handles)
def get_media_object_handles(self, sort_handles=True):
"""
Return a list of database handles, one handle for each MediaObject in
the database. If sort_handles is True, the list is sorted by title.
"""
return self.db.get_media_object_handles(sort_handles)
def get_event_handles(self):
"""
Return a list of database handles, one handle for each Event in
the database.
"""
return self.db.get_event_handles()
def get_family_handles(self):
"""
Return a list of database handles, one handle for each Family in
the database.
"""
return self.db.get_family_handles()
def iter_family_handles(self):
"""
Return an iterator over database handles, one handle for each Family in
the database..
"""
return self.db.iter_family_handles()
def get_repository_handles(self):
"""
Return a list of database handles, one handle for each Repository in
the database.
"""
return self.db.get_repository_handles()
def get_note_handles(self):
"""
Return a list of database handles, one handle for each Note in
the database.
"""
return self.db.get_note_handles()
def get_researcher(self):
"""returns the Researcher instance, providing information about
the owner of the database"""
return self.db.get_researcher()
person = self.db.get_person_from_handle(handle)
if self.__is_living(person):
return False
return True
def get_default_person(self):
"""returns the default Person of the database"""
person_handle = self.db.get_default_handle()

View File

@ -206,138 +206,63 @@ class PrivateProxyDb(ProxyDbBase):
return note
return None
def get_person_handles(self, sort_handles=True):
# Define predicate functions for use by default iterator methods
def person_predicate(self, handle):
"""
Return a list of database handles, one handle for each Person in
the database. If sort_handles is True, the list is sorted by surnames
Predicate returning True if object is to be included, else False
"""
handles = []
for handle in self.db.get_person_handles(sort_handles):
person = self.db.get_person_from_handle(handle)
if not person.get_privacy():
handles.append(handle)
return handles
def iter_person_handles(self):
obj = self.db.get_person_from_handle(handle)
return not obj.get_privacy()
def family_predicate(self, handle):
"""
Return an iterator over database handles, one handle for each Person in
the database. If sort_handles is True, the list is sorted by surnames
Predicate returning True if object is to be included, else False
"""
obj = self.db.get_family_from_handle(handle)
return not obj.get_privacy()
def event_predicate(self, handle):
"""
for handle in self.db.iter_person_handles():
person = self.db.get_person_from_handle(handle)
if not person.get_privacy():
yield handle
def get_place_handles(self, sort_handles=True):
Predicate returning True if object is to be included, else False
"""
obj = self.db.get_event_from_handle(handle)
return not obj.get_privacy()
def source_predicate(self, handle):
"""
Return a list of database handles, one handle for each Place in
the database. If sort_handles is True, the list is sorted by
Place title.
Predicate returning True if object is to be included, else False
"""
obj = self.db.get_source_from_handle(handle)
return not obj.get_privacy()
def place_predicate(self, handle):
"""
handles = []
for handle in self.db.get_place_handles(sort_handles):
place = self.db.get_place_from_handle(handle)
if not place.get_privacy():
handles.append(handle)
return handles
def iter_place_handles(self):
Predicate returning True if object is to be included, else False
"""
obj = self.db.get_place_from_handle(handle)
return not obj.get_privacy()
def object_predicate(self, handle):
"""
Return an iterator over database handles, one handle for each Place in
the database.
Predicate returning True if object is to be included, else False
"""
obj = self.db.get_object_from_handle(handle)
return not obj.get_privacy()
def repository_predicate(self, handle):
"""
for handle in self.db.get_place_handles(sort_handles):
place = self.db.get_place_from_handle(handle)
if not place.get_privacy():
yield handle
def get_source_handles(self, sort_handles=True):
Predicate returning True if object is to be included, else False
"""
obj = self.db.get_repository_from_handle(handle)
return not obj.get_privacy()
def note_predicate(self, handle):
"""
Return a list of database handles, one handle for each Source in
the database. If sort_handles is True, the list is sorted by
Source title.
"""
handles = []
for handle in self.db.get_source_handles(sort_handles):
source = self.db.get_source_from_handle(handle)
if not source.get_privacy():
handles.append(handle)
return handles
def get_media_object_handles(self, sort_handles=True):
"""
Return a list of database handles, one handle for each MediaObject in
the database. If sort_handles is True, the list is sorted by title.
"""
handles = []
for handle in self.db.get_media_object_handles(sort_handles):
object = self.db.get_object_from_handle(handle)
if not object.get_privacy():
handles.append(handle)
return handles
def get_event_handles(self):
"""
Return a list of database handles, one handle for each Event in
the database.
"""
handles = []
for handle in self.db.get_event_handles():
event = self.db.get_event_from_handle(handle)
if not event.get_privacy():
handles.append(handle)
return handles
def get_family_handles(self):
"""
Return a list of database handles, one handle for each Family in
the database.
"""
handles = []
for handle in self.db.iter_family_handles():
family = self.db.get_family_from_handle(handle)
if not family.get_privacy():
handles.append(handle)
return handles
def iter_family_handles(self):
"""
Return an iterator over database handles, one handle for each Family in
the database.
"""
for handle in self.db.iter_family_handles():
family = self.db.get_family_from_handle(handle)
if not family.get_privacy():
yield handle
def get_repository_handles(self):
"""
Return a list of database handles, one handle for each Repository in
the database.
"""
handles = []
for handle in self.db.get_repository_handles():
repository = self.db.get_repository_from_handle(handle)
if not repository.get_privacy():
handles.append(handle)
return handles
def get_note_handles(self):
"""
Return a list of database handles, one handle for each Note in
the database.
"""
handles = []
for handle in self.db.get_note_handles():
note = self.db.get_note_from_handle(handle)
if not note.get_privacy():
handles.append(handle)
return handles
def get_researcher(self):
"""returns the Researcher instance, providing information about
the owner of the database"""
return self.db.get_researcher()
Predicate returning True if object is to be included, else False
"""
obj = self.db.get_note_from_handle(handle)
return not obj.get_privacy()
def get_default_person(self):
"""returns the default Person of the database"""

View File

@ -24,6 +24,13 @@
Proxy class for the GRAMPS databases. Filter out all data marked private.
"""
#-------------------------------------------------------------------------
#
# Python modules
#
#-------------------------------------------------------------------------
from itertools import ifilter
#-------------------------------------------------------------------------
#
# GRAMPS libraries
@ -62,6 +69,165 @@ class ProxyDbBase(DbBase):
Return 1 if the database has been opened.
"""
return self.db.is_open
def get_researcher(self):
"""returns the Researcher instance, providing information about
the owner of the database"""
return self.db.get_researcher()
def predicate(self, handle):
"""
Default predicate. Returns True
"""
return True
# Define default predicates for each object type
person_predicate = \
family_predicate = \
event_predicate = \
source_predicate = \
place_predicate = \
object_predicate = \
repository_predicate = \
note_predicate = \
predicate
def get_person_handles(self, sort_handles=True):
"""
Return a list of database handles, one handle for each Person in
the database.
"""
if self.db.is_open:
return list(self.iter_person_handles())
else:
return []
def get_family_handles(self, sort_handles=True):
"""
Return a list of database handles, one handle for each Family in
the database.
"""
if self.db.is_open:
return list(self.iter_family_handles())
else:
return []
def get_event_handles(self, sort_handles=True):
"""
Return a list of database handles, one handle for each Event in
the database.
"""
if self.db.is_open:
return list(self.iter_event_handles())
else:
return []
def get_source_handles(self, sort_handles=True):
"""
Return a list of database handles, one handle for each Source in
the database.
"""
if self.db.is_open:
return list(self.iter_source_handles())
else:
return []
def get_place_handles(self, sort_handles=True):
"""
Return a list of database handles, one handle for each Place in
the database.
"""
if self.db.is_open:
return list(self.iter_place_handles())
else:
return []
def get_media_object_handles(self, sort_handles=True):
"""
Return a list of database handles, one handle for each MediaObject in
the database.
"""
if self.db.is_open:
return list(self.iter_media_object_handles())
else:
return []
def get_repository_handles(self, sort_handles=True):
"""
Return a list of database handles, one handle for each Repository in
the database.
"""
if self.db.is_open:
return list(self.iter_repository_handles())
else:
return []
def get_note_handles(self, sort_handles=True):
"""
Return a list of database handles, one handle for each Note in
the database.
"""
if self.db.is_open:
return list(self.iter_note_handles())
else:
return []
def iter_person_handles(self):
"""
Return an iterator over database handles, one handle for each Person in
the database.
"""
return ifilter(self.person_predicate, self.db.iter_person_handles())
def iter_family_handles(self):
"""
Return an iterator over database handles, one handle for each Family in
the database.
"""
return ifilter(self.family_predicate, self.db.iter_family_handles())
def iter_event_handles(self):
"""
Return an iterator over database handles, one handle for each Event in
the database.
"""
return ifilter(self.event_predicate, self.db.iter_event_handles())
def iter_source_handles(self):
"""
Return an iterator over database handles, one handle for each Source in
the database.
"""
return ifilter(self.source_predicate, self.db.iter_source_handles())
def iter_place_handles(self):
"""
Return an iterator over database handles, one handle for each Place in
the database.
"""
return ifilter(self.place_predicate, self.db.iter_place_handles())
def iter_media_object_handles(self):
"""
Return an iterator over database handles, one handle for each Media
Object in the database.
"""
return ifilter(self.object_predicate, self.db.iter_media_object_handles())
def iter_repository_handles(self):
"""
Return an iterator over database handles, one handle for each
Repository in the database.
"""
return ifilter(self.repository_predicate, self.db.iter_repository_handles())
def iter_note_handles(self):
"""
Return an iterator over database handles, one handle for each Note in
the database.
"""
return ifilter(self.note_predicate, self.db.iter_note_handles())
def get_name_group_mapping(self, name):
"""
@ -85,43 +251,43 @@ class ProxyDbBase(DbBase):
"""
Return the number of people currently in the databse.
"""
return len(self.get_person_handles())
return self.db.get_number_of_people()
def get_number_of_families(self):
"""
Return the number of families currently in the databse.
"""
return len(self.get_family_handles())
return self.db.get_number_of_families()
def get_number_of_events(self):
"""
Return the number of events currently in the databse.
"""
return len(self.get_event_handles())
return self.db.get_number_of_events()
def get_number_of_places(self):
"""
Return the number of places currently in the databse.
"""
return len(self.get_place_handles())
return self.db.get_number_of_places()
def get_number_of_sources(self):
"""
Return the number of sources currently in the databse.
"""
return len(self.get_source_handles())
return self.db.get_number_of_sources()
def get_number_of_media_objects(self):
"""
Return the number of media objects currently in the databse.
"""
return len(self.get_media_object_handles())
return self.db.get_number_of_media_objects()
def get_number_of_repositories(self):
"""
Return the number of source repositories currently in the databse.
"""
return len(self.get_repository_handles())
return self.db.get_number_of_repositories()
def get_number_of_notes(self):
"""

View File

@ -165,99 +165,21 @@ class ReferencedProxyDb(ProxyDbBase):
"""
return self.db.get_note_from_gramps_id(val)
def get_person_handles(self, sort_handles=True):
"""
Return a list of database handles, one handle for each Person in
the database. If sort_handles is True, the list is sorted by surnames
"""
return self.db.get_person_handles(sort_handles)
def iter_person_handles(self):
"""
Return an iterator over database handles, one handle for each Person in
the database. If sort_handles is True, the list is sorted by surnames
"""
return self.db.iter_person_handles()
def get_place_handles(self, sort_handles=True):
"""
Return a list of database handles, one handle for each Place still
referenced in the database. If sort_handles is True, the list is
sorted by Place title.
"""
return list(set(self.db.get_place_handles(sort_handles)) -
set(self.unreferenced_places))
def iter_place_handles(self):
"""
Return an iterator over database handles, one handle for each Place still
referenced in the database.
"""
for handle in self.db.iter_place_handles():
if handle not in self.unreferenced_places:
yield handle
def get_source_handles(self, sort_handles=True):
"""
Return a list of database handles, one handle for each Source still
referenced in the database. If sort_handles is True, the list is
sorted by Source title.
"""
return list(set(self.db.get_source_handles(sort_handles)) -
set(self.unreferenced_sources))
def get_media_object_handles(self, sort_handles=True):
"""
Return a list of database handles, one handle for each MediaObject
still referenced in the database. If sort_handles is True, the list
is sorted by title.
"""
return list(set(self.db.get_media_object_handles(sort_handles)) -
set(self.unreferenced_media_objects))
def get_event_handles(self):
"""
Return a list of database handles, one handle for each Event
still referenced in the database.
"""
return list(set(self.db.get_event_handles()) -
set(self.unreferenced_events))
def get_family_handles(self):
"""
Return a list of database handles, one handle for each Family in
the database.
"""
return self.db.get_family_handles()
def iter_family_handles(self):
"""
Return an iterator over database handles, one handle for each Family in
the database..
"""
return self.db.iter_family_handles()
def get_repository_handles(self):
"""
Return a list of database handles, one handle for each Repository still
referenced in the database.
"""
return list(set(self.db.get_repository_handles()) -
set(self.unreferenced_repositories))
def get_note_handles(self):
"""
Return a list of database handles, one handle for each Note still
referenced in the database.
"""
return list(set(self.db.get_note_handles()) -
set(self.unreferenced_notes))
def get_researcher(self):
"""returns the Researcher instance, providing information about
the owner of the database"""
return self.db.get_researcher()
def place_predicate(self, handle):
return handle not in self.unreferenced_places
def object_predicate(self, handle):
return handle not in self.unreferenced_media_objects
def event_predicate(self, handle):
return handle not in self.unreferenced_events
def repository_predicate(self, handle):
return handle not in self.unreferenced_repositories
def note_predicate(self, handle):
return handle not in self.unreferenced_notes
def get_default_person(self):
"""returns the default Person of the database"""
return self.db.get_default_person()