From dfe221d48ed45e832c204e1871d694918772a042 Mon Sep 17 00:00:00 2001 From: Christopher Horn Date: Fri, 28 May 2021 20:41:22 -0400 Subject: [PATCH] Add round trip Ancestry.com _APID tag support Implements #9925 --- gramps/plugins/export/exportgedcom.py | 10 ++++++++++ gramps/plugins/lib/libgedcom.py | 15 +++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/gramps/plugins/export/exportgedcom.py b/gramps/plugins/export/exportgedcom.py index 2a6102485..d6d64bfcd 100644 --- a/gramps/plugins/export/exportgedcom.py +++ b/gramps/plugins/export/exportgedcom.py @@ -999,6 +999,11 @@ class GedcomWriter(UpdateCallback): self._note_references(source.get_note_list(), 1) self._change(source.get_change_time(), 1) + for srcattr in source.get_attribute_list(): + if str(srcattr.type) == "_APID": + self._writeln(1, "_APID", srcattr.value) + break + def _notes(self): """ Write out the list of notes, sorting by Gramps ID. @@ -1408,6 +1413,11 @@ class GedcomWriter(UpdateCallback): self._writeln(level + 2, "ROLE", srcattr.value) break + for srcattr in citation.get_attribute_list(): + if str(srcattr.type) == "_APID": + self._writeln(level + 1, "_APID", srcattr.value) + break + def _photo(self, photo, level): """ n OBJE @@ {1:1} diff --git a/gramps/plugins/lib/libgedcom.py b/gramps/plugins/lib/libgedcom.py index 515baa7f9..4e7e0eaa4 100644 --- a/gramps/plugins/lib/libgedcom.py +++ b/gramps/plugins/lib/libgedcom.py @@ -275,6 +275,7 @@ TOKEN__PRIM = 134 TOKEN__JUST = 135 TOKEN__TEXT = 136 TOKEN__DATE = 137 +TOKEN__APID = 138 TOKENS = { "_ADPN" : TOKEN__ADPN, @@ -282,6 +283,7 @@ TOKENS = { "_AKAN" : TOKEN__AKA, "_ALIA" : TOKEN_ALIA, "_ANCES_ORDRE" : TOKEN_IGNORE, + "_APID" : TOKEN__APID, # Ancestry.com database and page id "_CAT" : TOKEN_IGNORE, "_CHUR" : TOKEN_IGNORE, "_COMM" : TOKEN__COMM, @@ -2304,6 +2306,7 @@ class GedcomParser(UpdateCallback): TOKEN_TEXT : self.__citation_data_text, TOKEN__LINK : self.__citation_link, TOKEN__JUST : self.__citation__just, + TOKEN__APID : self.__citation__apid, } self.func_list.append(self.citation_parse_tbl) @@ -2452,6 +2455,7 @@ class GedcomParser(UpdateCallback): # not legal, but Ultimate Family Tree does this TOKEN_DATE : self.__ignore, TOKEN_IGNORE : self.__ignore, + TOKEN__APID : self.__source_attr, } self.func_list.append(self.source_func) @@ -6377,6 +6381,17 @@ class GedcomParser(UpdateCallback): self.dbase.add_note(note, self.trans) state.citation.add_note(note.get_handle()) + def __citation__apid(self, line, state): + """ + Not legal GEDCOM - added to support Ancestry.com, converts the + _APID tag to an attribute. This tag identifies the location of + the cited page in the relevant Ancestry.com database. + """ + sattr = SrcAttribute() + sattr.set_type("_APID") + sattr.set_value(line.data) + state.citation.add_attribute(sattr) + def __citation_data_note(self, line, state): self.__parse_note(line, state.citation, state)