Set place type to "Unknown" when main location is missing
svn: r23448
This commit is contained in:
parent
da7d62c65f
commit
31a3f074f1
@ -108,12 +108,12 @@ def gramps_upgrade_17(self):
|
|||||||
|
|
||||||
# find title and type
|
# find title and type
|
||||||
main_loc = get_location(new_place[5])
|
main_loc = get_location(new_place[5])
|
||||||
for type_num, name in enumerate(main_loc):
|
for level, name in enumerate(main_loc):
|
||||||
if name:
|
if name:
|
||||||
break
|
break
|
||||||
|
|
||||||
loc = list(main_loc[:])
|
loc = list(main_loc[:])
|
||||||
loc[type_num] = ''
|
loc[level] = ''
|
||||||
|
|
||||||
# find top parent
|
# find top parent
|
||||||
parent_handle = None
|
parent_handle = None
|
||||||
@ -127,7 +127,7 @@ def gramps_upgrade_17(self):
|
|||||||
# create nodes
|
# create nodes
|
||||||
if parent_handle:
|
if parent_handle:
|
||||||
n -= 1
|
n -= 1
|
||||||
while n > type_num:
|
while n > level:
|
||||||
if loc[n]:
|
if loc[n]:
|
||||||
title = ', '.join([item for item in loc[n:] if item])
|
title = ', '.join([item for item in loc[n:] if item])
|
||||||
parent_handle = add_place(self, loc[n], n, parent_handle, title)
|
parent_handle = add_place(self, loc[n], n, parent_handle, title)
|
||||||
@ -141,8 +141,9 @@ def gramps_upgrade_17(self):
|
|||||||
else:
|
else:
|
||||||
placeref_list = []
|
placeref_list = []
|
||||||
|
|
||||||
|
type_num = 7 - level if name else 8
|
||||||
new_place = new_place[:5] + [placeref_list, name,
|
new_place = new_place[:5] + [placeref_list, name,
|
||||||
PlaceType(7-type_num).serialize(), zip_code] + \
|
PlaceType(type_num).serialize(), zip_code] + \
|
||||||
new_place[6:12] + [[]] + new_place[12:]
|
new_place[6:12] + [[]] + new_place[12:]
|
||||||
new_place = tuple(new_place)
|
new_place = tuple(new_place)
|
||||||
with BSDDBTxn(self.env, self.place_map) as txn:
|
with BSDDBTxn(self.env, self.place_map) as txn:
|
||||||
@ -260,15 +261,15 @@ def get_location(loc):
|
|||||||
location = loc[0][:2] + (loc[1],) + loc[0][2:6]
|
location = loc[0][:2] + (loc[1],) + loc[0][2:6]
|
||||||
return location
|
return location
|
||||||
|
|
||||||
def add_place(self, name, type_num, parent, title):
|
def add_place(self, name, level, parent, title):
|
||||||
handle = self.create_id()
|
handle = self.create_id()
|
||||||
place = Place()
|
place = Place()
|
||||||
place.handle = handle
|
place.handle = handle
|
||||||
self.max_id += 1
|
self.max_id += 1
|
||||||
place.gramps_id = self.place_prefix % self.max_id
|
place.gramps_id = self.place_prefix % self.max_id
|
||||||
place.name = name
|
place.set_name(name)
|
||||||
place.title = title
|
place.set_title(title)
|
||||||
place.place_type = PlaceType(7-type_num)
|
place.set_type(PlaceType(7-level))
|
||||||
if parent is not None:
|
if parent is not None:
|
||||||
placeref = PlaceRef()
|
placeref = PlaceRef()
|
||||||
placeref.ref = parent
|
placeref.ref = parent
|
||||||
|
@ -1185,12 +1185,13 @@ class GrampsParser(UpdateCallback):
|
|||||||
attrs.get('country', ''))
|
attrs.get('country', ''))
|
||||||
self.place_import.store_location(location, self.placeobj.handle)
|
self.place_import.store_location(location, self.placeobj.handle)
|
||||||
|
|
||||||
for type_num, name in enumerate(location):
|
for level, name in enumerate(location):
|
||||||
if name:
|
if name:
|
||||||
break
|
break
|
||||||
|
|
||||||
self.placeobj.set_name(name)
|
self.placeobj.set_name(name)
|
||||||
self.placeobj.set_type(PlaceType(7-type_num))
|
type_num = 7 - level if name else 8
|
||||||
|
self.placeobj.set_type(PlaceType(type_num))
|
||||||
codes = [attrs.get('postal'), attrs.get('phone')]
|
codes = [attrs.get('postal'), attrs.get('phone')]
|
||||||
self.placeobj.set_code(' '.join(code for code in codes if code))
|
self.placeobj.set_code(' '.join(code for code in codes if code))
|
||||||
else:
|
else:
|
||||||
|
@ -1688,12 +1688,13 @@ class PlaceParser(object):
|
|||||||
|
|
||||||
place_import.store_location(location, place.handle)
|
place_import.store_location(location, place.handle)
|
||||||
|
|
||||||
for type_num, name in enumerate(location):
|
for level, name in enumerate(location):
|
||||||
if name:
|
if name:
|
||||||
break
|
break
|
||||||
|
|
||||||
place.set_name(name)
|
place.set_name(name)
|
||||||
place.set_type(PlaceType(7-type_num))
|
type_num = 7 - level if name else 8
|
||||||
|
place.set_type(PlaceType(type_num))
|
||||||
code = loc.get_postal_code()
|
code = loc.get_postal_code()
|
||||||
place.set_code(code)
|
place.set_code(code)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user