def toList(s, listid, dialname=None, listname=None): elem = JsonParser().parse(s) object = elem.getAsJsonObject() array = object.getAsJsonArray(listid) list = [] lform = None if dialname != None: lform = miscutil.toListMap(dialname, listname) for i in range(array.size()): ma = {} o = array.get(i) # print i,o s = o.entrySet() for e in s: # print e,e.getKey(),e.getValue() if e.getValue().isJsonNull(): val = None else: if lform != None: (ttype, after) = miscutil.getColumnDescr(lform, e.getKey()) p = o.getAsJsonPrimitive(e.getKey()) if p.isBoolean(): val = p.getAsBoolean() elif p.isNumber(): val = p.getAsDouble() if lform != None: if ttype == cutil.LONG: val = int(val) else: val = p.getAsString() if lform != None: if ttype == cutil.DATE: val = con.StoDate(val) if ttype == cutil.DATETIME: val = con.StoDate(val, True) ma[e.getKey()] = val list.append(ma) return list
def toList(s,listid,dialname=None,listname=None) : elem = JsonParser().parse(s) object = elem.getAsJsonObject() array = object.getAsJsonArray(listid) list=[] lform = None if dialname != None : lform = miscutil.toListMap(dialname,listname) for i in range (array.size()) : ma = {} o = array.get(i) # print i,o s = o.entrySet() for e in s : # print e,e.getKey(),e.getValue() if e.getValue().isJsonNull() : val = None else : if lform != None : (ttype,after) = miscutil.getColumnDescr(lform,e.getKey()) p = o.getAsJsonPrimitive(e.getKey()) if p.isBoolean() : val = p.getAsBoolean() elif p.isNumber() : val = p.getAsDouble() if lform != None : if ttype == cutil.LONG : val = int(val) else : val = p.getAsString() if lform != None : if ttype == cutil.DATE : val = con.StoDate(val) if ttype == cutil.DATETIME : val = con.StoDate(val,True) ma[e.getKey()] = val list.append(ma) return list
def toFormat(format,jsondata,jsonform,dialogname,listname): lform = miscutil.toListMap(dialogname,listname) assert lform != None listform = jsutil.toList(jsonform,LIST) jdata = jsutil.toList(jsondata,LIST,dialogname,listname) vis = _toVisMap(listform) if format == XML : li = [] for j in jdata : ma = {} for k in j.keys() : if k in vis : ma[k] = j[k] li.append(ma) return xmlutil.toXML({},li) if format == JSON : return jsondata if format == CSV : return _toCSV(jdata,lform,listform,vis) html = _toHTML(jdata,lform,listform,vis) if format == HTML : return html return pdfutil.createPDFH(html)
def dialogaction(action, var): cutil.printVar('js', action, var) if action == 'test1': s = "{'list':[{'visible':true, 'id':'id', 'columnname':'Next num'},{'visible':true, 'id':'number0', 'columnname':'Number'},{'visible':true, 'id':'number1', 'columnname':'Number 1'},{'visible':true, 'id':'number2', 'columnname':'Number 2'},{'visible':true, 'id':'number3', 'columnname':'Number 3'},{'visible':true, 'id':'number4', 'columnname':'Number 4'}]}" a = jsutil.toList(s, 'list') print len(a) assert len(a) == 6 for e in a: print e["visible"], e["id"], e["columnname"] assert e["visible"] var["OK"] = True if action == 'test2': s = "{'list':[{'id':1, 'number0':123, 'number1':333.7, 'number2':null, 'number3':null, 'number4':null},{'id':2, 'number0':78, 'number1':4, 'number2':null, 'number3':1.987, 'number4':3.4555}]}" a = jsutil.toList(s, 'list') print a print len(a) assert 2 == len(a) assert a[0][u'number3'] == None assert a[0][u'number1'] == 333.7 var["OK"] = True if action == 'test3': dlist = miscutil.toListMap("test107.xml", "lista") assert dlist != None (dtype, afterdot) = miscutil.getColumnDescr(dlist, "id") print dtype, afterdot assert "int" == dtype assert 0 == afterdot (dtype, afterdot) = miscutil.getColumnDescr(dlist, "mon") print dtype, afterdot assert "decimal" == dtype assert 3 == afterdot (dtype, afterdot) = miscutil.getColumnDescr(dlist, "bol") print dtype, afterdot assert "boolean" == dtype assert 0 == afterdot (dtype, afterdot) = miscutil.getColumnDescr(dlist, "dat") print dtype, afterdot assert "date" == dtype assert 0 == afterdot var["OK"] = True if action == 'test4': s = "{'list':[{'id':1, 'number0':123, 'number1':333.7, 'number2':null, 'number3':null, 'number4':null},{'id':2, 'number0':78, 'number1':4, 'number2':null, 'number3':1.987, 'number4':3.4555}]}" a = jsutil.toList(s, 'list', "test107.xml", "list1") print a assert 2 == len(a) print type(a[0]['id']) assert (type(a[0]['id']) == int) var["OK"] = True if action == "test5": d = "2017/01/14" t = "2017/01/14 20:45:14" da = con.StoDate(d) print da assert 2017 == da.year assert 1 == da.month assert 14 == da.day ta = con.StoDate(t, True) print ta assert 20 == ta.hour assert 45 == ta.minute assert 14 == ta.second var["OK"] = True if action == "test6": s = "{'list':[{'timef':'2017/01/14 20:45:14', 'keyf':null},{'timef':'2017/01/15 20:45:14', 'keyf':null},{'timef':'2017/01/16 20:45:14', 'keyf':null},{'timef':'2017/01/17 20:45:14', 'keyf':null},{'timef':'2017/01/18 20:45:14', 'keyf':null},{'timef':'2017/01/19 20:45:14', 'keyf':null},{'timef':'2017/01/20 20:45:14', 'keyf':null},{'timef':'2017/01/21 20:45:14', 'keyf':null},{'timef':'2017/01/22 20:45:14', 'keyf':null},{'timef':'2017/01/23 20:45:14', 'keyf':null},{'timef':'2017/01/24 20:45:14', 'keyf':null},{'timef':'2017/01/25 20:45:14', 'keyf':null},{'timef':'2017/01/26 20:45:14', 'keyf':null},{'timef':'2017/01/27 20:45:14', 'keyf':null},{'timef':'2017/01/28 20:45:14', 'keyf':null},{'timef':'2017/01/29 20:45:14', 'keyf':null},{'timef':'2017/01/30 20:45:14', 'keyf':null},{'timef':'2017/01/31 20:45:14', 'keyf':null},{'timef':'2017/02/01 20:45:14', 'keyf':null},{'timef':'2017/02/02 20:45:14', 'keyf':null},{'timef':'2017/02/03 20:45:14', 'keyf':null},{'timef':'2017/02/04 20:45:14', 'keyf':null},{'timef':'2017/02/05 20:45:14', 'keyf':null},{'timef':'2017/02/06 20:45:14', 'keyf':null},{'timef':'2017/02/07 20:45:14', 'keyf':null},{'timef':'2017/02/08 20:45:14', 'keyf':null},{'timef':'2017/02/09 20:45:14', 'keyf':null},{'timef':'2017/02/10 20:45:14', 'keyf':null},{'timef':'2017/02/11 20:45:14', 'keyf':null},{'timef':'2017/02/12 20:45:14', 'keyf':null},{'timef':'2017/02/13 20:45:14', 'keyf':null},{'timef':'2017/02/14 20:45:14', 'keyf':null},{'timef':'2017/02/15 20:45:14', 'keyf':null},{'timef':'2017/02/16 20:45:14', 'keyf':null},{'timef':'2017/02/17 20:45:14', 'keyf':null},{'timef':'2017/02/18 20:45:14', 'keyf':null},{'timef':'2017/02/19 20:45:14', 'keyf':null},{'timef':'2017/02/20 20:45:14', 'keyf':null},{'timef':'2017/02/21 20:45:14', 'keyf':null},{'timef':'2017/02/22 20:45:14', 'keyf':null},{'timef':'2017/02/23 20:45:14', 'keyf':null},{'timef':'2017/02/24 20:45:14', 'keyf':null},{'timef':'2017/02/25 20:45:14', 'keyf':null},{'timef':'2017/02/26 20:45:14', 'keyf':null},{'timef':'2017/02/27 20:45:14', 'keyf':null},{'timef':'2017/02/28 20:45:14', 'keyf':null},{'timef':'2017/03/01 20:45:14', 'keyf':null},{'timef':'2017/03/02 20:45:14', 'keyf':null},{'timef':'2017/03/03 20:45:14', 'keyf':null},{'timef':'2017/03/04 20:45:14', 'keyf':null},{'timef':'2017/03/05 20:45:14', 'keyf':null},{'timef':'2017/03/06 20:45:14', 'keyf':null},{'timef':'2017/03/07 20:45:14', 'keyf':null},{'timef':'2017/03/08 20:45:14', 'keyf':null},{'timef':'2017/03/09 20:45:14', 'keyf':null},{'timef':'2017/03/10 20:45:14', 'keyf':null},{'timef':'2017/03/11 20:45:14', 'keyf':null},{'timef':'2017/03/12 20:45:14', 'keyf':null},{'timef':'2017/03/13 20:45:14', 'keyf':null},{'timef':'2017/03/14 20:45:14', 'keyf':null},{'timef':'2017/03/15 20:45:14', 'keyf':null},{'timef':'2017/03/16 20:45:14', 'keyf':null},{'timef':'2017/03/17 20:45:14', 'keyf':null},{'timef':'2017/03/18 20:45:14', 'keyf':null},{'timef':'2017/03/19 20:45:14', 'keyf':null},{'timef':'2017/03/20 20:45:14', 'keyf':null},{'timef':'2017/03/21 20:45:14', 'keyf':null},{'timef':'2017/03/22 20:45:14', 'keyf':null},{'timef':'2017/03/23 20:45:14', 'keyf':null},{'timef':'2017/03/24 20:45:14', 'keyf':null},{'timef':'2017/03/25 20:45:14', 'keyf':null},{'timef':'2017/03/26 21:45:14', 'keyf':null},{'timef':'2017/03/27 21:45:14', 'keyf':null},{'timef':'2017/03/28 21:45:14', 'keyf':null},{'timef':'2017/03/29 21:45:14', 'keyf':null},{'timef':'2017/03/30 21:45:14', 'keyf':null},{'timef':'2017/03/31 21:45:14', 'keyf':null},{'timef':'2017/04/01 20:45:14', 'keyf':null},{'timef':'2017/04/02 20:45:14', 'keyf':null},{'timef':'2017/04/03 20:45:14', 'keyf':null},{'timef':'2017/04/04 20:45:14', 'keyf':null},{'timef':'2017/04/05 20:45:14', 'keyf':null},{'timef':'2017/04/06 20:45:14', 'keyf':null},{'timef':'2017/04/07 20:45:14', 'keyf':null},{'timef':'2017/04/08 20:45:14', 'keyf':null},{'timef':'2017/04/09 20:45:14', 'keyf':null},{'timef':'2017/04/10 20:45:14', 'keyf':null},{'timef':'2017/04/11 20:45:14', 'keyf':null},{'timef':'2017/04/12 20:45:14', 'keyf':null},{'timef':'2017/04/13 20:45:14', 'keyf':null},{'timef':'2017/04/14 20:45:14', 'keyf':null},{'timef':'2017/04/15 20:45:14', 'keyf':null},{'timef':'2017/04/16 20:45:14', 'keyf':null},{'timef':'2017/04/17 20:45:14', 'keyf':null},{'timef':'2017/04/18 20:45:14', 'keyf':null},{'timef':'2017/04/19 20:45:14', 'keyf':null},{'timef':'2017/04/20 20:45:14', 'keyf':null},{'timef':'2017/04/21 20:45:14', 'keyf':null},{'timef':'2017/04/22 20:45:14', 'keyf':null},{'timef':'2017/04/23 20:45:14', 'keyf':null}]}" a = jsutil.toList(s, 'list', "test107.xml", "list2") print len(a) assert 100 == len(a) for e in a: # print e assert type(e['timef']) == datetime.datetime var["OK"] = True if action == "test7": formatS = FORMATS dataS = DATAS xml = toformat.toFormat("xml", dataS, formatS, "test107.xml", "list1") print xml assert xml != None var["OK"] = True if action == "test8": formatS = FORMATS dataS = DATAS xml = toformat.toFormat("csv", dataS, formatS, "test107.xml", "list1") print xml assert xml != None var["OK"] = True if action == "test9": formatS = FORMATS dataS = DATAS xml = toformat.toFormat("html", dataS, formatS, "test107.xml", "list1") print xml assert xml != None var_file = open("/tmp/test.html", "w") var_file.write(xml) var_file.close() var["OK"] = True if action == "test10": formatS = FORMATS dataS = DATAS pdf = toformat.toFormat("pdf", dataS, formatS, "test107.xml", "list1") print pdf assert pdf != None var_file = open("/tmp/test.pdf", "wb") var_file.write(pdf) var_file.close() var["OK"] = True if action == "test11": formatS = CHECKFORMATS dataS = CHECKDATAS pdf = toformat.toFormat("pdf", dataS, formatS, "test107.xml", "list3") print pdf assert pdf != None var_file = open("/tmp/test.pdf", "wb") var_file.write(pdf) var_file.close() csv = toformat.toFormat("csv", dataS, formatS, "test107.xml", "list3") print csv xml = toformat.toFormat("xml", dataS, formatS, "test107.xml", "list3") print xml var["OK"] = True
def dialogaction(action,var): cutil.printVar('js',action,var) if action == 'test1' : s = "{'list':[{'visible':true, 'id':'id', 'columnname':'Next num'},{'visible':true, 'id':'number0', 'columnname':'Number'},{'visible':true, 'id':'number1', 'columnname':'Number 1'},{'visible':true, 'id':'number2', 'columnname':'Number 2'},{'visible':true, 'id':'number3', 'columnname':'Number 3'},{'visible':true, 'id':'number4', 'columnname':'Number 4'}]}" a = jsutil.toList(s,'list') print len(a) assert len(a) == 6 for e in a : print e["visible"],e["id"],e["columnname"] assert e["visible"] var["OK"] = True if action == 'test2' : s = "{'list':[{'id':1, 'number0':123, 'number1':333.7, 'number2':null, 'number3':null, 'number4':null},{'id':2, 'number0':78, 'number1':4, 'number2':null, 'number3':1.987, 'number4':3.4555}]}" a = jsutil.toList(s,'list') print a print len(a) assert 2 == len(a) assert a[0][u'number3'] == None assert a[0][u'number1'] == 333.7 var["OK"] = True if action == 'test3' : dlist = miscutil.toListMap("test107.xml","lista") assert dlist != None (dtype,afterdot) = miscutil.getColumnDescr(dlist,"id") print dtype,afterdot assert "int" == dtype assert 0 == afterdot (dtype,afterdot) = miscutil.getColumnDescr(dlist,"mon") print dtype,afterdot assert "decimal" == dtype assert 3 == afterdot (dtype,afterdot) = miscutil.getColumnDescr(dlist,"bol") print dtype,afterdot assert "boolean" == dtype assert 0 == afterdot (dtype,afterdot) = miscutil.getColumnDescr(dlist,"dat") print dtype,afterdot assert "date" == dtype assert 0 == afterdot var["OK"] = True if action == 'test4' : s = "{'list':[{'id':1, 'number0':123, 'number1':333.7, 'number2':null, 'number3':null, 'number4':null},{'id':2, 'number0':78, 'number1':4, 'number2':null, 'number3':1.987, 'number4':3.4555}]}" a = jsutil.toList(s,'list',"test107.xml","list1") print a assert 2 == len(a) print type(a[0]['id']) assert (type(a[0]['id']) == int) var["OK"] = True if action == "test5" : d = "2017/01/14" t = "2017/01/14 20:45:14" da = con.StoDate(d) print da assert 2017 == da.year assert 1 == da.month assert 14 == da.day ta = con.StoDate(t,True) print ta assert 20 == ta.hour assert 45 == ta.minute assert 14 == ta.second var["OK"] = True if action == "test6" : s = "{'list':[{'timef':'2017/01/14 20:45:14', 'keyf':null},{'timef':'2017/01/15 20:45:14', 'keyf':null},{'timef':'2017/01/16 20:45:14', 'keyf':null},{'timef':'2017/01/17 20:45:14', 'keyf':null},{'timef':'2017/01/18 20:45:14', 'keyf':null},{'timef':'2017/01/19 20:45:14', 'keyf':null},{'timef':'2017/01/20 20:45:14', 'keyf':null},{'timef':'2017/01/21 20:45:14', 'keyf':null},{'timef':'2017/01/22 20:45:14', 'keyf':null},{'timef':'2017/01/23 20:45:14', 'keyf':null},{'timef':'2017/01/24 20:45:14', 'keyf':null},{'timef':'2017/01/25 20:45:14', 'keyf':null},{'timef':'2017/01/26 20:45:14', 'keyf':null},{'timef':'2017/01/27 20:45:14', 'keyf':null},{'timef':'2017/01/28 20:45:14', 'keyf':null},{'timef':'2017/01/29 20:45:14', 'keyf':null},{'timef':'2017/01/30 20:45:14', 'keyf':null},{'timef':'2017/01/31 20:45:14', 'keyf':null},{'timef':'2017/02/01 20:45:14', 'keyf':null},{'timef':'2017/02/02 20:45:14', 'keyf':null},{'timef':'2017/02/03 20:45:14', 'keyf':null},{'timef':'2017/02/04 20:45:14', 'keyf':null},{'timef':'2017/02/05 20:45:14', 'keyf':null},{'timef':'2017/02/06 20:45:14', 'keyf':null},{'timef':'2017/02/07 20:45:14', 'keyf':null},{'timef':'2017/02/08 20:45:14', 'keyf':null},{'timef':'2017/02/09 20:45:14', 'keyf':null},{'timef':'2017/02/10 20:45:14', 'keyf':null},{'timef':'2017/02/11 20:45:14', 'keyf':null},{'timef':'2017/02/12 20:45:14', 'keyf':null},{'timef':'2017/02/13 20:45:14', 'keyf':null},{'timef':'2017/02/14 20:45:14', 'keyf':null},{'timef':'2017/02/15 20:45:14', 'keyf':null},{'timef':'2017/02/16 20:45:14', 'keyf':null},{'timef':'2017/02/17 20:45:14', 'keyf':null},{'timef':'2017/02/18 20:45:14', 'keyf':null},{'timef':'2017/02/19 20:45:14', 'keyf':null},{'timef':'2017/02/20 20:45:14', 'keyf':null},{'timef':'2017/02/21 20:45:14', 'keyf':null},{'timef':'2017/02/22 20:45:14', 'keyf':null},{'timef':'2017/02/23 20:45:14', 'keyf':null},{'timef':'2017/02/24 20:45:14', 'keyf':null},{'timef':'2017/02/25 20:45:14', 'keyf':null},{'timef':'2017/02/26 20:45:14', 'keyf':null},{'timef':'2017/02/27 20:45:14', 'keyf':null},{'timef':'2017/02/28 20:45:14', 'keyf':null},{'timef':'2017/03/01 20:45:14', 'keyf':null},{'timef':'2017/03/02 20:45:14', 'keyf':null},{'timef':'2017/03/03 20:45:14', 'keyf':null},{'timef':'2017/03/04 20:45:14', 'keyf':null},{'timef':'2017/03/05 20:45:14', 'keyf':null},{'timef':'2017/03/06 20:45:14', 'keyf':null},{'timef':'2017/03/07 20:45:14', 'keyf':null},{'timef':'2017/03/08 20:45:14', 'keyf':null},{'timef':'2017/03/09 20:45:14', 'keyf':null},{'timef':'2017/03/10 20:45:14', 'keyf':null},{'timef':'2017/03/11 20:45:14', 'keyf':null},{'timef':'2017/03/12 20:45:14', 'keyf':null},{'timef':'2017/03/13 20:45:14', 'keyf':null},{'timef':'2017/03/14 20:45:14', 'keyf':null},{'timef':'2017/03/15 20:45:14', 'keyf':null},{'timef':'2017/03/16 20:45:14', 'keyf':null},{'timef':'2017/03/17 20:45:14', 'keyf':null},{'timef':'2017/03/18 20:45:14', 'keyf':null},{'timef':'2017/03/19 20:45:14', 'keyf':null},{'timef':'2017/03/20 20:45:14', 'keyf':null},{'timef':'2017/03/21 20:45:14', 'keyf':null},{'timef':'2017/03/22 20:45:14', 'keyf':null},{'timef':'2017/03/23 20:45:14', 'keyf':null},{'timef':'2017/03/24 20:45:14', 'keyf':null},{'timef':'2017/03/25 20:45:14', 'keyf':null},{'timef':'2017/03/26 21:45:14', 'keyf':null},{'timef':'2017/03/27 21:45:14', 'keyf':null},{'timef':'2017/03/28 21:45:14', 'keyf':null},{'timef':'2017/03/29 21:45:14', 'keyf':null},{'timef':'2017/03/30 21:45:14', 'keyf':null},{'timef':'2017/03/31 21:45:14', 'keyf':null},{'timef':'2017/04/01 20:45:14', 'keyf':null},{'timef':'2017/04/02 20:45:14', 'keyf':null},{'timef':'2017/04/03 20:45:14', 'keyf':null},{'timef':'2017/04/04 20:45:14', 'keyf':null},{'timef':'2017/04/05 20:45:14', 'keyf':null},{'timef':'2017/04/06 20:45:14', 'keyf':null},{'timef':'2017/04/07 20:45:14', 'keyf':null},{'timef':'2017/04/08 20:45:14', 'keyf':null},{'timef':'2017/04/09 20:45:14', 'keyf':null},{'timef':'2017/04/10 20:45:14', 'keyf':null},{'timef':'2017/04/11 20:45:14', 'keyf':null},{'timef':'2017/04/12 20:45:14', 'keyf':null},{'timef':'2017/04/13 20:45:14', 'keyf':null},{'timef':'2017/04/14 20:45:14', 'keyf':null},{'timef':'2017/04/15 20:45:14', 'keyf':null},{'timef':'2017/04/16 20:45:14', 'keyf':null},{'timef':'2017/04/17 20:45:14', 'keyf':null},{'timef':'2017/04/18 20:45:14', 'keyf':null},{'timef':'2017/04/19 20:45:14', 'keyf':null},{'timef':'2017/04/20 20:45:14', 'keyf':null},{'timef':'2017/04/21 20:45:14', 'keyf':null},{'timef':'2017/04/22 20:45:14', 'keyf':null},{'timef':'2017/04/23 20:45:14', 'keyf':null}]}" a = jsutil.toList(s,'list',"test107.xml","list2") print len(a) assert 100 == len(a) for e in a : # print e assert type(e['timef']) == datetime.datetime var["OK"] = True if action == "test7" : formatS = FORMATS dataS = DATAS xml = toformat.toFormat("xml",dataS,formatS,"test107.xml","list1") print xml assert xml != None var["OK"] = True if action == "test8" : formatS = FORMATS dataS = DATAS xml = toformat.toFormat("csv",dataS,formatS,"test107.xml","list1") print xml assert xml != None var["OK"] = True if action == "test9" : formatS = FORMATS dataS = DATAS xml = toformat.toFormat("html",dataS,formatS,"test107.xml","list1") print xml assert xml != None var_file = open("/tmp/test.html","w") var_file.write(xml) var_file.close() var["OK"] = True if action == "test10" : formatS = FORMATS dataS = DATAS pdf = toformat.toFormat("pdf",dataS,formatS,"test107.xml","list1") print pdf assert pdf != None var_file = open("/tmp/test.pdf","wb") var_file.write(pdf) var_file.close() var["OK"] = True if action == "test11" : formatS = CHECKFORMATS dataS = CHECKDATAS pdf = toformat.toFormat("pdf",dataS,formatS,"test107.xml","list3") print pdf assert pdf != None var_file = open("/tmp/test.pdf","wb") var_file.write(pdf) var_file.close() csv = toformat.toFormat("csv",dataS,formatS,"test107.xml","list3") print csv xml = toformat.toFormat("xml",dataS,formatS,"test107.xml","list3") print xml var["OK"] = True