From afef197a57b42565cf59bab394febf13fdc2cbfb Mon Sep 17 00:00:00 2001 From: Nick Hall Date: Tue, 30 Aug 2011 12:34:46 +0000 Subject: [PATCH] Update Gramps XML Import/Export to support Citations svn: r18086 --- data/grampsxml.dtd | 79 +++++++------ data/grampsxml.rng | 96 ++++++++++------ src/plugins/export/ExportXml.py | 126 ++++++++++---------- src/plugins/import/ImportXml.py | 197 +++++++++++++++++++++++--------- src/plugins/lib/libgrampsxml.py | 2 +- 5 files changed, 306 insertions(+), 194 deletions(-) diff --git a/data/grampsxml.dtd b/data/grampsxml.dtd index e78a611d7..c120a6ab3 100644 --- a/data/grampsxml.dtd +++ b/data/grampsxml.dtd @@ -5,7 +5,7 @@ # # Copyright (C) 2001 Graham J. Williams # Copyright (C) 2000-2007 Donald N. Allingham -# Copyright (C) 2010 Nick Hall +# Copyright (C) 2010-2011 Nick Hall # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -25,15 +25,15 @@ --> @@ -48,6 +48,7 @@ DATABASE families events places + citations sources objects repositories @@ -59,9 +60,9 @@ DATABASE --> - + citations?, sources?, places?, objects?, repositories?, + notes?, bookmarks?, namemaps?)> + - + - + + citationref*)> @@ -180,12 +181,11 @@ FAMILY + childref*, attribute*, noteref*, citationref*, tagref*)> @@ -195,7 +195,7 @@ FAMILY - + + description?, attribute*, noteref*, citationref*, objref*)> @@ -234,7 +233,6 @@ SOURCES id CDATA #IMPLIED handle ID #REQUIRED priv (0|1) #IMPLIED - marker CDATA #IMPLIED change CDATA #REQUIRED > @@ -249,12 +247,11 @@ PLACES + citationref*)> @@ -285,12 +282,11 @@ OBJECTS + (daterange|datespan|dateval|datestr)?, citationref*, tagref*)> @@ -312,7 +308,6 @@ REPOSITORIES id CDATA #IMPLIED handle ID #REQUIRED priv (0|1) #IMPLIED - marker CDATA #IMPLIED change CDATA #REQUIRED > @@ -329,7 +324,6 @@ NOTES id CDATA #IMPLIED handle ID #REQUIRED priv (0|1) #IMPLIED - marker CDATA #IMPLIED change CDATA #REQUIRED format (0|1) #IMPLIED type CDATA #REQUIRED @@ -365,6 +359,21 @@ TAGS change CDATA #REQUIRED > + + + + + + + @@ -436,11 +445,14 @@ SHARED ELEMENTS - + + + + @@ -468,9 +480,10 @@ SHARED ELEMENTS hlink IDREF #REQUIRED > - + + - + - + + status?, sealed_to?, noteref*, citationref*)> @@ -82,6 +82,12 @@ + + + + + + @@ -148,7 +154,6 @@ 0 1 - @@ -195,8 +200,8 @@ - - + + @@ -234,20 +239,20 @@ + + + + + - - - - - - - + + @@ -284,8 +289,8 @@ - - + + @@ -379,8 +384,8 @@ - - + + @@ -401,14 +406,34 @@ - - + + + + + + + + + + + + + + + + + + + + + + @@ -456,8 +481,8 @@ - - + + @@ -475,8 +500,8 @@ - - + + @@ -564,19 +589,14 @@ + + + + - - - - - - - - - - + @@ -620,8 +640,8 @@ - - + + @@ -648,8 +668,8 @@ - - + + @@ -678,8 +698,8 @@ - - + + diff --git a/src/plugins/export/ExportXml.py b/src/plugins/export/ExportXml.py index af0baad73..3629e4dbe 100644 --- a/src/plugins/export/ExportXml.py +++ b/src/plugins/export/ExportXml.py @@ -7,7 +7,7 @@ # Copyright (C) 2008 Robert Cheramy # Copyright (C) 2009 Douglas S. Blank # Copyright (C) 2010 Jakim Friant -# Copyright (C) 2010 Nick Hall +# Copyright (C) 2010-2011 Nick Hall # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -200,6 +200,7 @@ class GrampsXmlWriter(UpdateCallback): person_len = self.db.get_number_of_people() family_len = self.db.get_number_of_families() event_len = self.db.get_number_of_events() + citation_len = self.db.get_number_of_citations() source_len = self.db.get_number_of_sources() place_len = self.db.get_number_of_places() repo_len = self.db.get_number_of_repositories() @@ -207,8 +208,9 @@ class GrampsXmlWriter(UpdateCallback): note_len = self.db.get_number_of_notes() tag_len = self.db.get_number_of_tags() - total_steps = (person_len + family_len + event_len + source_len + - place_len + repo_len + obj_len + note_len + tag_len + total_steps = (person_len + family_len + event_len + citation_len + + source_len + place_len + repo_len + obj_len + note_len + + tag_len ) self.set_total(total_steps) @@ -282,11 +284,20 @@ class GrampsXmlWriter(UpdateCallback): self.update() self.g.write(" \n") + if citation_len > 0: + self.g.write(" \n") + for handle in self.db.get_citation_handles(): + citation = self.db.get_citation_from_handle(handle) + self.write_citation(citation,2) + self.update() + self.g.write(" \n") + if source_len > 0: self.g.write(" \n") for handle in self.db.get_source_handles(): source = self.db.get_source_from_handle(handle) self.write_source(source,2) + self.update() self.g.write(" \n") if place_len > 0: @@ -522,8 +533,8 @@ class GrampsXmlWriter(UpdateCallback): self.write_note_list(person.get_note_list(),index+1) - for s in person.get_source_references(): - self.dump_source_ref(s,index+2) + for citation_handle in person.get_citation_references(): + self.write_ref("citationref", citation_handle, index+2) for tag_handle in person.get_tag_list(): self.write_ref("tagref", tag_handle, index+1) @@ -550,14 +561,26 @@ class GrampsXmlWriter(UpdateCallback): self.dump_child_ref(child_ref,index+1) self.write_attribute_list(family.get_attribute_list()) self.write_note_list(family.get_note_list(),index+1) - for s in family.get_source_references(): - self.dump_source_ref(s,index+1) + for citation_handle in family.get_citation_references(): + self.write_ref("citationref", citation_handle, index+1) for tag_handle in family.get_tag_list(): self.write_ref("tagref", tag_handle, index+1) self.g.write("%s\n" % sp) + def write_citation(self, citation, index=1): + sp = " " * index + self.write_primary_tag("citation", citation, index) + self.write_date(citation.get_date_object(), index+1) + self.write_line("page", citation.get_page(), index+1) + self.write_line("confidence", citation.get_confidence_level(), index+1) + self.write_note_list(citation.get_note_list(), index+1) + self.write_media_list(citation.get_media_list(), index+1) + self.write_data_map(citation.get_data_map()) + self.write_ref("sourceref", citation.get_reference_handle(), index+1) + self.g.write("%s\n" % sp) + def write_source(self,source,index=1): sp = " "*index self.write_primary_tag("source",source,index) @@ -602,8 +625,8 @@ class GrampsXmlWriter(UpdateCallback): self.write_line("postal",address.get_postal_code(),index+1) self.write_line("phone",address.get_phone(),index+1) self.write_note_list(address.get_note_list(),index+1) - for s in address.get_source_references(): - self.dump_source_ref(s,index+2) + for citation_handle in address.get_citation_references(): + self.write_ref("citationref", citation_handle, index+1) self.g.write('%s\n' % sp) def dump_person_ref(self,personref,index=1): @@ -613,16 +636,17 @@ class GrampsXmlWriter(UpdateCallback): priv_text = conf_priv(personref) rel_text = ' rel="%s"' % escxml(personref.get_relation()) - sreflist = personref.get_source_references() + citation_list = personref.get_citation_references() nreflist = personref.get_note_list() - if (len(sreflist) + len(nreflist) == 0): + if (len(citation_list) + len(nreflist) == 0): self.write_ref('personref',personref.ref,index,close=True, extra_text=priv_text+rel_text) else: self.write_ref('personref',personref.ref,index,close=False, extra_text=priv_text+rel_text) - for sref in sreflist: - self.dump_source_ref(sref,index+1) + for citation_handle in citation_list: + self.write_ref("citationref", citation_handle, index+1) + self.write_note_list(nreflist,index+1) self.g.write('%s\n' % sp) @@ -639,16 +663,16 @@ class GrampsXmlWriter(UpdateCallback): mrel_text = '' else: mrel_text = ' mrel="%s"' % escxml(childref.mrel.xml_str()) - sreflist = childref.get_source_references() + citation_list = childref.get_citation_references() nreflist = childref.get_note_list() - if (len(sreflist)+len(nreflist) == 0): + if (len(citation_list)+len(nreflist) == 0): self.write_ref('childref',childref.ref,index,close=True, extra_text=priv_text+mrel_text+frel_text) else: self.write_ref('childref',childref.ref,index,close=False, extra_text=priv_text+mrel_text+frel_text) - for sref in sreflist: - self.dump_source_ref(sref,index+1) + for citation_handle in citation_list: + self.write_ref("citationref", citation_handle, index+1) self.write_note_list(nreflist,index+1) self.g.write('%s\n' % sp) @@ -690,8 +714,8 @@ class GrampsXmlWriter(UpdateCallback): self.write_attribute_list(event.get_attribute_list(),index+1) self.write_note_list(event.get_note_list(),index+1) - for s in event.get_source_references(): - self.dump_source_ref(s,index+1) + for citation_handle in event.get_citation_references(): + self.write_ref("citationref", citation_handle, index+1) self.write_media_list(event.get_media_list(),index+1) self.g.write("%s\n" % sp) @@ -717,39 +741,9 @@ class GrampsXmlWriter(UpdateCallback): self.g.write('%s\n' % (sp2,"_"+ord.get_family_handle())) self.write_note_list(ord.get_note_list(),index+1) - for s in ord.get_source_references(): - self.dump_source_ref(s,index+1) + for citation_handle in ord.get_citation_references(): + self.write_ref("citationref", citation_handle, index+1) self.g.write('%s\n' % sp) - - def dump_source_ref(self,source_ref,index=1): - source = self.db.get_source_from_handle( - source_ref.get_reference_handle()) - if source: - p = source_ref.get_page() - n = source_ref.get_note_list() - d = source_ref.get_date_object() - q = source_ref.get_confidence_level() - self.g.write(" " * index) - - priv = conf_priv(source_ref) - - if p == "" and n == [] and d.is_empty() and q == 2: - self.g.write('\n' - % ("_"+source.get_handle(), priv) - ) - else: - if q == 2: - self.g.write('\n' - % ("_"+source.get_handle(), priv) - ) - else: - self.g.write('\n' - % ("_"+source.get_handle(), q, priv) - ) - self.write_line("spage",p,index+1) - self.write_note_list(n,index+1) - self.write_date(d,index+1) - self.g.write("%s\n" % (" " * index)) def write_ref(self,tagname, handle,index=1,close=True,extra_text=''): if handle: @@ -956,8 +950,8 @@ class GrampsXmlWriter(UpdateCallback): if name.date: self.write_date(name.date,4) self.write_note_list(name.get_note_list(),index+1) - for s in name.get_source_references(): - self.dump_source_ref(s,index+1) + for citation_handle in name.get_citation_references(): + self.write_ref("citationref", citation_handle, index+1) self.g.write('%s\n' % sp) @@ -1037,14 +1031,14 @@ class GrampsXmlWriter(UpdateCallback): (sp,conf_priv(attr),escxml(attr.get_type().xml_str()), self.fix(attr.get_value())) ) - slist = attr.get_source_references() + citation_list = attr.get_citation_references() nlist = attr.get_note_list() - if (len(nlist)+len(slist)) == 0: + if (len(nlist)+len(citation_list)) == 0: self.g.write('/>\n') else: self.g.write('>\n') - for s in attr.get_source_references(): - self.dump_source_ref(s,indent+1) + for citation_handle in citation_list: + self.write_ref("citationref", citation_handle, indent+1) self.write_note_list(attr.get_note_list(),indent+1) self.g.write('%s\n' % sp) @@ -1056,7 +1050,7 @@ class GrampsXmlWriter(UpdateCallback): if photo.get_privacy(): self.g.write(' priv="1"') proplist = photo.get_attribute_list() - refslist = photo.get_source_references() + citation_list = photo.get_citation_references() nreflist = photo.get_note_list() rect = photo.get_rectangle() if rect is not None : @@ -1073,7 +1067,7 @@ class GrampsXmlWriter(UpdateCallback): corner1_x == corner1_y == 0 and corner2_x == corner2_y == 100): rect = None - if (len(proplist) + len(nreflist) + len(refslist) == 0 and + if (len(proplist) + len(nreflist) + len(citation_list) == 0 and rect is None): self.g.write("/>\n") else: @@ -1089,8 +1083,8 @@ class GrampsXmlWriter(UpdateCallback): ) ) self.write_attribute_list(proplist,indent+1) - for ref in refslist: - self.dump_source_ref(ref, indent+1) + for citation_handle in citation_list: + self.write_ref("citationref", citation_handle, indent+1) self.write_note_list(nreflist, indent+1) self.g.write('%s\n' % sp) @@ -1169,7 +1163,7 @@ class GrampsXmlWriter(UpdateCallback): llen = (len(place.get_alternate_locations()) + len(place.get_url_list()) + len(place.get_media_list()) + - len(place.get_source_references()) + len(place.get_citation_references()) ) ml_empty = main_loc.is_empty() @@ -1186,8 +1180,8 @@ class GrampsXmlWriter(UpdateCallback): self.write_media_list(place.get_media_list(), index+1) self.write_url_list(place.get_url_list()) self.write_note_list(place.get_note_list(), index+1) - for s in place.get_source_references(): - self.dump_source_ref(s, index+1) + for citation_handle in place.get_citation_references(): + self.write_ref("citationref", citation_handle, index+1) self.g.write("%s\n" % (" "*index)) def write_object(self, obj, index=1): @@ -1216,8 +1210,8 @@ class GrampsXmlWriter(UpdateCallback): dval = obj.get_date_object() if not dval.is_empty(): self.write_date(dval, index+1) - for s in obj.get_source_references(): - self.dump_source_ref(s, index+1) + for citation_handle in obj.get_citation_references(): + self.write_ref("citationref", citation_handle, index+1) for tag_handle in obj.get_tag_list(): self.write_ref("tagref", tag_handle, index+1) diff --git a/src/plugins/import/ImportXml.py b/src/plugins/import/ImportXml.py index 6c903fb27..976ab1d6e 100644 --- a/src/plugins/import/ImportXml.py +++ b/src/plugins/import/ImportXml.py @@ -3,7 +3,7 @@ # # Copyright (C) 2000-2007 Donald N. Allingham # Copyright (C) 2009 Douglas S. Blank -# Copyright (C) 2010 Nick Hall +# Copyright (C) 2010-2011 Nick Hall # Copyright (C) 2011 Michiel D. Nauta # # This program is free software; you can redistribute it and/or modify @@ -52,7 +52,7 @@ import DateHandler from gen.display.name import displayer as name_displayer from gen.db.dbconst import (PERSON_KEY, FAMILY_KEY, SOURCE_KEY, EVENT_KEY, MEDIA_KEY, PLACE_KEY, REPOSITORY_KEY, NOTE_KEY, - TAG_KEY) + TAG_KEY, CITATION_KEY) from gen.updatecallback import UpdateCallback import const import libgrampsxml @@ -190,7 +190,7 @@ class ImportInfo(object): Class object that can hold information about the import """ keyorder = [PERSON_KEY, FAMILY_KEY, SOURCE_KEY, EVENT_KEY, MEDIA_KEY, - PLACE_KEY, REPOSITORY_KEY, NOTE_KEY, TAG_KEY] + PLACE_KEY, REPOSITORY_KEY, NOTE_KEY, TAG_KEY, CITATION_KEY] key2data = { PERSON_KEY : 0, FAMILY_KEY : 1, @@ -200,7 +200,8 @@ class ImportInfo(object): PLACE_KEY: 5, REPOSITORY_KEY: 6, NOTE_KEY: 7, - TAG_KEY: 8 + TAG_KEY: 8, + CITATION_KEY: 9 } def __init__(self): @@ -209,8 +210,8 @@ class ImportInfo(object): This creates the datastructures to hold info """ - self.data_mergecandidate = [{}, {}, {}, {}, {}, {}, {}, {}, {}] - self.data_newobject = [0] * 9 + self.data_mergecandidate = [{}, {}, {}, {}, {}, {}, {}, {}, {}, {}] + self.data_newobject = [0] * 10 self.data_relpath = False def add(self, category, key, obj, sec_obj=None): @@ -260,6 +261,9 @@ class ImportInfo(object): 'id': obj.gramps_id, 'id2': sec_obj.gramps_id} elif key == TAG_KEY: pass # Tags can't be merged + elif key == CITATION_KEY: + return _(" Citation %(id)s with %(id2)s\n") % { + 'id': obj.gramps_id, 'id2': sec_obj.gramps_id} def info_text(self): """ @@ -275,6 +279,7 @@ class ImportInfo(object): REPOSITORY_KEY : _(' Repositories: %d\n'), NOTE_KEY : _(' Notes: %d\n'), TAG_KEY : _(' Tags: %d\n'), + CITATION_KEY : _(' Citations: %d\n'), } txt = _("Number of new objects imported:\n") for key in self.keyorder: @@ -453,8 +458,9 @@ class GrampsParser(UpdateCallback): self.person = None self.family = None self.address = None + self.citation = None + self.in_old_sourceref = False self.source = None - self.source_ref = None self.attribute = None self.placeobj = None self.locations = 0 @@ -500,6 +506,7 @@ class GrampsParser(UpdateCallback): self.idswap = {} self.fidswap = {} self.eidswap = {} + self.cidswap = {} self.sidswap = {} self.pidswap = {} self.oidswap = {} @@ -540,10 +547,14 @@ class GrampsParser(UpdateCallback): "childof": (self.start_childof, None), "childref": (self.start_childref, self.stop_childref), "personref": (self.start_personref, self.stop_personref), + "citation": (self.start_citation, self.stop_citation), + "citationref": (self.start_citationref, None), + "citations": (None, None), "city": (None, self.stop_city), "county": (None, self.stop_county), "country": (None, self.stop_country), "comment": (None, self.stop_comment), + "confidence": (None, self.stop_confidence), "created": (self.start_created, None), "ref": (None, self.stop_ref), "database": (self.start_database, self.stop_database), @@ -576,6 +587,7 @@ class GrampsParser(UpdateCallback): "objref": (self.start_objref, self.stop_objref), "object": (self.start_object, self.stop_object), "file": (self.start_file, None), + "page": (None, self.stop_page), "place": (self.start_place, self.stop_place), "dateval": (self.start_dateval, None), "daterange": (self.start_daterange, None), @@ -1698,9 +1710,9 @@ class GrampsParser(UpdateCallback): self.note.format = int(attrs.get('format', gen.lib.Note.FLOWED)) # The order in this long if-then statement should reflect the # DTD: most deeply nested elements come first. - if self.source_ref: - self.note.type.set(gen.lib.NoteType.SOURCEREF) - self.note.private = self.source_ref.private + if self.citation: + self.note.type.set(gen.lib.NoteType.CITATION) + self.note.private = self.citation.private elif self.address: self.note.type.set(gen.lib.NoteType.ADDRESS) self.note.private = self.address.private @@ -1774,8 +1786,8 @@ class GrampsParser(UpdateCallback): # The order in this long if-then statement should reflect the # DTD: most deeply nested elements come first. - if self.source_ref: - self.source_ref.add_note(handle) + if self.citation: + self.citation.add_note(handle) elif self.address: self.address.add_note(handle) elif self.ord: @@ -1811,11 +1823,79 @@ class GrampsParser(UpdateCallback): elif self.repo: self.repo.add_note(handle) + def __add_citation(self, citation_handle): + """ + Add a citation to the object currently processed. + """ + if self.photo: + self.photo.add_citation(citation_handle) + elif self.ord: + self.ord.add_citation(citation_handle) + elif self.attribute: + self.attribute.add_citation(citation_handle) + elif self.object: + self.object.add_citation(citation_handle) + elif self.objref: + self.objref.add_citation(citation_handle) + elif self.event: + self.event.add_citation(citation_handle) + elif self.address: + self.address.add_citation(citation_handle) + elif self.name: + self.name.add_citation(citation_handle) + elif self.placeobj: + self.placeobj.add_citation(citation_handle) + elif self.childref: + self.childref.add_citation(citation_handle) + elif self.family: + self.family.add_citation(citation_handle) + elif self.personref: + self.personref.add_citation(citation_handle) + elif self.person: + self.person.add_citation(citation_handle) + + def start_citationref(self, attrs): + """ + Add a citation reference to the object currently processed. + """ + handle = self.inaugurate(attrs['hlink'], gen.lib.Citation, + self.db.has_citation_handle, + self.db.add_citation, + self.db.get_raw_citation_data) + + self.__add_citation(handle) + + def start_citation(self, attrs): + """ + Add a citation object to db if it doesn't exist yet and assign + id, privacy and changetime. + """ + self.update(self.p.CurrentLineNumber) + self.citation = gen.lib.Citation() + orig_handle = attrs['handle'].replace('_', '') + is_merge_candidate = (self.replace_import_handle and + self.db.has_citation_handle(orig_handle)) + self.inaugurate(orig_handle, self.citation, + self.db.has_citation_handle, + self.db.add_citation, + self.db.get_raw_citation_data) + gramps_id = self.legalize_id(attrs.get('id'), CITATION_KEY, + self.cidswap, self.db.cid2user_format, + self.db.find_next_citation_gramps_id) + self.citation.set_gramps_id(gramps_id) + if is_merge_candidate: + orig_citation = self.db.get_citation_from_handle(orig_handle) + self.info.add('merge-candidate', CITATION_KEY, orig_citation, + self.citation) + self.citation.private = bool(attrs.get("priv")) + self.citation.change = int(attrs.get('change', self.change)) + self.citation.confidence = self.conf # default + self.info.add('new-object', CITATION_KEY, self.citation) + def start_sourceref(self, attrs): """ Add a source reference to the object currently processed. """ - self.source_ref = gen.lib.SourceRef() if 'hlink' in attrs: handle = self.inaugurate(attrs['hlink'], gen.lib.Source, self.db.has_source_handle, @@ -1824,36 +1904,22 @@ class GrampsParser(UpdateCallback): else: handle = self.inaugurate_id(attrs.get('ref'), SOURCE_KEY, gen.lib.Source) - self.source_ref.ref = handle - self.source_ref.confidence = int(attrs.get("conf", self.conf)) - self.source_ref.private = bool(attrs.get("priv")) - - if self.photo: - self.photo.add_source_reference(self.source_ref) - elif self.ord: - self.ord.add_source_reference(self.source_ref) - elif self.attribute: - self.attribute.add_source_reference(self.source_ref) - elif self.object: - self.object.add_source_reference(self.source_ref) - elif self.objref: - self.objref.add_source_reference(self.source_ref) - elif self.event: - self.event.add_source_reference(self.source_ref) - elif self.address: - self.address.add_source_reference(self.source_ref) - elif self.name: - self.name.add_source_reference(self.source_ref) - elif self.placeobj: - self.placeobj.add_source_reference(self.source_ref) - elif self.childref: - self.childref.add_source_reference(self.source_ref) - elif self.family: - self.family.add_source_reference(self.source_ref) - elif self.personref: - self.personref.add_source_reference(self.source_ref) - elif self.person: - self.person.add_source_reference(self.source_ref) + + if self.citation: + self.citation.set_reference_handle(handle) + else: + # GRAMPS LEGACY: Prior to v1.5.0 there were no citation objects. + # We need to copy the contents of the old SourceRef into a new + # Citation object. + self.in_old_sourceref = True + + self.citation = gen.lib.Citation() + self.citation.set_reference_handle(handle) + self.citation.confidence = int(attrs.get("conf", self.conf)) + self.citation.private = bool(attrs.get("priv")) + + citation_handle = self.db.add_citation(self.citation, self.trans) + self.__add_citation(citation_handle) def start_source(self, attrs): """ @@ -2066,8 +2132,8 @@ class GrampsParser(UpdateCallback): self.start_compound_date(attrs, gen.lib.Date.MOD_SPAN) def start_compound_date(self, attrs, mode): - if self.source_ref: - date_value = self.source_ref.get_date_object() + if self.citation: + date_value = self.citation.get_date_object() elif self.ord: date_value = self.ord.get_date_object() elif self.object: @@ -2148,8 +2214,8 @@ class GrampsParser(UpdateCallback): newyear=newyear) def start_dateval(self, attrs): - if self.source_ref: - date_value = self.source_ref.get_date_object() + if self.citation: + date_value = self.citation.get_date_object() elif self.ord: date_value = self.ord.get_date_object() elif self.object: @@ -2227,8 +2293,8 @@ class GrampsParser(UpdateCallback): newyear=newyear) def start_datestr(self, attrs): - if self.source_ref: - date_value = self.source_ref.get_date_object() + if self.citation: + date_value = self.citation.get_date_object() elif self.ord: date_value = self.ord.get_date_object() elif self.object: @@ -2531,13 +2597,23 @@ class GrampsParser(UpdateCallback): self.source.title = tag def stop_sourceref(self, *tag): - self.source_ref = None + # if we are in an old style sourceref we need to commit the citation + if self.in_old_sourceref: + self.db.commit_citation(self.citation, self.trans, + self.citation.get_change_time()) + self.citation = None + self.in_old_sourceref = False def stop_source(self, *tag): self.db.commit_source(self.source, self.trans, self.source.get_change_time()) self.source = None + def stop_citation(self, *tag): + self.db.commit_citation(self.citation, self.trans, + self.citation.get_change_time()) + self.citation = None + def stop_sauthor(self, tag): self.source.author = tag @@ -2566,7 +2642,16 @@ class GrampsParser(UpdateCallback): self.address.set_postal_code(tag) def stop_spage(self, tag): - self.source_ref.set_page(tag) + # Valid for version <= 1.4.0 + self.citation.set_page(tag) + + def stop_page(self, tag): + # Valid for version >= 1.5.0 + self.citation.set_page(tag) + + def stop_confidence(self, tag): + # Valid for version >= 1.5.0 + self.citation.set_confidence_level(int(tag)) def stop_lds_ord(self, *tag): self.ord = None @@ -2587,14 +2672,14 @@ class GrampsParser(UpdateCallback): # So we create a new note, commit, and add the handle to note list. note = gen.lib.Note() note.handle = Utils.create_id() - note.private = self.source_ref.private + note.private = self.citation.private note.set(text) note.type.set(gen.lib.NoteType.SOURCE_TEXT) self.db.add_note(note, self.trans) #set correct change time self.db.commit_note(note, self.trans, self.change) self.info.add('new-object', NOTE_KEY, note) - self.source_ref.add_note(note.handle) + self.citation.add_note(note.handle) def stop_scomments(self, tag): if self.use_p: @@ -2604,14 +2689,14 @@ class GrampsParser(UpdateCallback): text = tag note = gen.lib.Note() note.handle = Utils.create_id() - note.private = self.source_ref.private + note.private = self.citation.private note.set(text) - note.type.set(gen.lib.NoteType.SOURCEREF) + note.type.set(gen.lib.NoteType.CITATION) self.db.add_note(note, self.trans) #set correct change time self.db.commit_note(note, self.trans, self.change) self.info.add('new-object', NOTE_KEY, note) - self.source_ref.add_note(note.handle) + self.citation.add_note(note.handle) def stop_last(self, tag): if self.surname: diff --git a/src/plugins/lib/libgrampsxml.py b/src/plugins/lib/libgrampsxml.py index cc2f79869..728474c9e 100644 --- a/src/plugins/lib/libgrampsxml.py +++ b/src/plugins/lib/libgrampsxml.py @@ -35,5 +35,5 @@ # Public Constants # #------------------------------------------------------------------------ -GRAMPS_XML_VERSION = "1.4.0" +GRAMPS_XML_VERSION = "1.5.0"