Exemple #1
0
def gjsonIter(rows, titleslist, typelist):  ###does not support date type

    import json
    # response={"cols":[],"rows":[]}
    yield '{"cols": '
    header = []
    first = True
    for name, type, num in zip(titleslist, typelist, xrange(len(titleslist))):
        id = latinnum(num + 1)
        header += [{"id": id, "label": name, "type": type}]
    yield json.dumps(header, sort_keys=True)
    yield ', "rows": ['
    for row in rows:
        rowdict = {"c": []}
        for val, type in zip(row, typelist):
            if type == "number":
                try:
                    rowdict["c"] += [{"v": numeric(val)}]
                except ValueError:
                    raise ValueError("Type problem in %s:\nRow:%sTypes:%s" %
                                     (val, row, typelist))
            else:
                rowdict["c"] += [{"v": val}]
        if not first:
            yield ', ' + json.dumps(rowdict, sort_keys=True)
        else:
            yield json.dumps(rowdict, sort_keys=True)
        first = False
    yield ']}'

    return
Exemple #2
0
def gjsonIter(rows,titleslist,typelist): ###does not support date type

    import json
    #response={"cols":[],"rows":[]}
    yield '{"cols": '
    header=[]
    first=True
    for name, type,num in zip(titleslist, typelist,xrange(len(titleslist))):
        id=latinnum(num+1)
        header+=[{"id":id, "label":name,"type":type}]
    yield json.dumps(header,sort_keys=True)
    yield ', "rows": ['
    for row in rows:
        rowdict={"c":[]}
        for val,type in zip(row, typelist):
            if type=="number":
                try:
                    rowdict["c"]+=[{"v":numeric(val)}]
                except ValueError:
                    raise ValueError("Type problem in %s:\nRow:%sTypes:%s" %(val,row,typelist))
            else:
                rowdict["c"]+=[{"v":val}]
        if not first:
            yield ', '+json.dumps(rowdict,sort_keys=True)
        else:
             yield json.dumps(rowdict,sort_keys=True)
        first=False
    yield ']}'
    
    return 
Exemple #3
0
def gjsonFull(rows,titleslist,typelist): ###does not support date type

    import json
    response={"cols":[],"rows":[]}    
    for name, type,num in zip(titleslist, typelist,xrange(len(titleslist))):
        id=latinnum(num+1)
        response["cols"]+=[{"id":id, "label":name,"type":type}]
    for row in rows:
        rowdict={"c":[]}
        for val,type in zip(row, typelist):
            if type=="number":
                try:
                    rowdict["c"]+=[{"v":numeric(val)}]
                except ValueError:
                    raise ValueError("Type problem in %s:\nRow:%sTypes:%s" %(val,row,typelist))
            else:
                rowdict["c"]+=[{"v":val}]
        response["rows"]+=[rowdict]
    
    return json.dumps(response,sort_keys=True)
Exemple #4
0
def gjsonFull(rows, titleslist, typelist):  ###does not support date type

    import json
    response = {"cols": [], "rows": []}
    for name, type, num in zip(titleslist, typelist, xrange(len(titleslist))):
        id = latinnum(num + 1)
        response["cols"] += [{"id": id, "label": name, "type": type}]
    for row in rows:
        rowdict = {"c": []}
        for val, type in zip(row, typelist):
            if type == "number":
                try:
                    rowdict["c"] += [{"v": numeric(val)}]
                except ValueError:
                    raise ValueError("Type problem in %s:\nRow:%sTypes:%s" %
                                     (val, row, typelist))
            else:
                rowdict["c"] += [{"v": val}]
        response["rows"] += [rowdict]

    return json.dumps(response, sort_keys=True)