Commit ab527357 by aagusti

perbaikan fungsi

1 parent b94bfdea
import traceback
# from collections import mappingproxy
import colander
import deform.widget
import logging
from icecream import ic
log = logging.getLogger(__name__)
field_widgets = (deform.widget.TextInputWidget,
deform.widget.MoneyInputWidget,
deform.widget.AutocompleteInputWidget,
......@@ -29,9 +29,7 @@ field_widgets = (deform.widget.TextInputWidget,
deform.widget.DatePartsWidget,
deform.widget.TextAreaCSVWidget,
deform.widget.TextInputCSVWidget,)
"""
" , ,
"requirements", """
field2remove = (
"_parent", "counter", "bindings", "resource_registry", "renderer",
"validator"
......@@ -41,7 +39,6 @@ field2remove = (
def form2dict(obj):
d = {}
if getattr(obj, "__dict__", str(obj)):
ic(obj.__dict__)
for k, v in obj.__dict__.items():
d[k] = v
for k, v in d.items():
......@@ -50,21 +47,15 @@ def form2dict(obj):
d[k] = ""
elif type(v) == colander.Invalid:
d[k] = v.asdict()
# elif type(v) == mappingproxy():
# d[k] = v.asdict()
elif v and hasattr(v, "__dict__") and \
getattr(v, "__dict__", str(v)):
ic("Caller dict")
ic(k,v)
d[k] = form2dict(v)
elif isinstance(v, list):
lv = []
for l in v:
if l and hasattr(l, "__dict__") and \
getattr(l, "__dict__", str(l)):
ic("Caller List")
ic(k, v)
lv.append(form2dict(l))
d[k] = lv
elif getattr(v, "__dict__", str(v)) == {}:
......@@ -76,13 +67,14 @@ def form2dict(obj):
if k == "widget" and type(v) in field_widgets:
d[k].update({"template": v.template})
if k == "missing" and v == colander.drop:
d[k] = True
except Exception as e:
print(e)
log.error(e)
traceback.print_exc()
ic(k, v)
return d
......@@ -107,16 +99,15 @@ def remove_child(data):
def formfield2dict(obj):
resp = form2dict(obj)
ic(resp)
log.debug(resp)
children = resp["children"]
children = remove_child(children)
table = "table" in resp and resp["table"] or None
result = dict(title=resp.get("title"),
children=children,
buttons=resp["buttons"],
url=resp.get("url"),
table=table,
)
ic(result)
log.debug(result)
return result
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!