GEPS 006: Add Locality field to Location
svn: r16063
This commit is contained in:
@@ -82,6 +82,7 @@ def gramps_upgrade_15(self):
|
||||
tags = [tag_handle]
|
||||
else:
|
||||
tags = []
|
||||
address_list = [convert_address(addr) for addr in address_list]
|
||||
new_primary_name = convert_name_15(primary_name)
|
||||
new_alternate_names = [convert_name_15(altname) for altname in
|
||||
alternate_names]
|
||||
@@ -186,6 +187,8 @@ def gramps_upgrade_15(self):
|
||||
for handle in self.place_map.keys():
|
||||
place = self.place_map[handle]
|
||||
new_place = list(place)
|
||||
new_place[5] = convert_location(new_place[5])
|
||||
new_place[6] = [convert_location(loc) for loc in new_place[6]]
|
||||
new_place = new_place[:11] + new_place[12:]
|
||||
new_place = tuple(new_place)
|
||||
with BSDDBTxn(self.env, self.place_map) as txn:
|
||||
@@ -243,6 +246,18 @@ def convert_marker(self, marker_field):
|
||||
else:
|
||||
return None
|
||||
|
||||
def convert_locbase(loc):
|
||||
"""Convert location base to include an empty locality field."""
|
||||
return tuple([loc[0], u''] + list(loc[1:]))
|
||||
|
||||
def convert_location(loc):
|
||||
"""Convert a location into the new format."""
|
||||
return (convert_locbase(loc[0]), loc[1])
|
||||
|
||||
def convert_address(addr):
|
||||
"""Convert an address into the new format."""
|
||||
return (addr[0], addr[1], addr[2], addr[3], convert_locbase(addr[4]))
|
||||
|
||||
def convert_name_15(name):
|
||||
(privacy, source_list, note_list, date,
|
||||
first_name, surname, suffix, title,
|
||||
|
||||
@@ -528,6 +528,8 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback):
|
||||
try:
|
||||
owner_data = self.metadata.get('researcher')
|
||||
if owner_data:
|
||||
if len(owner_data[0]) == 7: # Pre-3.3 format
|
||||
owner_data = upgrade_researcher(owner_data)
|
||||
self.owner.unserialize(owner_data)
|
||||
except ImportError: #handle problems with pre-alpha 3.0
|
||||
pass
|
||||
@@ -1837,6 +1839,14 @@ def write_lock_file(name):
|
||||
f.write(text)
|
||||
f.close()
|
||||
|
||||
def upgrade_researcher(owner_data):
|
||||
"""
|
||||
Upgrade researcher data to include a locality field in the address.
|
||||
This should be called for databases prior to Gramps 3.3.
|
||||
"""
|
||||
addr = tuple([owner_data[0][0], ''] + list(owner_data[0][1:]))
|
||||
return (addr, owner_data[1], owner_data[2], owner_data[3])
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
import os, sys, pdb
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2000-2006 Donald N. Allingham
|
||||
# Copyright (C) 2010 Nick Hall
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -41,6 +42,7 @@ class LocationBase(object):
|
||||
"""
|
||||
if source:
|
||||
self.street = source.street
|
||||
self.locality = source.locality
|
||||
self.city = source.city
|
||||
self.county = source.county
|
||||
self.state = source.state
|
||||
@@ -49,6 +51,7 @@ class LocationBase(object):
|
||||
self.phone = source.phone
|
||||
else:
|
||||
self.street = ""
|
||||
self.locality = ""
|
||||
self.city = ""
|
||||
self.county = ""
|
||||
self.state = ""
|
||||
@@ -60,15 +63,15 @@ class LocationBase(object):
|
||||
"""
|
||||
Convert the object to a serialized tuple of data.
|
||||
"""
|
||||
return (self.street, self.city, self.county, self.state,
|
||||
return (self.street, self.locality, self.city, self.county, self.state,
|
||||
self.country, self.postal, self.phone)
|
||||
|
||||
def unserialize(self, data):
|
||||
"""
|
||||
Convert a serialized tuple of data to an object.
|
||||
"""
|
||||
(self.street, self.city, self.county, self.state, self.country,
|
||||
self.postal, self.phone) = data
|
||||
(self.street, self.locality, self.city, self.county, self.state,
|
||||
self.country, self.postal, self.phone) = data
|
||||
return self
|
||||
|
||||
def get_text_data_list(self):
|
||||
@@ -88,6 +91,14 @@ class LocationBase(object):
|
||||
"""Return the street portion of the Location."""
|
||||
return self.street
|
||||
|
||||
def set_locality(self, val):
|
||||
"""Set the locality portion of the Location."""
|
||||
self.locality = val
|
||||
|
||||
def get_locality(self):
|
||||
"""Return the locality portion of the Location."""
|
||||
return self.locality
|
||||
|
||||
def set_city(self, data):
|
||||
"""Set the city name of the LocationBase object."""
|
||||
self.city = data
|
||||
|
||||
@@ -218,6 +218,7 @@ def get_address_str(addr):
|
||||
"""
|
||||
str = ""
|
||||
elems = [ addr.get_street(),
|
||||
addr.get_locality(),
|
||||
addr.get_city(),
|
||||
addr.get_county(),
|
||||
addr.get_state(),
|
||||
|
||||
@@ -611,12 +611,13 @@ def sanitize_address(db, address):
|
||||
new_address = Address()
|
||||
|
||||
new_address.set_street(address.get_street())
|
||||
new_address.set_locality(address.get_locality())
|
||||
new_address.set_city(address.get_city())
|
||||
new_address.set_postal_code(address.get_postal_code())
|
||||
new_address.set_phone(address.get_phone())
|
||||
new_address.set_county(address.get_county())
|
||||
new_address.set_state(address.get_state())
|
||||
new_address.set_country(address.get_country())
|
||||
new_address.set_county(address.get_county())
|
||||
new_address.set_postal_code(address.get_postal_code())
|
||||
new_address.set_phone(address.get_phone())
|
||||
|
||||
new_address.set_date_object(address.get_date_object())
|
||||
copy_source_ref_list(db, address, new_address)
|
||||
|
||||
Reference in New Issue
Block a user