Skip to content

Commit

Permalink
Change the output of ADDR tags in the Gedcom export
Browse files Browse the repository at this point in the history
* Only output the ADDR structure for addresses, not places.
* Remove empty lines from the ADDR structure.
  • Loading branch information
Nick-Hall committed May 14, 2024
1 parent 07e4f4e commit 47245a9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 78 deletions.
33 changes: 1 addition & 32 deletions data/tests/exp_sample_ged.ged
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@
2 TYPE Christening of Amber Marie Smith
2 DATE 26 APR 1998
2 PLAC Community Presbyterian Church, Danville, CA
2 ADDR
3 ADR2 Community Presbyterian Church, Danville, CA
1 FAMC @F0013@
2 PEDI birth
1 CHAN
Expand Down Expand Up @@ -131,8 +129,6 @@
2 TYPE Christening of Mason Michael Smith
2 DATE 10 JUL 1996
2 PLAC Community Presbyterian Church, Danville, CA
2 ADDR
3 ADR2 Community Presbyterian Church, Danville, CA
1 FAMC @F0013@
2 PEDI birth
1 CHAN
Expand Down Expand Up @@ -626,10 +622,6 @@
3 MAP
4 LATI N39.7392
4 LONG W104.9903
2 ADDR
3 CITY Denver, Denver Co., CO
3 STAE Colorado
3 CTRY USA
1 DEAT
2 TYPE Death of Marjorie Ohman
2 DATE 22 JUN 1980
Expand All @@ -648,8 +640,6 @@
2 TYPE Birth of Darcy Horne
2 DATE 2 JUL 1966
2 PLAC Sacramento, Sacramento Co., CA
2 ADDR
3 CITY Sacramento, Sacramento Co., CA
1 FAMS @F0010@
1 CHAN
2 DATE 21 DEC 2007
Expand Down Expand Up @@ -858,12 +848,6 @@
1 BIRT
2 DATE 29 DEC 1954
2 PLAC 123 High St, Cleveland, Cuyahoga, Ohio, USA
2 ADDR 123 High St
3 ADR1 123 High St
3 CITY Cleveland
3 STAE Ohio
3 POST 44140
3 CTRY USA
2 PHON 440-871-3400
2 PHON 800-871-3400
2 EMAIL thetester@@gmail.com
Expand All @@ -884,8 +868,7 @@
1 SOUR @S0005@
1 RESI
2 DATE 27 OCT 2017
2 ADDR
3 CONT test village
2 ADDR test village
3 CONT Akron
3 CONT OH
3 CONT 44177
Expand Down Expand Up @@ -946,10 +929,6 @@
3 MAP
4 LATI N39.7392
4 LONG W104.9903
2 ADDR
3 CITY Denver, Denver Co., CO
3 STAE Colorado
3 CTRY USA
2 PHON 440-871-3402
2 EMAIL tomtester@@gmail.com
2 FAX 440-321-4569
Expand All @@ -965,10 +944,6 @@
3 MAP
4 LATI N39.7392
4 LONG W104.9903
2 ADDR
3 CITY Denver, Denver Co., CO
3 STAE Colorado
3 CTRY USA
1 FAMC @F0016@
2 PEDI birth
1 SOUR @S0005@
Expand Down Expand Up @@ -1023,10 +998,6 @@
3 MAP
4 LATI N39.7392
4 LONG W104.9903
2 ADDR
3 CITY Denver, Denver Co., CO
3 STAE Colorado
3 CTRY USA
2 STAT QUALIFIED
1 FAMC @F0016@
2 _FREL Adopted
Expand Down Expand Up @@ -1278,8 +1249,6 @@
2 DATE 22 FEB 2000
2 TEMP DENVE
2 PLAC Community Presbyterian Church, Danville, CA
2 ADDR
3 ADR2 Community Presbyterian Church, Danville, CA
2 STAT CLEARED
1 MARR
2 HUSB
Expand Down
19 changes: 19 additions & 0 deletions gramps/gen/lib/locationbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,25 @@ def get_text_data_list(self):
self.phone,
]

def get_address_lines(self):
"""
Return a list of non-empty address lines for the Location suitable for
producing a formatted address.
:returns: A list of address lines for the Location.
:rtype: list
"""
addr_lines = [
self.street,
self.locality,
self.city,
self.county,
self.state,
self.postal,
self.country,
]
return [line for line in addr_lines if line]

def set_street(self, val):
"""Set the street portion of the Location."""
self.street = val
Expand Down
51 changes: 5 additions & 46 deletions gramps/plugins/export/exportgedcom.py
Original file line number Diff line number Diff line change
Expand Up @@ -1598,33 +1598,6 @@ def _place(self, place, dateobj, level):
self._writeln(level + 1, "MAP")
self._writeln(level + 2, "LATI", latitude)
self._writeln(level + 2, "LONG", longitude)

# The Gedcom standard shows that an optional address structure can
# be written out in the event detail.
# http://homepages.rootsweb.com/~pmcbride/gedcom/55gcch2.htm#EVENT_DETAIL
location = get_main_location(self.dbase, place)
street = location.get(PlaceType.STREET)
locality = location.get(PlaceType.LOCALITY)
city = location.get(PlaceType.CITY)
state = location.get(PlaceType.STATE)
country = location.get(PlaceType.COUNTRY)
postal_code = place.get_code()

if street or locality or city or state or postal_code or country:
self._writeln(level, "ADDR", street)
if street:
self._writeln(level + 1, "ADR1", street)
if locality:
self._writeln(level + 1, "ADR2", locality)
if city:
self._writeln(level + 1, "CITY", city)
if state:
self._writeln(level + 1, "STAE", state)
if postal_code:
self._writeln(level + 1, "POST", postal_code)
if country:
self._writeln(level + 1, "CTRY", country)

self._note_references(place.get_note_list(), level + 1)

def __write_addr(self, level, addr):
Expand Down Expand Up @@ -1652,25 +1625,11 @@ def __write_addr(self, level, addr):
@param addr: The location or address
@type addr: [a super-type of] LocationBase
"""
if (
addr.get_street()
or addr.get_locality()
or addr.get_city()
or addr.get_state()
or addr.get_postal_code()
or addr.get_country()
):
self._writeln(level, "ADDR", addr.get_street())
if addr.get_locality():
self._writeln(level + 1, "CONT", addr.get_locality())
if addr.get_city():
self._writeln(level + 1, "CONT", addr.get_city())
if addr.get_state():
self._writeln(level + 1, "CONT", addr.get_state())
if addr.get_postal_code():
self._writeln(level + 1, "CONT", addr.get_postal_code())
if addr.get_country():
self._writeln(level + 1, "CONT", addr.get_country())
addr_lines = addr.get_address_lines()
if addr_lines:
self._writeln(level, "ADDR", addr_lines[0])
for line in addr_lines[1:]:
self._writeln(level + 1, "CONT", line)

if addr.get_street():
self._writeln(level + 1, "ADR1", addr.get_street())
Expand Down

0 comments on commit 47245a9

Please sign in to comment.