Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Owo Sugiana
/
web-starter
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 9225fc21
authored
Apr 13, 2022
by
Owo Sugiana
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
YAML yang lebih sederhana
1 parent
f126ffe3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
40 deletions
web_starter/views/theme1/renderer.py
web_starter/views/theme1/templates/user/edit.yml
web_starter/views/theme1/user.py
web_starter/views/theme1/renderer.py
View file @
9225fc2
...
...
@@ -5,6 +5,9 @@ from deform import field
from
deform.widget
import
MappingWidget
schema
=
colander
.
Schema
()
class
PanelWidget
(
MappingWidget
):
# templates/user/panel.pt
template
=
'panel'
...
...
@@ -14,34 +17,31 @@ class Panel(field.Field):
widget
=
PanelWidget
()
here
=
os
.
path
.
abspath
(
os
.
path
.
dirname
(
__file__
))
my_templates
=
os
.
path
.
join
(
here
,
'templates'
,
'user'
)
search_path
=
[
my_templates
]
Panel
.
set_zpt_renderer
(
search_path
)
here
=
os
.
path
.
abspath
(
os
.
path
.
dirname
(
__file__
))
schema
=
colander
.
Schema
()
def
get_widgets
(
form
,
fields
,
level
=
0
):
r
=
[]
for
field_id
in
fields
:
if
field_id
.
find
(
'Group'
)
==
0
:
field
=
get_widgets
(
form
,
fields
[
field_id
],
level
+
1
)
else
:
# templates/user/mapping_item.pt
if
isinstance
(
field_id
,
str
):
form
[
field_id
]
.
my_level
=
level
# templates/user/mapping_item.pt
field
=
form
[
field_id
]
.
render_template
(
'mapping_item'
)
else
:
for
group_id
in
field_id
:
field_ids
=
field_id
[
group_id
]
field
=
get_widgets
(
form
,
field_ids
,
level
+
1
)
r
.
append
(
field
)
return
'
\n
'
.
join
(
r
)
def
render
(
form
,
yml_file
):
for
button
in
form
.
buttons
:
if
isinstance
(
button
,
tuple
):
button
=
button
[
0
]
yml_file
=
os
.
path
.
join
(
here
,
yml_file
)
with
open
(
yml_file
)
as
f
:
def
render
(
form
,
yml_template
):
yml_file
=
yml_template
+
'.yml'
full_path
=
None
for
path
in
Panel
.
default_renderer
.
loader
.
search_path
:
full_path
=
os
.
path
.
join
(
path
,
yml_file
)
if
os
.
path
.
exists
(
full_path
):
break
if
not
full_path
:
raise
Exception
(
f
'File {yml_file} tidak ditemukan'
)
with
open
(
full_path
)
as
f
:
y
=
yaml
.
safe_load
(
f
)
panels
=
[]
for
title
in
y
[
'Panels'
]:
...
...
web_starter/views/theme1/templates/user/edit.yml
View file @
9225fc2
...
...
@@ -2,20 +2,21 @@
---
Panels
:
No Title
:
user_name
:
User Name
email
:
Email
groups
:
Grup
-
user_name
-
email
-
groups
Bio Data
:
tempat_lahir
:
Tempat Lahir
tgl_lahir
:
Tanggal Lahir
-
tempat_lahir
-
tgl_lahir
Alamat
:
Group 1
:
alamat
:
Alamat
Group
:
rt
:
RT
rw
:
RW
Group 2
:
kelurahan
:
Kelurahan
kecamatan
:
Kecamatan
kabupaten
:
Kota / Kabupaten
provinsi
:
Provinsi
-
alamat
-
Group 1
:
-
rt
-
rw
-
Group 2
:
-
kelurahan
-
kecamatan
-
kabupaten
-
provinsi
web_starter/views/theme1/user.py
View file @
9225fc2
...
...
@@ -4,7 +4,6 @@ from sqlalchemy import (
Text
,
)
from
pyramid.view
import
view_config
from
pyramid.i18n
import
TranslationStringFactory
from
deform
import
(
Form
,
ZPTRendererFactory
,
...
...
@@ -19,10 +18,10 @@ from ..user import (
deform_templates
,
BaseView
,
)
from
.renderer
import
render
_
=
TranslationStringFactory
(
'user'
)
from
.renderer
import
(
Panel
,
render
,
)
columns
=
[
...
...
@@ -36,6 +35,7 @@ here = os.path.abspath(os.path.dirname(__file__))
my_templates
=
os
.
path
.
join
(
here
,
'templates'
,
'user'
)
search_path
=
[
my_templates
,
deform_templates
]
my_renderer
=
ZPTRendererFactory
(
search_path
)
Panel
.
set_zpt_renderer
(
search_path
)
@view_config
(
...
...
@@ -55,7 +55,7 @@ def view_act(request):
class
View
(
BaseView
):
def
render
(
self
,
form
):
# Override
form
.
my_widgets
=
render
(
form
,
'
templates/user/edit.yml
'
)
form
.
my_widgets
=
render
(
form
,
'
edit
'
)
return
form
.
render
()
def
get_form
(
self
,
schema
,
user
=
None
):
# Override
...
...
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