From 31a3f074f1c933232865eb6b2286b015a541a07f Mon Sep 17 00:00:00 2001 From: Nick Hall Date: Sat, 2 Nov 2013 18:19:32 +0000 Subject: [PATCH] Set place type to "Unknown" when main location is missing svn: r23448 --- gramps/gen/db/upgrade.py | 17 +++++++++-------- gramps/plugins/importer/importxml.py | 5 +++-- gramps/plugins/lib/libgedcom.py | 5 +++-- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/gramps/gen/db/upgrade.py b/gramps/gen/db/upgrade.py index 130457048..7694344bf 100644 --- a/gramps/gen/db/upgrade.py +++ b/gramps/gen/db/upgrade.py @@ -108,12 +108,12 @@ def gramps_upgrade_17(self): # find title and type main_loc = get_location(new_place[5]) - for type_num, name in enumerate(main_loc): + for level, name in enumerate(main_loc): if name: break loc = list(main_loc[:]) - loc[type_num] = '' + loc[level] = '' # find top parent parent_handle = None @@ -127,7 +127,7 @@ def gramps_upgrade_17(self): # create nodes if parent_handle: n -= 1 - while n > type_num: + while n > level: if loc[n]: title = ', '.join([item for item in loc[n:] if item]) parent_handle = add_place(self, loc[n], n, parent_handle, title) @@ -141,8 +141,9 @@ def gramps_upgrade_17(self): else: placeref_list = [] + type_num = 7 - level if name else 8 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 = tuple(new_place) 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] return location -def add_place(self, name, type_num, parent, title): +def add_place(self, name, level, parent, title): handle = self.create_id() place = Place() place.handle = handle self.max_id += 1 place.gramps_id = self.place_prefix % self.max_id - place.name = name - place.title = title - place.place_type = PlaceType(7-type_num) + place.set_name(name) + place.set_title(title) + place.set_type(PlaceType(7-level)) if parent is not None: placeref = PlaceRef() placeref.ref = parent diff --git a/gramps/plugins/importer/importxml.py b/gramps/plugins/importer/importxml.py index 12a8f8a9e..dba82ed9f 100644 --- a/gramps/plugins/importer/importxml.py +++ b/gramps/plugins/importer/importxml.py @@ -1185,12 +1185,13 @@ class GrampsParser(UpdateCallback): attrs.get('country', '')) self.place_import.store_location(location, self.placeobj.handle) - for type_num, name in enumerate(location): + for level, name in enumerate(location): if name: break 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')] self.placeobj.set_code(' '.join(code for code in codes if code)) else: diff --git a/gramps/plugins/lib/libgedcom.py b/gramps/plugins/lib/libgedcom.py index 0d1c6ca15..92f94e727 100644 --- a/gramps/plugins/lib/libgedcom.py +++ b/gramps/plugins/lib/libgedcom.py @@ -1688,12 +1688,13 @@ class PlaceParser(object): place_import.store_location(location, place.handle) - for type_num, name in enumerate(location): + for level, name in enumerate(location): if name: break 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() place.set_code(code)