Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
aa.gusti
/
opensipkd-tools
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 099e9fd3
authored
Jul 26, 2022
by
aagusti
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
perbaikan form_api
1 parent
d84d05c9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
29 deletions
opensipkd/tools/buttons.py
opensipkd/tools/form_api.py
opensipkd/tools/buttons.py
View file @
099e9fd
from
deform.form
import
Button
from
deform.form
import
Button
from
translationstring
import
TranslationStringFactory
btn_add
=
Button
(
'add'
,
title
=
'Tambah'
,
css_class
=
"btn-success"
)
_
=
TranslationStringFactory
(
'button'
)
btn_view
=
Button
(
'view'
,
title
=
'Lihat'
,
css_class
=
"btn-info"
)
btn_add
=
Button
(
'add'
,
title
=
_
(
'Add'
),
css_class
=
"btn-success"
)
btn_view
=
Button
(
'view'
,
title
=
_
(
'Lihat'
),
css_class
=
"btn-info"
)
btn_edit
=
Button
(
'edit'
,
title
=
'Edit'
,
css_class
=
"btn-success"
)
btn_edit
=
Button
(
'edit'
,
title
=
'Edit'
,
css_class
=
"btn-success"
)
btn_delete
=
Button
(
'delete'
,
title
=
'Hapus'
,
css_class
=
"btn-danger"
)
btn_delete
=
Button
(
'delete'
,
title
=
'Hapus'
,
css_class
=
"btn-danger"
)
btn_save
=
Button
(
'save'
,
title
=
'Simpan'
,
css_class
=
"btn-primary"
)
btn_save
=
Button
(
'save'
,
title
=
'Simpan'
,
css_class
=
"btn-primary"
)
...
@@ -11,7 +14,6 @@ btn_filter = Button('filter', title='Filter', css_class="btn-info")
...
@@ -11,7 +14,6 @@ btn_filter = Button('filter', title='Filter', css_class="btn-info")
btn_cancel
=
Button
(
'cancel'
,
title
=
'Batal'
,
css_class
=
"btn-warning"
)
btn_cancel
=
Button
(
'cancel'
,
title
=
'Batal'
,
css_class
=
"btn-warning"
)
btn_reset
=
Button
(
'reset'
,
title
=
'Reset'
,
css_class
=
"btn-warning"
,
type
=
"reset"
)
btn_reset
=
Button
(
'reset'
,
title
=
'Reset'
,
css_class
=
"btn-warning"
,
type
=
"reset"
)
btn_close
=
Button
(
'close'
,
title
=
'Tutup'
,
css_class
=
"btn-danger"
)
btn_close
=
Button
(
'close'
,
title
=
'Tutup'
,
css_class
=
"btn-danger"
)
btn_password
=
Button
(
'reset'
,
title
=
'Reset'
,
css_class
=
"btn-warning"
)
btn_print
=
Button
(
'print'
,
title
=
'Print'
,
css_class
=
"btn-info"
,
type
=
"button"
)
btn_print
=
Button
(
'print'
,
title
=
'Print'
,
css_class
=
"btn-info"
,
type
=
"button"
)
btn_pdf
=
Button
(
'pdf'
,
title
=
'PDF'
,
css_class
=
"btn-info"
,
type
=
"button"
)
btn_pdf
=
Button
(
'pdf'
,
title
=
'PDF'
,
css_class
=
"btn-info"
,
type
=
"button"
)
...
@@ -55,6 +57,7 @@ flow_2_buttons = [btn_prev, btn_next, btn_cancel]
...
@@ -55,6 +57,7 @@ flow_2_buttons = [btn_prev, btn_next, btn_cancel]
pdf_txt_buttons
=
[
btn_pdf
,
btn_txt
,
btn_close
]
pdf_txt_buttons
=
[
btn_pdf
,
btn_txt
,
btn_close
]
pdf_buttons
=
[
btn_pdf
,
btn_close
]
pdf_buttons
=
[
btn_pdf
,
btn_close
]
btn_login
=
Button
(
'login'
,
title
=
'Masuk'
,
css_class
=
"btn-success"
)
btn_register
=
Button
(
'register'
,
title
=
'Register'
,
css_class
=
"btn-warning"
)
btn_password
=
Button
(
'get_password'
,
title
=
'Get Password'
,
css_class
=
"btn-danger"
)
\ No newline at end of file
\ No newline at end of file
btn_login
=
Button
(
'login'
,
title
=
_
(
'Login'
),
css_class
=
"btn-success"
)
btn_register
=
Button
(
'register'
,
title
=
_
(
'Register'
),
css_class
=
"btn-success"
)
btn_password
=
Button
(
'password'
,
title
=
'Change Password'
,
css_class
=
"btn-danger"
)
btn_lost
=
Button
(
'lost'
,
title
=
'Lost Password'
,
css_class
=
"btn-danger"
)
\ No newline at end of file
\ No newline at end of file
opensipkd/tools/form_api.py
View file @
099e9fd
import
traceback
import
traceback
# from collections import mappingproxy
import
colander
import
colander
import
deform.widget
import
deform.widget
...
@@ -28,39 +29,52 @@ field_widgets = (deform.widget.TextInputWidget,
...
@@ -28,39 +29,52 @@ field_widgets = (deform.widget.TextInputWidget,
deform
.
widget
.
DatePartsWidget
,
deform
.
widget
.
DatePartsWidget
,
deform
.
widget
.
TextAreaCSVWidget
,
deform
.
widget
.
TextAreaCSVWidget
,
deform
.
widget
.
TextInputCSVWidget
,)
deform
.
widget
.
TextInputCSVWidget
,)
"""
field2remove
=
(
"_parent"
,
"counter"
,
"renderer"
,
"resource_registry"
,
" , ,
"requirements"
,
"bindings"
)
"requirements", """
field2remove
=
(
"_parent"
,
"counter"
,
"bindings"
,
"resource_registry"
,
"renderer"
,
"validator"
)
def
form2dict
(
obj
):
def
form2dict
(
obj
):
d
=
{}
d
=
{}
if
getattr
(
obj
,
"__dict__"
,
str
(
obj
)):
if
getattr
(
obj
,
"__dict__"
,
str
(
obj
)):
d
=
obj
.
__dict__
ic
(
obj
.
__dict__
)
for
k
,
v
in
obj
.
__dict__
.
items
():
d
[
k
]
=
v
for
k
,
v
in
d
.
items
():
for
k
,
v
in
d
.
items
():
try
:
try
:
if
type
(
v
)
==
colander
.
Invalid
:
if
k
in
field2remove
:
ic
(
dir
(
v
))
d
[
k
]
=
""
d
[
k
]
=
v
.
asdict
()
elif
type
(
v
)
==
colander
.
Invalid
:
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
))
==
{}:
d
[
k
]
=
{}
d
[
k
]
=
{}
if
k
in
field2remove
:
d
[
k
]
=
""
# elif getattr(v, "__dict__", str(v)):
# d[k] = form2dict(v)
if
k
==
"widget"
and
type
(
v
)
in
field_widgets
:
if
k
==
"widget"
and
type
(
v
)
in
field_widgets
:
# if hasattr(d[k], "udpate"):
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
...
@@ -93,19 +107,16 @@ def remove_child(data):
...
@@ -93,19 +107,16 @@ def remove_child(data):
def
formfield2dict
(
obj
):
def
formfield2dict
(
obj
):
resp
=
form2dict
(
obj
)
resp
=
form2dict
(
obj
)
ic
(
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
# for child in children:
# c_order = child["schema"]["_order"]
result
=
dict
(
title
=
resp
.
get
(
"title"
),
# count = 0
children
=
children
,
# for f in fields:
buttons
=
resp
[
"buttons"
],
# if f["_order"] == c_order:
url
=
resp
.
get
(
"url"
),
# f["children"] = (child["children"])
table
=
table
,
# fields[count]=f
)
# count += 1
ic
(
result
)
# ic(resp)
return
result
return
dict
(
children
=
children
,
buttons
=
resp
[
"buttons"
],
action
=
resp
[
"action"
],
table
=
table
)
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment