From 29022a6f1e73eac42824f985b88bce6f99bc7217 Mon Sep 17 00:00:00 2001 From: Alex Roitman Date: Fri, 14 Oct 2005 00:25:22 +0000 Subject: [PATCH] * src/WriteXML.py (write_xml_data): Use ISO date in the created attribute; (get_iso_date): Return empty string on empty date; (write_date): Write quality attributes, if any. * src/ReadXML.py (start_daterange,start_dateval): Parse quality attributes. svn: r5315 --- gramps2/ChangeLog | 5 +++++ gramps2/doc/grampsxml.dtd | 8 ++++--- gramps2/doc/grampsxml.rng | 10 ++++++++- gramps2/src/ReadXML.py | 26 ++++++++++++++++++++-- gramps2/src/WriteXML.py | 46 +++++++++++++++++++++++++++------------ 5 files changed, 75 insertions(+), 20 deletions(-) diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index 2f2b2f803..f5785e3d7 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -2,6 +2,11 @@ * example/gramps/data.gramps: Update example data to conform with the format changes and the DTD. * doc/grampsxml.dtd, doc/grampsxml.rng: Update. + * src/WriteXML.py (write_xml_data): Use ISO date in the created + attribute; (get_iso_date): Return empty string on empty date; + (write_date): Write quality attributes, if any. + * src/ReadXML.py (start_daterange,start_dateval): Parse quality + attributes. 2005-10-13 Martin Hawlisch * src/plugins/TestcaseGenerator.py: Randomize more; Add LDS events diff --git a/gramps2/doc/grampsxml.dtd b/gramps2/doc/grampsxml.dtd index 61524f50a..0fbc78510 100644 --- a/gramps2/doc/grampsxml.dtd +++ b/gramps2/doc/grampsxml.dtd @@ -256,14 +256,16 @@ SHARED ELEMENTS diff --git a/gramps2/doc/grampsxml.rng b/gramps2/doc/grampsxml.rng index 37af07ba9..a289e0d9f 100644 --- a/gramps2/doc/grampsxml.rng +++ b/gramps2/doc/grampsxml.rng @@ -38,7 +38,7 @@ - + @@ -229,6 +229,10 @@ + + estimated + calculated + @@ -239,6 +243,10 @@ after about + + estimated + calculated + diff --git a/gramps2/src/ReadXML.py b/gramps2/src/ReadXML.py index b1d9e3b52..d81dd2419 100644 --- a/gramps2/src/ReadXML.py +++ b/gramps2/src/ReadXML.py @@ -990,7 +990,18 @@ class GrampsParser: else: cal = Date.CAL_GREGORIAN - dv.set(Date.QUAL_NONE,Date.MOD_RANGE,cal,(d,m,y,False,rd,rm,ry,False)) + if attrs.has_key('quality'): + val = attrs['quality'] + if val == 'estimated': + qual = Date.QUAL_ESTIMATED + elif val == 'calculated': + qual = Date.QUAL_CALCULATED + else: + qual = Date.QUAL_NONE + else: + qual = Date.QUAL_NONE + + dv.set(qual,Date.MOD_RANGE,cal,(d,m,y,False,rd,rm,ry,False)) def start_dateval(self,attrs): if self.source_ref: @@ -1042,8 +1053,19 @@ class GrampsParser: mod = Date.MOD_BEFORE else: mod = Date.MOD_NONE + + if attrs.has_key('quality'): + val = attrs['quality'] + if val == 'estimated': + qual = Date.QUAL_ESTIMATED + elif val == 'calculated': + qual = Date.QUAL_CALCULATED + else: + qual = Date.QUAL_NONE + else: + qual = Date.QUAL_NONE - dv.set(Date.QUAL_NONE,mod,cal,(d,m,y,False)) + dv.set(qual,mod,cal,(d,m,y,False)) def start_datestr(self,attrs): if self.source_ref: diff --git a/gramps2/src/WriteXML.py b/gramps2/src/WriteXML.py index b20893a1c..e1a3c0e20 100644 --- a/gramps2/src/WriteXML.py +++ b/gramps2/src/WriteXML.py @@ -197,7 +197,7 @@ class XmlWriter: def write_xml_data(self): - date = time.ctime(time.time()).split() + date = time.localtime(time.time()) owner = self.db.get_researcher() person_len = self.db.get_number_of_people() family_len = len(self.db.get_family_handles()) @@ -212,11 +212,10 @@ class XmlWriter: 'PUBLIC "-//GRAMPS//DTD GRAMPS XML V%s//EN"\n' '"http://gramps-project.org/xml/%s/grampsxml.dtd">\n' % (_xml_version,_xml_version)) - self.g.write("\n") self.g.write("
\n") - self.g.write(" \n") self.g.write(" \n") @@ -614,7 +613,12 @@ class XmlWriter: d = '' else: d = "-%02d" % date[0] - return "%s%s%s" % (y,m,d) + ret = "%s%s%s" % (y,m,d) + # If the result does not contain anything beyond dashes + # and question marks then it's as good as empty + if ret.replace('-','').replace('?','') == '': + ret = '' + return ret def write_date(self,date,indent=1): sp = ' '*indent @@ -625,27 +629,41 @@ class XmlWriter: else: calstr = '' + qual = date.get_quality() + if qual == Date.QUAL_ESTIMATED: + qual_str = ' quality="estimated"' + elif qual == Date.QUAL_CALCULATED: + qual_str = ' quality="calculated"' + else: + qual_str = "" + mode = date.get_modifier() if date.is_compound(): d1 = self.get_iso_date(date.get_start_date()) d2 = self.get_iso_date(date.get_stop_date()) - self.g.write('%s\n' % (sp,d1,d2,calstr)) + if d1 != "" or d2 != "": + self.g.write('%s\n' + % (sp,d1,d2,qual_str,calstr)) elif mode != Date.MOD_TEXTONLY: - dstr = self.get_iso_date(date.get_start_date()) + date_str = self.get_iso_date(date.get_start_date()) + if date_str == "": + return if mode == Date.MOD_BEFORE: - pref = ' type="before"' + mode_str = ' type="before"' elif mode == Date.MOD_AFTER: - pref = ' type="after"' + mode_str = ' type="after"' elif mode == Date.MOD_ABOUT: - pref = ' type="about"' + mode_str = ' type="about"' else: - pref = "" - - self.g.write('%s\n' % (sp,dstr,pref,calstr)) + mode_str = "" + + self.g.write('%s\n' + % (sp,date_str,mode_str,qual_str,calstr)) else: - self.g.write('%s\n' %(sp,self.fix(date.get_text()))) + self.g.write('%s\n' + %(sp,self.fix(date.get_text()))) def write_force_line(self,label,value,indent=1): if value != None: