From d524bdd512d77be813065aa01df4937ef7926e0f Mon Sep 17 00:00:00 2001 From: prculley Date: Thu, 30 Jun 2016 09:44:47 -0500 Subject: [PATCH] bug 9501 CSV import/export messes up places --- data/tests/imp_sample_csv.csv | 123 +++ data/tests/imp_sample_csv.gramps | 1111 ++++++++++++++++++++++++++ gramps/plugins/export/exportcsv.py | 75 +- gramps/plugins/importer/importcsv.py | 5 +- 4 files changed, 1276 insertions(+), 38 deletions(-) create mode 100644 data/tests/imp_sample_csv.csv create mode 100644 data/tests/imp_sample_csv.gramps diff --git a/data/tests/imp_sample_csv.csv b/data/tests/imp_sample_csv.csv new file mode 100644 index 000000000..b58709cea --- /dev/null +++ b/data/tests/imp_sample_csv.csv @@ -0,0 +1,123 @@ +Place,Title,Name,Type,Latitude,Longitude,Code,Enclosed_by,Date +[P0000],"Löderup, Malmöhus Län, Sweden","Löderup, Malmöhus Län, Sweden",Unknown,,,,, +[P0001],"Sparks, Washoe Co., NV","Sparks, Washoe Co., NV",Unknown,,,,, +[P0002],"San Francisco, San Francisco Co., CA","San Francisco, San Francisco Co., CA",Unknown,,,,, +[P0003],"Rønne, Bornholm, Denmark","Rønne, Bornholm, Denmark",Unknown,,,,, +[P0004],"Gladsax, Kristianstad Län, Sweden","Gladsax, Kristianstad Län, Sweden",Unknown,,,,, +[P0005],"Reno, Washoe Co., NV","Reno, Washoe Co., NV",Unknown,,,,, +[P0006],"Hayward, Alameda Co., CA","Hayward, Alameda Co., CA",Unknown,,,,, +[P0007],"Community Presbyterian Church, Danville, CA","Community Presbyterian Church, Danville, CA",Unknown,,,,, +[P0008],Sweden,Sweden,Unknown,,,,, +[P0009],"Grostorp, Kristianstad Län, Sweden","Grostorp, Kristianstad Län, Sweden",Unknown,,,,, +[P0010],"Copenhagen, Denmark","Copenhagen, Denmark",Unknown,,,,, +[P0011],"Hoya/Jona/Hoia, Sweden","Hoya/Jona/Hoia, Sweden",Unknown,,,,, +[P0012],"Simrishamn, Kristianstad Län, Sweden","Simrishamn, Kristianstad Län, Sweden",Unknown,,,,, +[P0013],"Fremont, Alameda Co., CA","Fremont, Alameda Co., CA",Unknown,,,,, +[P0016],"Santa Rosa, Sonoma Co., CA","Santa Rosa, Sonoma Co., CA",Unknown,,,,, +[P0017],"San Jose, Santa Clara Co., CA","San Jose, Santa Clara Co., CA",Unknown,,,,, +[P0018],UC Berkeley,UC Berkeley,Unknown,,,,, +[P0019],"Smestorp, Kristianstad Län, Sweden","Smestorp, Kristianstad Län, Sweden",Unknown,,,,, +[P0020],"Tommarp, Kristianstad Län, Sweden","Tommarp, Kristianstad Län, Sweden",Unknown,,,,, +[P0021],"Rønne Bornholm, Denmark","Rønne Bornholm, Denmark",Unknown,,,,, +[P0022],"Woodland, Yolo Co., CA","Woodland, Yolo Co., CA",Unknown,,,,, +[P0023],"San Ramon, Conta Costa Co., CA","San Ramon, Conta Costa Co., CA",Unknown,,,,, +[P0026],United States of America,USA,Country,,,,, +[P0028],"California, USA",California,State,,,,[P0026],2016-06-04 +[P0025],"Colorado, USA",Colorado,State,,,,[P0026], +[P0027],"Sacramento Co., California, USA",Sacramento Co.,County,,,,[P0028],2016-06-01 +[P0015],"Sacramento, Sacramento Co., CA","Sacramento, Sacramento Co., CA",City,,,,[P0027],2016-06-04 +[P0024],"Denver Co., Colorado, USA",Denver Co.,County,,,,[P0025], +[P0014],"Denver, Denver Co., CO","Denver, Denver Co., CO",City,39.7392,104.9903 W,,[P0024], + +Person,Surname,Given,Call,Suffix,Prefix,Title,Gender,Birth date,Birth place,Birth source,Baptism date,Baptism place,Baptism source,Death date,Death place,Death source,Burial date,Burial place,Burial source,Note +[I0030],Adams,Janice Ann,,,,,female,26 Aug 1965,"Fremont, Alameda Co., CA",,,,,,,,,,, +[I0016],Anderson,Jennifer,,,,,female,5 Nov 1907,"Rønne, Bornholm, Denmark",,,,,29 May 1985,"San Francisco, San Francisco Co., CA",,,,, +[I0025],Ericsdotter,Marta,,,,,female,about 1775,Sweden,,,,,,,,,,, +[I0041],Green,Janis Elaine,,,,,female,2 Dec 1935,,,,,,,,,,,, +[I0000],Hansdotter,Anna,,,,,female,2 Oct 1864,"Löderup, Malmöhus Län, Sweden",,,,,29 Sep 1945,"Sparks, Washoe Co., NV",,,,, +[I0038],Hansdotter,Kerstina,,,,,female,29 Nov 1832,"Smestorp, Kristianstad Län, Sweden",,,,,before 1908,Sweden,,,,, +[I0032],Horne,Darcy,,,,,female,2 Jul 1966,"Sacramento, Sacramento Co., CA",,,,,,,,,,, +[I0036],Jefferson,Elna,,,,,female,14 Sep 1800,"Gladsax, Kristianstad Län, Sweden",,,,,,Sweden,,,,, +[I0017],Jones,Lillie Harriet,,,,,female,2 May 1910,"Rønne, Bornholm, Denmark",,,,,26 Jun 1990,,,,,, +[I0042],Ke 柯,雪,,,,,male,,,,,,,,,,,,, +[I0013],Michaels,Evelyn,,,,,female,about 1897,,,,,,,,,,,, +[I0012],Nielsen,Herman Julius,,,,,male,31 Aug 1889,"Rønne, Bornholm, Denmark",,,,,1945,,,,,, +[I0031],Ohman,Marjorie,,,,,female,3 Jun 1903,"Denver, Denver Co., CO, Denver Co., Colorado, USA",,,,,22 Jun 1980,"Reno, Washoe Co., NV",,,,, +[I0034],Perkins,Alice Paula,,,,,female,22 Nov 1933,"Sparks, Washoe Co., NV",,,,,,,,,,, +[I0002],Smith,Amber Marie,,,,,female,12 Apr 1998,"Hayward, Alameda Co., CA",,,,,,,,,,, +[I0023],Smith,Astrid Shermanna Augusta,,,,,female,31 Jan 1889,"Rønne, Bornholm, Denmark",,,,,21 Dec 1963,"San Francisco, San Francisco Co., CA",,,,, +[I0020],Smith,Carl Emil,,,,,male,20 Dec 1899,"Rønne, Bornholm, Denmark",,,,,28 Jan 1959,"Reno, Washoe Co., NV",,,,, +[I0029],Smith,Craig Peter,,,,,male,after 1966,"San Francisco, San Francisco Co., CA",,,,,,,,,,, +[I0037],Smith,Edwin Michael,,,,,male,24 May 1961,"San Jose, Santa Clara Co., CA","Birth, Death and Marriage Records",,,,,,,,,, +[I0009],Smith,Emil,,,,,male,27 Sep 1860,"Simrishamn, Kristianstad Län, Sweden",,,,,,,,,,, +[I0019],Smith,Eric Lloyd,,,,Dr.,male,28 Aug 1963,"San Francisco, San Francisco Co., CA",,,,,,,,,,, +[I0015],Smith,Gus,,,,,male,11 Sep 1897,"Rønne, Bornholm, Denmark",,,,,21 Oct 1963,"San Francisco, San Francisco Co., CA",,,,, +[I0024],Smith,Gustaf,,Sr.,,,male,28 Nov 1862,"Grostorp, Kristianstad Län, Sweden",,,,,before 23 Jul 1930,"Sparks, Washoe Co., NV",,,,, +[I0011],Smith,Hanna,,,,,female,29 Jan 1821,"Gladsax, Kristianstad Län, Sweden",,,,,,,,,,, +[I0010],Smith,Hans Peter,,,,,male,17 Apr 1904,"Rønne, Bornholm, Denmark",Birth Records,,,,29 Jan 1977,"San Francisco, San Francisco Co., CA",,5 Feb 1977,"San Francisco, San Francisco Co., CA",findagrave.com, +[I0021],Smith,Hjalmar,,,,,male,31 Jan 1893,"Rønne, Bornholm, Denmark",,,,,25 Sep 1894,"Rønne, Bornholm, Denmark",,,,, +[I0008],Smith,Hjalmar,,,,,male,7 Apr 1895,"Rønne, Bornholm, Denmark",,3 Jun 1895,"Rønne Bornholm, Denmark",,26 Jun 1975,"Reno, Washoe Co., NV",,,,, +[I0007],Smith,Ingar,,,,,female,after 1823,"Gladsax, Kristianstad Län, Sweden",,,,,,,,,,, +[I0027],Smith,Ingeman,,,,,male,about 1770,Sweden,,,,,,,,,,, +[I0004],Smith,Ingeman,,,,,male,29 Jan 1826,"Gladsax, Kristianstad Län, Sweden",,,,,,,,,,, +[I0018],Smith,John Hjalmar,,,,,male,30 Jan 1932,"San Francisco, San Francisco Co., CA",,,,,,,,,,, +[I0001],Smith,Keith Lloyd,,,,,male,11 Aug 1966,"San Francisco, San Francisco Co., CA",,,,,,,,,,, +[I0026],Smith,Kirsti Marie,,,,,female,15 Dec 1886,"Rønne, Bornholm, Denmark",,,,,18 Jul 1966,"San Francisco, San Francisco Co., CA",,,,, +[I0035],Smith,Lars Peter,,,,,male,16 Sep 1991,"Santa Rosa, Sonoma Co., CA",,,,,,,,,,, +[I0033],Smith,Lloyd,,,,,male,13 Mar 1935,"San Francisco, San Francisco Co., CA",,,,,,,,,,, +[I0003],Smith,Magnes,,,,,male,6 Oct 1858,"Simrishamn, Kristianstad Län, Sweden",,,,,20 Feb 1910,"Rønne, Bornholm, Denmark",,,,, +[I0040],Smith,Marjorie Alice,,,,,female,5 Feb 1960,"San Jose, Santa Clara Co., CA",,,,,,,,,,, +[I0014],Smith,Marjorie Lee,,,,,female,4 Nov 1934,"Reno, Washoe Co., NV",,,,,,,,,,, +[I0022],Smith,Martin,,,,,male,19 Nov 1830,"Gladsax, Kristianstad Län, Sweden",,23 Nov 1830,"Gladsax, Kristianstad Län, Sweden",,between 1899 and 1905,Sweden,,,,, +[I0039],Smith,Martin,,,,,male,between 1794 and 1796,"Tommarp, Kristianstad Län, Sweden",,,,,,Sweden,,,,, +[I0005],Smith,Mason Michael,,,,,male,26 Jun 1996,"Hayward, Alameda Co., CA",,,,,,,,,,, +[I0028],Streiffert,Anna,,,,,female,23 Sep 1860,"Hoya/Jona/Hoia, Sweden",,,,,2 Feb 1927,"Rønne, Bornholm, Denmark",,,,, +[I0006],Willard,Edwin,,,,,male,about 1886,,,,,,,,,,,, +[I0043],リチミシキスイミ,ピーター,,,,,male,,,,,,,,,,,,, + +Marriage,Husband,Wife,Date,Place,Source,Note +[F0000],[I0039],[I0036],about 1816,"Gladsax, Kristianstad Län, Sweden",, +[F0001],[I0027],[I0025],about 1790,Sweden,, +[F0002],[I0022],[I0038],about 1856,,, +[F0003],[I0024],[I0000],27 Nov 1885,"Rønne, Bornholm, Denmark",, +[F0004],[I0006],[I0026],about 1910,,, +[F0005],[I0012],[I0023],30 Nov 1912,"Rønne, Bornholm, Denmark",, +[F0006],[I0008],[I0031],31 Oct 1927,"Reno, Washoe Co., NV",, +[F0007],[I0015],[I0013],about 1920,,, +[F0008],[I0033],[I0041],10 Aug 1958,"San Francisco, San Francisco Co., CA",, +[F0009],[I0010],[I0017],,,, +[F0010],[I0019],[I0032],12 Jul 1986,"Woodland, Yolo Co., CA",, +[F0011],[I0003],[I0028],24 Aug 1884,"Rønne, Bornholm, Denmark",, +[F0012],[I0018],[I0034],4 Jun 1954,"Sparks, Washoe Co., NV",Marriage Certificae, +[F0013],[I0037],[I0030],27 May 1995,"San Ramon, Conta Costa Co., CA",, +[F0014],[I0010],[I0016],,,, + +Family,Child +[F0000],[I0011] +[F0000],[I0007] +[F0000],[I0004] +[F0000],[I0022] +[F0001],[I0039] +[F0002],[I0003] +[F0002],[I0009] +[F0002],[I0024] +[F0003],[I0026] +[F0003],[I0023] +[F0003],[I0021] +[F0003],[I0008] +[F0003],[I0015] +[F0003],[I0020] +[F0003],[I0010] +[F0005],[I0042] +[F0006],[I0018] +[F0006],[I0014] +[F0008],[I0019] +[F0008],[I0001] +[F0008],[I0029] +[F0009],[I0033] +[F0010],[I0035] +[F0012],[I0040] +[F0012],[I0037] +[F0013],[I0005] +[F0013],[I0002] + diff --git a/data/tests/imp_sample_csv.gramps b/data/tests/imp_sample_csv.gramps new file mode 100644 index 000000000..c60251515 --- /dev/null +++ b/data/tests/imp_sample_csv.gramps @@ -0,0 +1,1111 @@ + + + +
+ + + Paul Culley + 11210 Olde Mint House Ln + Tomball + Tx + USA + 77375 + paulr2787@gmail.com + +
+ + + Birth + + + + + Birth + + + + + Death + + + + + Birth + + + + + Birth + + + + Birth + + + + + Death + + + + + Birth + + + + + Death + + + + + Birth + + + + + Birth + + + + + Death + + + + Birth + + + + + Death + + + + Birth + + + + Birth + + + + + Death + + + + Birth + + + + + Death + + + + + Birth + + + + + Birth + + + + + Birth + + + + + Death + + + + + Birth + + + + + Death + + + + + Birth + + + + + Birth + + + + + + Birth + + + + + Birth + + + + + Birth + + + + + Death + + + + + Birth + + + + + Death + + + + + Birth + + + + + Birth + + + + + + Death + + + + + Burial + + + + + + Birth + + + + + Death + + + + + Birth + + + + + Baptism + + + + + Death + + + + + Birth + + + + + Birth + + + + + Birth + + + + + Birth + + + + + Birth + + + + + Birth + + + + + Death + + + + + Birth + + + + + Birth + + + + + Birth + + + + + Death + + + + + Birth + + + + + Birth + + + + + Birth + + + + + Baptism + + + + + Death + + + + + Birth + + + + + Death + + + + Birth + + + + + Birth + + + + + Death + + + + + Birth + + + + Marriage + + + + + Marriage + + + + + Marriage + + + + Marriage + + + + + Marriage + + + + Marriage + + + + + Marriage + + + + + Marriage + + + + Marriage + + + + + Marriage + + + + + Marriage + + + + + Marriage + + + + + + Marriage + + + + + + + F + + Janice Ann + Adams + + + + + + F + + Jennifer + Anderson + + + + + + + F + + Marta + Ericsdotter + + + + + + F + + Janis Elaine + Green + + + + + + F + + Anna + Hansdotter + + + + + + + F + + Kerstina + Hansdotter + + + + + + + F + + Darcy + Horne + + + + + + F + + Elna + Jefferson + + + + + + + F + + Lillie Harriet + Jones + + + + + + + M + + + Ke 柯 + + + + + F + + Evelyn + Michaels + + + + + + M + + Herman Julius + Nielsen + + + + + + + F + + Marjorie + Ohman + + + + + + + F + + Alice Paula + Perkins + + + + + + F + + Amber Marie + Smith + + + + + + F + + Astrid Shermanna Augusta + Smith + + + + + + + + M + + Carl Emil + Smith + + + + + + + M + + Craig Peter + Smith + + + + + + M + + Edwin Michael + Smith + + + + + + + M + + Emil + Smith + + + + + + M + + Eric Lloyd + Smith + Dr. + + + + + + + M + + Gus + Smith + + + + + + + + M + + Gustaf + Smith + Sr. + + + + + + + + F + + Hanna + Smith + + + + + + M + + Hans Peter + Smith + + + + + + + + + + M + + Hjalmar + Smith + + + + + + + M + + Hjalmar + Smith + + + + + + + + + F + + Ingar + Smith + + + + + + M + + Ingeman + Smith + + + + + + M + + Ingeman + Smith + + + + + + M + + John Hjalmar + Smith + + + + + + + M + + Keith Lloyd + Smith + + + + + + F + + Kirsti Marie + Smith + + + + + + + + M + + Lars Peter + Smith + + + + + + M + + Lloyd + Smith + + + + + + + M + + Magnes + Smith + + + + + + + + F + + Marjorie Alice + Smith + + + + + + F + + Marjorie Lee + Smith + + + + + + M + + Martin + Smith + + + + + + + + + M + + Martin + Smith + + + + + + + + M + + Mason Michael + Smith + + + + + + F + + Anna + Streiffert + + + + + + + M + + Edwin + Willard + + + + + + M + + ピーター + リチミシキスイミ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 2 + + + + 2 + + + + 2 + + + + 2 + + + + + + Birth, Death and Marriage Records + + + Birth Records + + + findagrave.com + + + Marriage Certificae + + + + + Löderup, Malmöhus Län, Sweden + + + + Sparks, Washoe Co., NV + + + + San Francisco, San Francisco Co., CA + + + + Rønne, Bornholm, Denmark + + + + Gladsax, Kristianstad Län, Sweden + + + + Reno, Washoe Co., NV + + + + Hayward, Alameda Co., CA + + + + Community Presbyterian Church, Danville, CA + + + + Sweden + + + + Grostorp, Kristianstad Län, Sweden + + + + Copenhagen, Denmark + + + + Hoya/Jona/Hoia, Sweden + + + + Simrishamn, Kristianstad Län, Sweden + + + + Fremont, Alameda Co., CA + + + + Santa Rosa, Sonoma Co., CA + + + + San Jose, Santa Clara Co., CA + + + + UC Berkeley + + + + Smestorp, Kristianstad Län, Sweden + + + + Tommarp, Kristianstad Län, Sweden + + + + Rønne Bornholm, Denmark + + + + Woodland, Yolo Co., CA + + + + San Ramon, Conta Costa Co., CA + + + + United States of America + + + + California, USA + + + + + + + Colorado, USA + + + + + Sacramento Co., California, USA + + + + + + + Sacramento, Sacramento Co., CA + + + + + + + Denver Co., Colorado, USA + + + + + Denver, Denver Co., CO + + + + + +
diff --git a/gramps/plugins/export/exportcsv.py b/gramps/plugins/export/exportcsv.py index 06f75584a..3e1606dd7 100644 --- a/gramps/plugins/export/exportcsv.py +++ b/gramps/plugins/export/exportcsv.py @@ -279,6 +279,44 @@ class CSVWriter: LOG.debug("Possible people to export: %s", len(self.plist)) LOG.debug("Possible families to export: %s", len(self.flist)) LOG.debug("Possible places to export: %s", len(self.place_list)) + ########################### + if self.include_places: + if self.translate_headers: + self.write_csv(_("Place"), _("Title"), _("Name"), + _("Type"), _("Latitude"), _("Longitude"), + _("Code"), _("Enclosed_by"), _("Date")) + else: + self.write_csv("Place", "Title", "Name", + "Type", "Latitude", "Longitude", + "Code", "Enclosed_by", "Date") + for key in self.place_list: + place = self.db.get_place_from_handle(key) + if place: + place_id = place.gramps_id + place_title = place.title + place_name = place.name.value + place_type = str(place.place_type) + place_latitude = place.lat + place_longitude = place.long + place_code = place.code + if place.placeref_list: + for placeref in place.placeref_list: + placeref_obj = self.db.get_place_from_handle(placeref.ref) + placeref_date = "" + if not placeref.date.is_empty(): + placeref_date = placeref.date + placeref_id = "" + if placeref_obj: + placeref_id = "[%s]" % placeref_obj.gramps_id + self.write_csv("[%s]" % place_id, place_title, place_name, place_type, + place_latitude, place_longitude, place_code, placeref_id, + placeref_date) + else: + self.write_csv("[%s]" % place_id, place_title, place_name, place_type, + place_latitude, place_longitude, place_code, "", + "") + self.update() + self.writeln() ########################### sort: sortorder = [] dropped_surnames = set() @@ -493,43 +531,6 @@ class CSVWriter: self.write_csv(family_id, grampsid_ref) self.update() self.writeln() - ########################### - if self.include_places: - if self.translate_headers: - self.write_csv(_("Place"), _("Title"), _("Name"), - _("Type"), _("Latitude"), _("Longitude"), - _("Code"), _("Enclosed_by"), _("Date")) - else: - self.write_csv("Place", "Title", "Name", - "Type", "Latitude", "Longitude", - "Code", "Enclosed_by", "Date") - for key in self.place_list: - place = self.db.get_place_from_handle(key) - if place: - place_id = place.gramps_id - place_title = place.title - place_name = place.name.value - place_type = str(place.place_type) - place_latitude = place.lat - place_longitude = place.long - place_code = place.code - if place.placeref_list: - for placeref in place.placeref_list: - placeref_obj = self.db.get_place_from_handle(placeref.ref) - placeref_date = "" - if not placeref.date.is_empty(): - placeref_date = placeref.date - placeref_id = "" - if placeref_obj: - placeref_id = "[%s]" % placeref_obj.gramps_id - self.write_csv("[%s]" % place_id, place_title, place_name, place_type, - place_latitude, place_longitude, place_code, placeref_id, - placeref_date) - else: - self.write_csv("[%s]" % place_id, place_title, place_name, place_type, - place_latitude, place_longitude, place_code, "", - "") - self.writeln() self.fp.close() return True diff --git a/gramps/plugins/importer/importcsv.py b/gramps/plugins/importer/importcsv.py index b418ad595..ef890c482 100644 --- a/gramps/plugins/importer/importcsv.py +++ b/gramps/plugins/importer/importcsv.py @@ -784,7 +784,10 @@ class CSVParser: if place is None: # new place place = self.create_place() - self.storeup("place", place_id.lower(), place) + if place_id is not None: + if place_id.startswith("[") and place_id.endswith("]"): + place.gramps_id = self.db.id2user_format(place_id[1:-1]) + self.storeup("place", place_id.lower(), place) if place_title is not None: place.title = place_title if place_name is not None: