def WriteXML(self, log, first, last, surnames, places, sources): """ Write the result of the query for distributed, shared protocols """ # Custom XML file in buffer self.lang = xml_lang() self.title = _('I am looking at ...') self.footer = _('Content generated by Gramps') self.surnames_title = _('Surnames') self.places_name = _('Places') self.sources_title = _('List of sources') time = date.Today() xml = etree.Element("query") xml.set("lang", self.lang) xml.set("title", self.title) xml.set("footer", self.footer) xml.set("date", gramps.gen.datehandler.displayer.display(time)) xml.set("first", first) xml.set("last", last) # only for info doc = etree.ElementTree(xml) # custom countries list (re-use some Gramps translations ...) ;) countries = [ '', _('Australia'), _('Brazil'), _('Bulgaria'), _('Canada'), _('Chile'), _('China'), _('Croatia'), _('Czech Republic'), _('England'), _('Finland'), _('France'), _('Germany'), _('India'), _('Japan'), _('Norway'), _('Portugal'), _('Russia'), _('Sweden'), _('United States of America'), ] c = etree.SubElement(xml, "clist") self.name = _('Name') self.country = _('Country') c.set("pname", self.name) c.set("country", self.country) for country in countries: c1 = etree.SubElement(c, "country") c1.text = country # data log [(k1, v1), (k2, v2)] = log l = etree.SubElement(xml, "log") l.set("date", v1) l.set("version", v2) s = etree.SubElement(xml, "surnames") s.set("title", self.surnames_title) surnames.sort() cnt = [] for surname in surnames: if surname not in cnt: s1 = etree.SubElement(s, "surname") s1.text = surname cnt.append(surname) p = etree.SubElement(xml, "places") p.set("pname", self.places_name) places.sort() for place in places: p1 = etree.SubElement(p, "place") p1.text = place src = etree.SubElement(xml, "sources") src.set("title", self.sources_title) sources.sort() for source in sources: src1 = etree.SubElement(src, "source") src1.text = source content = etree.XML(etree.tostring(xml, encoding="UTF-8")) # XSLT process xslt_doc = etree.parse( os.path.join(USER_PLUGINS, 'lxml', 'query_html.xsl')) transform = etree.XSLT(xslt_doc) outdoc = transform(content) #print(type(outdoc)) html = os.path.join(USER_PLUGINS, 'lxml', 'query.html') outfile = open(html, 'w') outfile.write(str(outdoc)) outfile.close() # clear the etree content.clear() # This is the end ! sys.stdout.write(_('1. Has generated "%s".\n') % html) LOG.info( _('Try to open\n "%s"\n into your prefered web navigator ...') % html) display_url(html)
def _setup_fields(self): r''' Gramps XML storage means ability to also import/manage alone records /!\ some attributes are translated keys see data_item keys and eventref types of attribute ''' #/database/repositories/repository/rname/text() self.rinfo = MonitoredText( self.top.get_object("rinfo"), self.top.get_object("rinfo").set_text(self.rinfo), self.top.get_object("rinfo").get_text, True) # date of transcription/search self.rdate = MonitoredText( self.top.get_object("rdate"), self.top.get_object("rdate").set_text(str(date.Today())), #self.top.get_object("rdate").get_date_object(), #uistate, #track, True) #/database/repositories/repository/@handle self.rid = MonitoredEntry(self.top.get_object("rid"), self.top.get_object("rid").set_text, self.top.get_object("rid").get_text, True) #/database/sources/source/stitle/text() self.aname = MonitoredText( self.top.get_object("aname"), self.top.get_object("aname").set_text(self.aname), self.top.get_object("aname").get_text, True) #/database/sources/source/@handle self.aid = MonitoredEntry(self.top.get_object("aid"), self.top.get_object("aid").set_text, self.top.get_object("aid").get_text, True) #/database/citations/citation/@handle self.aref = MonitoredEntry(self.top.get_object("aref"), self.top.get_object("aref").set_text, self.top.get_object("aref").get_text, True) #/database/citations/citation/dateval/@val #self.adate = MonitoredDate( #self.top.get_object("adate"), #self.top.get_object("adate").set_text, #self.top.get_object("adate").get_date_object(), #uistate, #track, #True) #/database/citations/citation/page # hardcoded /database/citations/citation/confidence self.avol = MonitoredEntry( self.top.get_object("avol"), self.top.get_object("avol").set_text(self.avol), self.top.get_object("avol").get_text, True) #/database/people/person/gender #self.gen = MonitoredType( #self.top.get_object("gen"), #self.top.get_object("gen").set_text, #self.top.get_object("gen").get_text, #True) #/database/people/person/childof/@hlink #/database/people/person/name/surname/surname/text() self.pname = MonitoredEntry(self.top.get_object("pname"), self.top.get_object("pname").set_text, self.top.get_object("pname").get_text, True) #/database/people/person/name/first/text() self.pfname = MonitoredText(self.top.get_object("pfname"), self.top.get_object("pfname").set_text, self.top.get_object("pfname").get_text, True) #/database/people/person/eventref/@hlink #/database/events/event/dateval/@val #self.pdate = MonitoredDate( #self.top.get_object("pdate"), #self.top.get_object("pdate_stat"), #self.top.get_object("pdate").get_date_object(), #uistate, #track, #True) #/database/people/person/eventref/@hlink #/database/events/event/place/@hlink #/database/places/placeobj/ptitle/text() #self.pplace = PlaceEntry( #dbstate, uistate, track, #self.top.get_object("pplace"), #self.top.get_object("pplace").set_place_handle, #self.top.get_object("pplace").get_place_handle, #self.top.get_object('add_del_place'), #self.top.get_object('select_place')) #/database/people/person/eventref/noteref/@hlink #/database/notes/note/text/text() #self.pnote = NoteEntry( #dbstate, uistate, track, #self.top.get_object("pnote"), #self.top.get_object("pnote").set_note_handle, #self.top.get_object("pnote").get_note_handle, #self.top.get_object('add_del_note'), #self.top.get_object('select_note')) #/database/objects/object/file/@src #self.fname = MediaEntry( #dbstate, uistate, track, #self.top.get_object("fname"), #self.top.get_object("fname").set_media_path, #self.top.get_object("fname").get_media_path, #self.top.get_object('add_del_path'), #self.top.get_object('select_path')) #/database/people/person/parentin/@hlink #/database/people/person/name/first/text() self.ffname = MonitoredText(self.top.get_object("ffname"), self.top.get_object("ffname").set_text, self.top.get_object("ffname").get_text, True) #/database/people/person/eventref/attribute/@type #/database/people/person/eventref/attribute/@value self.fage = MonitoredEntry(self.top.get_object("fage"), self.top.get_object("fage").set_text, self.top.get_object("fage").get_text, True) #/database/people/person/eventref/@hlink #/database/events/event/place/@hlink #/database/places/placeobj/ptitle/text() #self.forig = PlaceEntry( #dbstate, uistate, track, #self.top.get_object("forig"), #self.top.get_object("forig").set_place_handle, #self.top.get_object("forig").get_place_handle, #self.top.get_object('add_del_place'), #self.top.get_object('select_place')) #/database/people/person/eventref/@hlink #/database/events/event/description/text() self.foccu = MonitoredEntry(self.top.get_object("foccu"), self.top.get_object("foccu").set_text, self.top.get_object("foccu").get_text, True) #/database/people/person/eventref/@hlink #/database/events/event/dateval/@val #/database/events/event/description/text() self.flive = MonitoredEntry(self.top.get_object("flive"), self.top.get_object("flive").set_text, self.top.get_object("flive").get_text, True) #/database/people/person/parentin/@hlink #/database/people/person/name/first/text() self.mname = MonitoredText(self.top.get_object("mname"), self.top.get_object("mname").set_text, self.top.get_object("mname").get_text, True) self.mfname = MonitoredText(self.top.get_object("mfname"), self.top.get_object("mfname").set_text, self.top.get_object("mfname").get_text, True) self.mage = MonitoredText(self.top.get_object("mage"), self.top.get_object("mage").set_text, self.top.get_object("mage").get_text, True) #self.morigin = PlaceEntry( #dbstate, uistate, track, #self.top.get_object("morigin"), #self.top.get_object("morigin").set_place_handle, #self.top.get_object("morigin").get_place_handle, #self.top.get_object('add_del_place'), #self.top.get_object('select_place')) self.moccu = MonitoredText(self.top.get_object("moccu"), self.top.get_object("moccu").set_text, self.top.get_object("moccu").get_text, True) self.mlive = MonitoredEntry(self.top.get_object("mlive"), self.top.get_object("mlive").set_text, self.top.get_object("mlive").get_text, True) self.msname = MonitoredText(self.top.get_object("msname"), self.top.get_object("msname").set_text, self.top.get_object("msname").get_text, True)