From 181c0c9b41adb36c4d67cb7797f4e2e430dd3b7f Mon Sep 17 00:00:00 2001 From: Gerald Britton Date: Wed, 8 Jul 2009 18:11:02 +0000 Subject: [PATCH] Replace get_place_handles with iter_place_handles svn: r12778 --- src/DataViews/GeoView.py | 2 +- src/FilterEditor/_FilterEditor.py | 2 +- src/Merge/_MergeSource.py | 2 +- src/gen/proxy/filter.py | 7 +++++++ src/gen/proxy/living.py | 14 +++++++++++--- src/gen/proxy/private.py | 10 ++++++++++ src/gen/proxy/referenced.py | 9 +++++++++ src/plugins/gramplet/DataEntryGramplet.py | 2 +- src/plugins/import/ImportCsv.py | 4 ++-- src/plugins/textreport/PlaceReport.py | 2 +- src/plugins/tool/ExtractCity.py | 4 ++-- 11 files changed, 46 insertions(+), 12 deletions(-) diff --git a/src/DataViews/GeoView.py b/src/DataViews/GeoView.py index a449cd51a..de1759f14 100644 --- a/src/DataViews/GeoView.py +++ b/src/DataViews/GeoView.py @@ -1515,7 +1515,7 @@ class GeoView(HtmlView): latitude = "" longitude = "" self.center = True - for place_handle in dbstate.db.get_place_handles(): + for place_handle in dbstate.iter.get_place_handles(): place = dbstate.db.get_place_from_handle( place_handle) if place: descr = place.get_title() diff --git a/src/FilterEditor/_FilterEditor.py b/src/FilterEditor/_FilterEditor.py index ceb8e74e7..8276dece1 100644 --- a/src/FilterEditor/_FilterEditor.py +++ b/src/FilterEditor/_FilterEditor.py @@ -244,7 +244,7 @@ class FilterEditor(ManagedWindow.ManagedWindow): elif self.namespace == 'Source': return self.db.get_source_handles() elif self.namespace == 'Place': - return self.db.get_place_handles() + return self.db.iter_place_handles() elif self.namespace == 'MediaObject': return self.db.get_media_object_handles() elif self.namespace == 'Repository': diff --git a/src/Merge/_MergeSource.py b/src/Merge/_MergeSource.py index 662f72198..9ba65e81d 100644 --- a/src/Merge/_MergeSource.py +++ b/src/Merge/_MergeSource.py @@ -197,7 +197,7 @@ class MergeSources(ManagedWindow.ManagedWindow): self.db.commit_source(source,trans) # places - for handle in self.db.get_place_handles(): + for handle in self.iter.get_place_handles(): place = self.db.get_place_from_handle(handle) if place.has_source_reference(self.old_handle): place.replace_source_references(self.old_handle, diff --git a/src/gen/proxy/filter.py b/src/gen/proxy/filter.py index 7710c927f..acfbdbb80 100644 --- a/src/gen/proxy/filter.py +++ b/src/gen/proxy/filter.py @@ -297,6 +297,13 @@ class FilterProxyDb(ProxyDbBase): """ 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 diff --git a/src/gen/proxy/living.py b/src/gen/proxy/living.py index f7eaf9fd7..e67518a62 100644 --- a/src/gen/proxy/living.py +++ b/src/gen/proxy/living.py @@ -235,10 +235,11 @@ class LivingProxyDb(ProxyDbBase): if self.mode == self.MODE_EXCLUDE_ALL: for handle in self.db.iter_person_handles(): person = self.db.get_person_from_handle(handle) - if not self.__is_living(person): + if self.mode == self.MODE_EXCLUDE_ALL: + if not self.__is_living(person): + yield handle + else: yield handle - else: - return self.db.iter_person_handles() def get_place_handles(self, sort_handles=True): """ @@ -248,6 +249,13 @@ class LivingProxyDb(ProxyDbBase): """ 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 diff --git a/src/gen/proxy/private.py b/src/gen/proxy/private.py index 90e52d580..65ce8837b 100644 --- a/src/gen/proxy/private.py +++ b/src/gen/proxy/private.py @@ -241,6 +241,16 @@ class PrivateProxyDb(ProxyDbBase): handles.append(handle) return handles + def iter_place_handles(self): + """ + Return an iterator over database handles, one handle for each Place in + the database. + """ + 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): """ Return a list of database handles, one handle for each Source in diff --git a/src/gen/proxy/referenced.py b/src/gen/proxy/referenced.py index 505afe81a..50ce651b8 100644 --- a/src/gen/proxy/referenced.py +++ b/src/gen/proxy/referenced.py @@ -188,6 +188,15 @@ class ReferencedProxyDb(ProxyDbBase): 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 diff --git a/src/plugins/gramplet/DataEntryGramplet.py b/src/plugins/gramplet/DataEntryGramplet.py index cc7c21c63..d1639d2f3 100644 --- a/src/plugins/gramplet/DataEntryGramplet.py +++ b/src/plugins/gramplet/DataEntryGramplet.py @@ -282,7 +282,7 @@ class DataEntryGramplet(Gramplet): def get_or_create_place(self, place_name): if place_name == "": return (-1, None) - place_list = self.dbstate.db.get_place_handles() + place_list = self.dbstate.iter.get_place_handles() for place_handle in place_list: place = self.dbstate.db.get_place_from_handle(place_handle) if place.get_title().strip() == place_name: diff --git a/src/plugins/import/ImportCsv.py b/src/plugins/import/ImportCsv.py index 74d4399b3..48c599fe0 100644 --- a/src/plugins/import/ImportCsv.py +++ b/src/plugins/import/ImportCsv.py @@ -808,8 +808,8 @@ class CSVParser(object): return person def get_or_create_place(self,place_name): - place_list = self.db.get_place_handles() - if self.debug: print "get_or_create_place: list:", place_list + place_list = self.db.iter_place_handles() + if self.debug: print "get_or_create_place: list:", list(place_list) if self.debug: print "get_or_create_place: looking for:", place_name for place_handle in place_list: place = self.db.get_place_from_handle(place_handle) diff --git a/src/plugins/textreport/PlaceReport.py b/src/plugins/textreport/PlaceReport.py index 94cf3531e..7c7186361 100644 --- a/src/plugins/textreport/PlaceReport.py +++ b/src/plugins/textreport/PlaceReport.py @@ -75,7 +75,7 @@ class PlaceReport(Report): if self.filter.get_name() != '': # Use the selected filter to provide a list of place handles - plist = self.database.get_place_handles(sort_handles=False) + plist = self.database.iter_place_handles() self.place_handles = self.filter.apply(self.database, plist) else: # Use the place handles selected without a filter diff --git a/src/plugins/tool/ExtractCity.py b/src/plugins/tool/ExtractCity.py index 0e3a278b4..c1dc0dadc 100644 --- a/src/plugins/tool/ExtractCity.py +++ b/src/plugins/tool/ExtractCity.py @@ -430,11 +430,11 @@ class ExtractCity(Tool.BatchTool, ManagedWindow.ManagedWindow): self.progress = ProgressMeter(_('Checking Place Titles'), '') self.progress.set_pass(_('Looking for place fields'), - len(self.db.get_place_handles())) + self.db.get_number_of_places()) self.name_list = [] - for handle in db.get_place_handles(): + for handle in db.iter_place_handles(): place = db.get_place_from_handle(handle) descr = place.get_title() loc = place.get_main_location()