Update Extract City tool to create a place hierarchy

svn: r23447
This commit is contained in:
Nick Hall 2013-11-02 18:14:44 +00:00
parent ec76905791
commit da7d62c65f

View File

@ -51,6 +51,9 @@ from gi.repository import GObject
from gramps.gen.db import DbTxn from gramps.gen.db import DbTxn
from gramps.gui.managedwindow import ManagedWindow from gramps.gui.managedwindow import ManagedWindow
from gramps.gui.display import display_help from gramps.gui.display import display_help
from gramps.plugins.lib.libplaceimport import PlaceImport
from gramps.gen.utils.location import get_main_location
from gramps.gen.lib import PlaceType
from gramps.gui.plug import tool from gramps.gui.plug import tool
from gramps.gui.utils import ProgressMeter from gramps.gui.utils import ProgressMeter
@ -437,14 +440,23 @@ class ExtractCity(tool.BatchTool, ManagedWindow):
self.db.get_number_of_places()) self.db.get_number_of_places())
self.name_list = [] self.name_list = []
self.place_import = PlaceImport(db)
for place in db.iter_places(): for place in db.iter_places():
descr = place.get_title() descr = place.get_title()
loc = place.get_main_location()
self.progress.step() self.progress.step()
if loc.get_street() == loc.get_city() == \ loc = get_main_location(db, place)
loc.get_state() == loc.get_postal_code() == "": location = ((loc.get(PlaceType.STREET, '')),
(loc.get(PlaceType.LOCALITY, '')),
(loc.get(PlaceType.PARISH, '')),
(loc.get(PlaceType.CITY, '')),
(loc.get(PlaceType.COUNTY, '')),
(loc.get(PlaceType.STATE, '')),
(loc.get(PlaceType.COUNTRY, '')))
self.place_import.store_location(location, place.handle)
if len(place.get_placeref_list()) == 0:
match = CITY_STATE_ZIP.match(descr.strip()) match = CITY_STATE_ZIP.match(descr.strip())
if match: if match:
@ -603,18 +615,16 @@ class ExtractCity(tool.BatchTool, ManagedWindow):
for change in changelist: for change in changelist:
row = self.model[change] row = self.model[change]
place = self.db.get_place_from_handle(row[6]) place = self.db.get_place_from_handle(row[6])
(city, state, postal, country) = (row[2], row[3], row[4], row[5]) location = ('', '', '', row[2], '', row[3], row[5])
self.place_import.store_location(location, place.handle)
if city: place.set_name(row[2])
place.get_main_location().set_city(city) place.set_type(PlaceType.CITY)
if state: if row[4]:
place.get_main_location().set_state(state) place.set_code(row[4])
if postal:
place.get_main_location().set_postal_code(postal)
if country:
place.get_main_location().set_country(country)
self.db.commit_place(place, self.trans) self.db.commit_place(place, self.trans)
self.place_import.generate_hierarchy(self.trans)
self.db.enable_signals() self.db.enable_signals()
self.db.request_rebuild() self.db.request_rebuild()
self.close() self.close()