Commit ab527357 by aagusti

perbaikan fungsi

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