From fed7d5e5b85f5cb8e9c97a60dc14b35181e8f00e Mon Sep 17 00:00:00 2001 From: kulath Date: Mon, 16 Feb 2015 17:26:28 +0000 Subject: [PATCH] 0008347: GEDCOM import of embedded notes attached to media does not work --- src/plugins/lib/libgedcom.py | 39 +++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/src/plugins/lib/libgedcom.py b/src/plugins/lib/libgedcom.py index 60a0005c1..ac5376a8a 100644 --- a/src/plugins/lib/libgedcom.py +++ b/src/plugins/lib/libgedcom.py @@ -5041,14 +5041,44 @@ class GedcomParser(UpdateCallback): """ +1 <> {0:M} - TODO: Fix this for full reference - @param line: The current line in GedLine format @type line: GedLine @param state: The current state @type state: CurrentState """ - state.note = line.data + # This code pretty much duplicates the code in __parse_note. In + # __parse_note, we already know the object to which the note is to be + # attached, so we can directly add the note to the object. however, in + # the case of a media object, the media object is not constructed till + # the end of processing, so we just remember the handle of the note. + if line.token == TOKEN_RNOTE: + # reference to a named note defined elsewhere + #NOTE_STRUCTURE: = + # n NOTE @@ {1:1} + # +1 SOUR @@ {0:M} + state.note = self.__find_note_handle(self.nid_map[line.data]) + else: + # Embedded note + #NOTE_STRUCTURE: = + # n NOTE [ | ] {1:1} + # +1 [ CONC | CONT ] {0:M} + # +1 SOUR @@ {0:M} + if not line.data: + self.__add_msg(_("Empty note ignored"), line, state) + self.__skip_subordinate_levels(level+1, state) + else: + new_note = gen.lib.Note(line.data) + new_note.set_gramps_id(self.nid_map[""]) + new_note.set_handle(Utils.create_id()) + + sub_state = CurrentState(level=state.level+1) + sub_state.note = new_note + self.__parse_level(sub_state, self.note_parse_tbl, + self.__undefined) + state.msg += sub_state.msg + + self.dbase.commit_note(new_note, self.trans, new_note.change) + state.note = new_note.get_handle() def __family_adopt(self, line, state): """ @@ -7262,8 +7292,7 @@ class GedcomParser(UpdateCallback): oref = gen.lib.MediaRef() oref.set_reference_handle(photo.handle) if note: - gramps_id = self.nid_map[note] - oref.add_note(self.__find_note_handle(gramps_id)) + oref.add_note(note) obj.add_media_reference(oref) def __build_event_pair(self, state, event_type, event_map, description):