bug 9676 CSV import, fix failure for certain types of cross references

This commit is contained in:
prculley 2016-09-05 14:59:00 -05:00
parent 2226781a98
commit 0327f751c3

View File

@ -154,94 +154,79 @@ class CSVParser:
self.place_types[custom_type] = 0 self.place_types[custom_type] = 0
self.place_types[custom_type.lower()] = 0 self.place_types[custom_type.lower()] = 0
column2label = { column2label = {
"surname": ("Lastname", "Surname", _("Surname"), "lastname", "surname": ("lastname", "last_name", "surname", _("surname")),
"last_name", "surname", _("surname")), "firstname": ("firstname", "first_name", "given_name", "given",
"firstname": ("Firstname", "Given name", _("Given name"), "Given", "given name", _("given name"), _("given")),
_("Given"), "firstname", "first_name", "given_name", "callname": ("call name", _("Call name"), "callname", "call_name",
"given name", _("given name"), "given", _("given")), "call", _("call")),
"callname": ("Callname", "Call name", _("Call name"), "Call", "title": ("title", _("title"), _("Person or Place|title")),
_("Call"), "callname", "call_name", "call name", "call", "prefix": ("prefix", _("prefix")),
_("call")), "suffix": ("suffix", _("suffix")),
"title": ("Title", _("Person or Place|Title"), "title", _("Person or Place|title")), "gender": ("gender", _("gender")),
"prefix": ("Prefix", _("Prefix"), "prefix", _("prefix")), "source": ("source", _("source")),
"suffix": ("Suffix", _("Suffix"), "suffix", _("suffix")), "note": ("note", _("note")),
"gender": ("Gender", _("Gender"), "gender", _("gender")), "birthplace": ("birthplace", "birth_place", "birth place",
"source": ("Source", _("Source"), "source", _("source")), _("birth place")),
"note": ("Note", _("Note"), "note", _("note")), "birthplace_id": ("birthplaceid", "birth_place_id",
"birthplace": ("Birthplace", "Birth place", _("Birth place"), "birth place id", _("birth place id"),
"birthplace", "birth_place", "birth place", _("birth place")),
"birthplace_id": ("Birthplaceid", "Birth place id", _("Birth place id"),
"birthplaceid", "birth_place_id", "birth place id", _("birth place id"),
"birthplace_id"), "birthplace_id"),
"birthdate": ("Birthdate", "Birth date", _("Birth date"), "birthdate": ("birthdate", "birth_date", "birth date",
"birthdate", "birth_date", "birth date", _("birth date")), _("birth date")),
"birthsource": ("Birthsource", "Birth source", _("Birth source"), "birthsource": ("birthsource", "birth_source", "birth source",
"birthsource", "birth_source", "birth source", _("birth source")),
_("birth source")), "baptismplace": ("baptismplace", "baptism place",
"baptismplace": ("Baptismplace", "Baptism place", _("baptism place")),
_("Baptism place"), "baptismplace", "baptism place", "baptismplace_id": ("baptismplaceid", "baptism place id",
_("baptism place")),
"baptismplace_id": ("Baptismplaceid", "Baptism place id",
_("Baptism place id"), "baptismplaceid", "baptism place id",
_("baptism place id"), "baptism_place_id", _("baptism place id"), "baptism_place_id",
"baptismplace_id"), "baptismplace_id"),
"baptismdate": ("Baptismdate", "Baptism date", _("Baptism date"), "baptismdate": ("baptismdate", "baptism date", _("baptism date")),
"baptismdate", "baptism date", _("baptism date")), "baptismsource": ("baptismsource", "baptism source",
"baptismsource": ("Baptismsource", "Baptism source", _("baptism source")),
_("Baptism source"), "baptismsource", "baptism source", "burialplace": ("burialplace", "burial place", _("burial place")),
_("baptism source")), "burialplace_id": ("burialplaceid", "burial place id",
"burialplace": ("Burialplace", "Burial place", _("Burial place"), _("burial place id"), "burial_place_id",
"burialplace", "burial place", _("burial place")), "burialplace_id"),
"burialplace_id": ("Burialplaceid", "Burial place id", _("Burial place id"), "burialdate": ("burialdate", "burial date", _("burial date")),
"burialplaceid", "burial place id", _("burial place id"), "burialsource": ("burialsource", "burial source",
"burial_place_id", "burialplace_id"), _("burial source")),
"burialdate": ("Burialdate", "Burial date", _("Burial date"), "deathplace": ("deathplace", "death_place", "death place",
"burialdate", "burial date", _("burial date")), _("death place")),
"burialsource": ("Burialsource", "Burial source", "deathplace_id": ("deathplaceid", "death place id",
_("Burial source"), "burialsource", "burial source", _("death place id"), "death_place_id",
_("burial source")), "deathplace_id"),
"deathplace": ("Deathplace", "Death place", _("Death place"), "deathdate": ("deathdate", "death_date", "death date",
"deathplace", "death_place", "death place", _("death place")), _("death date")),
"deathplace_id": ("Deathplaceid", "Death place id", _("Death place id"), "deathsource": ("deathsource", "death_source", "death source",
"deathplaceid", "death_place_id", "death place id", _("death place id"), _("death source")),
"death_place_id", "deathplace_id"), "deathcause": ("deathcause", "death_cause", "death cause",
"deathdate": ("Deathdate", "Death date", _("Death date"), _("death cause")),
"deathdate", "death_date", "death date", _("death date")), "grampsid": (_("Gramps ID"), "grampsid", "id", "gramps_id",
"deathsource": ("Deathsource", "Death source", _("Death source"), "gramps id"),
"deathsource", "death_source", "death source", "person": ("person", _("person")),
_("death source")),
"deathcause": ("Deathcause", "Death cause", _("Death cause"),
"deathcause", "death_cause", "death cause", _("death cause")),
"grampsid": ("Grampsid", "ID", "Gramps id", _("Gramps ID"),
"grampsid", "id", "gramps_id", "gramps id", _("Gramps id")),
"person": ("Person", _("Person"), "person", _("person")),
# ---------------------------------- # ----------------------------------
"child": ("Child", _("Child"), "child", _("child")), "child": ("child", _("child")),
"family": ("Family", _("Family"), "family", _("family")), "family": ("family", _("family")),
# ---------------------------------- # ----------------------------------
"wife": ("Mother", _("Mother"), "Wife", _("Wife"), "Parent2", "wife": ("mother", _("mother"), "wife", _("wife"),
_("Parent2"), "mother", _("mother"), "wife", _("wife"), "parent2", _("parent2")),
"parent2", _("parent2")), "husband": ("father", _("father"), "husband", _("husband"),
"husband": ("Father", _("Father"), "Husband", _("Husband"), "parent1", _("parent1")),
"Parent1", _("Parent1"), "father", _("father"), "husband", "marriage": ("marriage", _("marriage")),
_("husband"), "parent1", _("parent1")), "date": ("date", _("date")),
"marriage": ("Marriage", _("Marriage"), "marriage", _("marriage")), "place": ("place", _("place")),
"date": ("Date", _("Date"), "date", _("date")), "place_id": ("place id", "place_id", "placeid", _("place id")),
"place": ("Place", _("Place"), "place", _("place")), "name": ("name", _("name")),
"place_id": ("Placeid", "place id", "Place id", "place_id", "placeid"), "type": ("type", _("type")),
"name": ("Name", _("Name"), "name", _("name")), "latitude": ("latitude", _("latitude")),
"type": ("Type", _("Type"), "type", _("type")), "longitude": ("longitude", _("longitude")),
"latitude": ("Latitude", _("latitude"), "latitude", _("latitude")), "code": ("code", _("code")),
"longitude": ("Longitude", _("Longitude"), "longitude", _("longitude")), "enclosed_by": ("enclosed by", _("enclosed by"),
"code": ("Code", _("Code"), "code", _("code")), "enclosed_by", _("enclosed_by"), "enclosedby")
"enclosed_by": ("Enclosed by", _("Enclosed by"), "enclosed by", _("enclosed by"),
"enclosed_by", _("enclosed_by"), "Enclosed_by", _("Enclosed_by"),
"enclosedby")
} }
lab2col_dict = [] lab2col_dict = []
for key in list(column2label.keys()): for key in list(column2label.keys()):
for val in column2label[key]: for val in column2label[key]:
lab2col_dict.append((val, key)) lab2col_dict.append((val.lower(), key))
self.label2column = dict(lab2col_dict) self.label2column = dict(lab2col_dict)
if default_tag_format: if default_tag_format:
name = time.strftime(default_tag_format) name = time.strftime(default_tag_format)
@ -283,10 +268,12 @@ class CSVParser:
return self.lookup(type_, id_) return self.lookup(type_, id_)
else: else:
return db_lookup return db_lookup
elif id_.lower() in self.fref:
return self.fref[id_.lower()]
else: else:
return None id_ = self.db.fid2user_format(id_)
if id_.lower() in self.fref:
return self.fref[id_.lower()]
else:
return None
elif type_ == "person": elif type_ == "person":
if id_.startswith("[") and id_.endswith("]"): if id_.startswith("[") and id_.endswith("]"):
id_ = self.db.id2user_format(id_[1:-1]) id_ = self.db.id2user_format(id_[1:-1])
@ -295,22 +282,26 @@ class CSVParser:
return self.lookup(type_, id_) return self.lookup(type_, id_)
else: else:
return db_lookup return db_lookup
elif id_.lower() in self.pref:
return self.pref[id_.lower()]
else: else:
return None id_ = self.db.id2user_format(id_)
if id_.lower() in self.pref:
return self.pref[id_.lower()]
else:
return None
elif type_ == "place": elif type_ == "place":
if id_.startswith("[") and id_.endswith("]"): if id_.startswith("[") and id_.endswith("]"):
id_ = self.db.id2user_format(id_[1:-1]) id_ = self.db.pid2user_format(id_[1:-1])
db_lookup = self.db.get_place_from_gramps_id(id_) db_lookup = self.db.get_place_from_gramps_id(id_)
if db_lookup is None: if db_lookup is None:
return self.lookup(type_, id_) return self.lookup(type_, id_)
else: else:
return db_lookup return db_lookup
elif id_.lower() in self.placeref:
return self.placeref[id_.lower()]
else: else:
return None id_ = self.db.pid2user_format(id_)
if id_.lower() in self.placeref:
return self.placeref[id_.lower()]
else:
return None
else: else:
LOG.warning("invalid lookup type in CSV import: '%s'" % type_) LOG.warning("invalid lookup type in CSV import: '%s'" % type_)
return None return None
@ -382,7 +373,7 @@ class CSVParser:
continue continue
###################################### ######################################
if header is None: if header is None:
header = [self.cleanup_column_name(r) for r in row] header = [self.cleanup_column_name(r.lower()) for r in row]
col = {} col = {}
count = 0 count = 0
for key in header: for key in header:
@ -433,7 +424,7 @@ class CSVParser:
wife.set_gender(Person.FEMALE) wife.set_gender(Person.FEMALE)
self.db.commit_person(wife, self.trans) self.db.commit_person(wife, self.trans)
if marriage_ref: if marriage_ref:
self.storeup("family", marriage_ref.lower(), family) self.storeup("family", marriage_ref, family)
if marriagesource: if marriagesource:
# add, if new # add, if new
new, marriagesource = self.get_or_create_source(marriagesource) new, marriagesource = self.get_or_create_source(marriagesource)
@ -786,8 +777,8 @@ class CSVParser:
place = self.create_place() place = self.create_place()
if place_id is not None: if place_id is not None:
if place_id.startswith("[") and place_id.endswith("]"): if place_id.startswith("[") and place_id.endswith("]"):
place.gramps_id = self.db.id2user_format(place_id[1:-1]) place.gramps_id = self.db.pid2user_format(place_id[1:-1])
self.storeup("place", place_id.lower(), place) self.storeup("place", place_id, place)
if place_title is not None: if place_title is not None:
place.title = place_title place.title = place_title
if place_name is not None: if place_name is not None: