Tweaks and simplifications

svn: r14001
This commit is contained in:
Gerald Britton 2010-01-08 21:47:02 +00:00
parent 16808b6c0e
commit afe85ad0d5
2 changed files with 29 additions and 39 deletions

View File

@ -384,32 +384,27 @@ class PrivateProxyDb(ProxyDbBase):
# private (like a SourceRef or MediaRef). It only checks if the # private (like a SourceRef or MediaRef). It only checks if the
# referenced object is private. # referenced object is private.
objects = {
'Person' : self.db.get_person_from_handle,
'Family' : self.db.get_family_from_handle,
'Event' : self.db.get_event_from_handle,
'Source' : self.db.get_source_from_handle,
'Place' : self.db.get_place_from_handle,
'MediaObject' : self.db.get_object_from_handle,
'Note' : self.db.get_note_from_handle,
'Repository' : self.db.get_repository_from_handle,
}
handle_itr = self.db.find_backlink_handles(handle, include_classes) handle_itr = self.db.find_backlink_handles(handle, include_classes)
for (class_name, handle) in handle_itr: for (class_name, handle) in handle_itr:
if class_name == 'Person': if class_name in objects:
obj = self.db.get_person_from_handle(handle) obj = objects[class_name](handle)
elif class_name == 'Family':
obj = self.db.get_family_from_handle(handle)
elif class_name == 'Event':
obj = self.db.get_event_from_handle(handle)
elif class_name == 'Source':
obj = self.db.get_source_from_handle(handle)
elif class_name == 'Place':
obj = self.db.get_place_from_handle(handle)
elif class_name == 'MediaObject':
obj = self.db.get_object_from_handle(handle)
elif class_name == 'Note':
obj = self.db.get_note_from_handle(handle)
elif class_name == 'Repository':
obj = self.db.get_repository_from_handle(handle)
else:
raise NotImplementedError
if obj and not obj.get_privacy(): if obj and not obj.get_privacy():
yield (class_name, handle) yield (class_name, handle)
else:
raise NotImplementedError
return return
def copy_media_ref_list(db, original_obj, clean_obj): def copy_media_ref_list(db, original_obj, clean_obj):
""" """
Copies media references from one object to another - excluding private Copies media references from one object to another - excluding private

View File

@ -145,29 +145,24 @@ class ReferencedProxyDb(ProxyDbBase):
effectively become unreferenced, so the action is performed in a loop effectively become unreferenced, so the action is performed in a loop
until there are no more objects to unreference. until there are no more objects to unreference.
""" """
object_types = {
'Event': {'unref_list': self.unreferenced_events, unrefs = (
'handle_list': self.get_event_handles}, (self.unreferenced_events, self.get_event_handles),
'Place': {'unref_list': self.unreferenced_places, (self.unreferenced_places, self.get_place_handles),
'handle_list': self.get_place_handles}, (self.unreferenced_sources, self.get_source_handles),
'Source': {'unref_list': self.unreferenced_sources, (self.unreferenced_repositories,
'handle_list': self.get_source_handles}, self.get_repository_handles),
'Repositories': {'unref_list': self.unreferenced_repositories, (self.unreferenced_media_objects,
'handle_list': self.get_repository_handles}, self.get_media_object_handles),
'MediaObjects': {'unref_list': self.unreferenced_media_objects, (self.unreferenced_notes, self.get_note_handles),
'handle_list': self.get_media_object_handles}, )
'Notes': {'unref_list': self.unreferenced_notes,
'handle_list': self.get_note_handles}
}
last_count = 0 last_count = 0
while True: while True:
current_count = 0 current_count = 0
for object_type, object_dict in object_types.iteritems(): for (unref_list, handle_list) in unrefs:
unref_list = object_dict['unref_list']
handle_list = object_dict['handle_list']()
unref_list.update( unref_list.update(
handle for handle in handle_list handle for handle in handle_list()
if not any(self.find_backlink_handles(handle))) if not any(self.find_backlink_handles(handle)))
current_count += len(unref_list) current_count += len(unref_list)