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
# 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)
for (class_name, handle) in handle_itr:
if class_name == 'Person':
obj = self.db.get_person_from_handle(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 class_name in objects:
obj = objects[class_name](handle)
if obj and not obj.get_privacy():
yield (class_name, handle)
else:
raise NotImplementedError
return
def copy_media_ref_list(db, original_obj, clean_obj):
"""
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
until there are no more objects to unreference.
"""
object_types = {
'Event': {'unref_list': self.unreferenced_events,
'handle_list': self.get_event_handles},
'Place': {'unref_list': self.unreferenced_places,
'handle_list': self.get_place_handles},
'Source': {'unref_list': self.unreferenced_sources,
'handle_list': self.get_source_handles},
'Repositories': {'unref_list': self.unreferenced_repositories,
'handle_list': self.get_repository_handles},
'MediaObjects': {'unref_list': self.unreferenced_media_objects,
'handle_list': self.get_media_object_handles},
'Notes': {'unref_list': self.unreferenced_notes,
'handle_list': self.get_note_handles}
}
unrefs = (
(self.unreferenced_events, self.get_event_handles),
(self.unreferenced_places, self.get_place_handles),
(self.unreferenced_sources, self.get_source_handles),
(self.unreferenced_repositories,
self.get_repository_handles),
(self.unreferenced_media_objects,
self.get_media_object_handles),
(self.unreferenced_notes, self.get_note_handles),
)
last_count = 0
while True:
current_count = 0
for object_type, object_dict in object_types.iteritems():
unref_list = object_dict['unref_list']
handle_list = object_dict['handle_list']()
for (unref_list, handle_list) in unrefs:
unref_list.update(
handle for handle in handle_list
handle for handle in handle_list()
if not any(self.find_backlink_handles(handle)))
current_count += len(unref_list)