From 9d23a4aaa466581951a192208cd3544b0734b00d Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Sat, 30 Sep 2006 03:40:23 +0000 Subject: [PATCH] 2006-09-29 Don Allingham * src/GrampsDb/_ReadGedcom.py: Handle the Place/Address combination for events svn: r7336 --- gramps2/ChangeLog | 4 ++ gramps2/src/GrampsDb/_ReadGedcom.py | 63 ++++++++++++++++++----------- 2 files changed, 44 insertions(+), 23 deletions(-) diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index cd0719129..0aea12c7f 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,3 +1,7 @@ +2006-09-29 Don Allingham + * src/GrampsDb/_ReadGedcom.py: Handle the Place/Address combination + for events + 2006-09-28 Don Allingham * src/DataViews/_PlaceView.py: add street column (bug #459) * src/DisplayModels/_PlaceModel.py: add street column diff --git a/gramps2/src/GrampsDb/_ReadGedcom.py b/gramps2/src/GrampsDb/_ReadGedcom.py index eb8af9e60..e7dc04c44 100644 --- a/gramps2/src/GrampsDb/_ReadGedcom.py +++ b/gramps2/src/GrampsDb/_ReadGedcom.py @@ -1178,20 +1178,13 @@ class GedcomParser(UpdateCallback): # if it does, create a new name by appending the GRAMPS ID. # generate a GRAMPS ID if needed - if title in self.place_names: - if not new_id: - new_id = self.db.find_next_place_gramps_id() - pname = "%s [%s]" % (title,new_id) - else: - pname = title - if self.db.has_place_handle(intid): place.unserialize(self.db.get_raw_place_data(intid)) else: intid = create_id() place.set_handle(intid) - place.set_title(pname) - load_place_values(place,pname) + place.set_title(title) + load_place_values(place,title) place.set_gramps_id(new_id) self.db.add_place(place,self.trans) self.lid2id[title] = intid @@ -1731,24 +1724,28 @@ class GedcomParser(UpdateCallback): else: self.not_recognized(level+1) - def parse_place_as_address(self, place, level): - note = "" + def parse_place_as_address(self, street, level): + note = None location = RelLib.Location() - added = False - + if street: + location.set_street(street) + added = True + else: + added = False + while True: matches = self.get_next() if self.level_is_finished(matches,level): break elif matches[1] in (TOKEN_ADDR, TOKEN_ADR1, TOKEN_ADR2): - val = place.get_title().strip() + val = location.get_street() if val: val = "%s, %s" % (val, matches[2].strip()) else: val = matches[2].strip() - place.set_title(val.replace('\n',' ')) + location.set_street(val.replace('\n',' ')) added = True elif matches[1] == TOKEN_DATE: location.set_date_object(self.extract_date(matches[2])) @@ -1767,14 +1764,15 @@ class GedcomParser(UpdateCallback): added = True elif matches[1] == TOKEN_NOTE: note = self.parse_note(matches,location,level+1,'') - place.set_note(note) added = True elif matches[1] in (TOKEN__LOC, TOKEN__NAME, TOKEN_PHON): pass # ignore unsupported extended location syntax else: self.not_recognized(level+1) if added: - place.set_main_location(location) + return (location, note) + else: + return (None, None) def parse_ord(self,lds_ord,level): note = "" @@ -1907,13 +1905,32 @@ class GedcomParser(UpdateCallback): event.add_source_reference(self.handle_source(matches,level)) def func_event_addr(self, matches, event_ref, event, level): - place = self.find_or_create_place(matches[2]) - place_handle = place.handle - place.set_title(matches[2]) - load_place_values(place,matches[2]) + (location, note) = self.parse_place_as_address(matches[2], level) + if location: + index = matches[2] + location.get_street() + else: + index = matches[2] + + place_handle = event.get_place_handle() + if place_handle: + place = self.db.get_place_from_handle(place_handle) + main_loc = place.get_main_location() + if main_loc and main_loc.get_street() != location.get_street(): + old_title = place.get_title() + place = self.find_or_create_place(index) + place.set_title(old_title) + place_handle = place.handle + else: + place = self.find_or_create_place(index) + place.set_title(matches[2]) + place_handle = place.handle + + load_place_values(place,matches[2]) + if location: + place.set_main_location(location) + if note: + place.set_note(note) - self.parse_place_as_address(place, level) - event.set_place_handle(place_handle) self.db.commit_place(place, self.trans)