12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- ### @Jason
- ### Code Generator @ 2019.09.03
- ### RealGen
- import json
- import os
- from Config import class_meta, fangan_meta
- def gen_for_controls(meta):
- for one in meta.get("searchMeta").get("controls"):
- type = "Unknown"
- extra = ""
- js_type = one.get("dataType")
- if js_type == "String":
- type = "Text"
- extra = ", max_length = 100"
- if js_type == "int" or js_type == "Timestamp":
- type = "Integer"
- if js_type == "float" or js_type == "double":
- type = "Float"
- name = str(one.get("name"))
- read_name = name
- if one.get("caption") is not None:
- read_name =one.get("caption")
- print("%s = models.%sField(u'%s'%s) ### %s" % (name.lower(), type, read_name, extra, one.get("dataType")))
- def read_meta_from_data(file_name):
- all_names = []
- with open(file_name, "rb") as input_file:
- bytes_in_file = input_file.read()
- try:
- strme = bytes_in_file.decode("UTF-8")
- except:
- strme = bytes_in_file.decode("GBK")
- local_obj = dict(json.loads(strme))
- datas = dict(local_obj.get("datas"))
- for model_key in datas.keys():
- print("\nKey : %s \n" % model_key)
- rows = datas.get(model_key).get("rows")
- for each in rows:
- for k,v in each.items():
- if isinstance(v, float):
- all_names.append({"name": k, "kind": "Float", "val":v})
- elif isinstance(v, int):
- all_names.append({"name": k, "kind": "Integer", "val":v})
- elif isinstance(v, str):
- all_names.append({"name": k, "kind": "Text", "extra": "String", "val": v})
- elif v is None:
- all_names.append({"name": k, "kind": "Text", "extra": "NoneType", "val":v})
- else:
- all_names.append({"name": k, "kind": "Unknown", "extra": "Unknown", "val": v})
- return all_names
- pass
- if __name__ == "__main__":
- print ("Class Meta:")
- print (class_meta)
- gen_for_controls(class_meta)
- print ("Fangan Meta:")
- print (fangan_meta)
- gen_for_controls(fangan_meta)
- print("\n\n\n\nfanganode.json")
- all_names = read_meta_from_data(os.path.join(os.path.dirname(__file__), "static", "All", "0a0fa2e3b5fb43458ef1ccb8ef5e3ca7_369d8f7961404b5294c1c4f7ea15c175.json"))
- for i in all_names:
- print ( "%s = models.%sField(u'%s') ## %s <= %s" % (i.get("name").lower(), i.get("kind"), i.get("name"), i.get("extra"), i.get("val")))
- print ("\n\n\n\nqxpyfa.json")
- all_names = read_meta_from_data(os.path.join(os.path.dirname(__file__), "qxpyfa.json"))
- for i in all_names:
- print ( "%s = models.%sField(u'%s') ## %s <= %s" % (i.get("name").lower(), i.get("kind"), i.get("name"), i.get("extra"), i.get("val")))
|