Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
aa.gusti
/
opensipkd-base
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 5b3198ae
authored
Feb 25, 2025
by
aa.gusti
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
perubahan loading routes and menus
1 parent
2dd6c441
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
23 deletions
opensipkd/base/__init__.py
opensipkd/base/scripts/data/routes.csv
opensipkd/base/__init__.py
View file @
5b3198a
...
...
@@ -5,6 +5,8 @@ import locale
import
logging
import
re
import
urllib
from
.routes
import
routes
# from opensipkd.tools.captcha import get_captcha_url
...
...
@@ -135,7 +137,9 @@ def _get_params(request, params, default=None, settings=None, context=None):
return
get_params
(
params
,
default
,
settings
)
BASE_MENUS
=
[]
BASE_MENUS
=
[]
@subscriber
(
BeforeRender
)
def
add_global
(
event
):
...
...
@@ -473,7 +477,7 @@ def get_home(request):
def
_add_route
(
config
,
route
):
if
int
(
route
.
get
(
"type"
,
0
))
==
0
:
if
int
(
route
.
get
(
"type"
,
0
))
==
0
:
config
.
add_route
(
route
.
get
(
"kode"
),
route
.
get
(
"path"
))
elif
int
(
route
.
get
(
"type"
))
==
1
:
config
.
add_jsonrpc_endpoint
(
route
.
get
(
"kode"
),
route
.
get
(
"path"
),
...
...
@@ -481,13 +485,14 @@ def _add_route(config, route):
if
route
.
get
(
"nama"
):
titles
[
route
.
get
(
"kode"
)]
=
route
.
get
(
"nama"
)
def
_add_view_config
(
config
,
view_name
,
route
):
_add_route
(
config
,
route
)
if
not
route
.
get
(
"def_func"
):
return
class_view
=
route
.
get
(
"class_view"
)
and
f
".{route.get('class_view')}"
or
""
class_view
=
route
.
get
(
"class_view"
)
and
f
".{route.get('class_view')}"
or
""
class_name
=
f
"{view_name}{class_view}"
attr
=
f
"view_{route.get('def_func')}"
try
:
...
...
@@ -713,59 +718,64 @@ def main(global_config, **settings):
return
get_config
(
settings
=
settings
)
.
make_wsgi_app
()
def
get_route_file
(
filename
):
base_dir
=
os
.
path
.
split
(
__file__
)[
0
]
fullpath
=
os
.
path
.
join
(
base_dir
,
'scripts'
,
'data'
,
filename
)
return
open
(
fullpath
)
class
BaseApp
():
def
__init__
(
self
):
self
.
menus
=
[]
def
route_from_csv
(
self
,
config
,
get_file
=
get_route_file
):
def
route_from_csv
(
self
,
config
,
get_file
=
get_route_file
,
paket
=
"opensipkd.base.views"
):
with
get_file
(
"routes.csv"
)
as
f
:
rows
=
csv
.
DictReader
(
f
)
new_routes
=
[]
new_routes
=
[]
for
row
in
rows
:
if
row
.
get
(
"parent_id"
)
or
row
.
get
(
"parent_id/routes.kode"
):
new_routes
[
len
(
new_routes
)
-
1
][
"children"
]
.
append
(
row
)
else
:
row
[
"children"
]
=
[]
row
[
"children"
]
=
[]
new_routes
.
append
(
row
)
self
.
add_menu
(
config
,
new_routes
)
self
.
add_menu
(
config
,
new_routes
,
paket
)
def
route_from_list
(
self
,
config
,
routs
=
routes
):
def
route_from_list
(
self
,
config
,
routs
=
routes
,
paket
=
"opensipkd.base.views"
):
new_routes
=
[]
for
route
in
routs
:
d
=
{
"kode"
:
route
[
0
],
"path"
:
route
[
1
],
"nama"
:
route
[
2
],
"type"
:
len
(
route
)
>
4
and
route
[
4
]
or
0
"type"
:
len
(
route
)
>
4
and
route
[
4
]
or
0
}
new_routes
.
append
(
d
)
self
.
add_menu
(
config
,
new_routes
)
self
.
add_menu
(
config
,
new_routes
,
paket
)
def
add_menu
(
self
,
config
,
route_menus
,
parent
=
None
):
def
add_menu
(
self
,
config
,
route_menus
,
parent
=
None
,
paket
=
"opensipkd.base.views"
):
route_names
=
[]
for
route
in
route_menus
:
route
[
"route_names"
]
=
[
route
[
"kode"
]]
route
[
"route_names"
]
=
[
route
[
"kode"
]]
route
[
"permission"
]
=
route
.
get
(
"permission"
,
""
)
route
[
"icon"
]
=
route
.
get
(
"icon"
,
None
)
route_type
=
route
.
get
(
"type"
,
0
)
if
route_type
==
""
or
route_type
==
None
:
if
route_type
==
""
or
route_type
==
None
:
route_type
=
0
else
:
route_type
=
int
(
route_type
)
route
[
"type"
]
=
route_type
route
[
"is_menu"
]
=
route
.
get
(
"is_menu"
,
0
)
route
[
"path"
]
=
route
.
get
(
"path"
,
"#"
)
url_path
=
route
.
get
(
"path"
,
None
)
if
not
url_path
:
# pjdl /pjdl pjdl-add /pjdl/add
url_path
=
"/"
+
route
[
"kode"
]
.
replace
(
"-"
,
"/"
)
route
[
"path"
]
=
url_path
children
=
route
.
get
(
"children"
,
[])
route
[
"children"
]
=
[]
route
[
"children"
]
=
[]
if
route
.
get
(
"class_view"
):
_add_view_config
(
config
,
"opensipkd.coba.views"
,
route
)
_add_view_config
(
config
,
paket
,
route
)
elif
route
[
"path"
]
!=
"#"
:
_add_route
(
config
,
route
)
...
...
@@ -776,7 +786,7 @@ class BaseApp():
parent
[
"children"
]
.
append
(
route
)
if
children
:
route
[
"route_names"
]
.
extend
(
self
.
add_menu
(
config
,
children
,
route
)
self
.
add_menu
(
config
,
children
,
route
,
paket
)
)
route_names
.
append
(
route
[
"kode"
])
return
route_names
...
...
@@ -786,6 +796,3 @@ class BaseApp():
BASE_CLASS
=
BaseApp
()
opensipkd/base/scripts/data/routes.csv
View file @
5b3198a
...
...
@@ -4,6 +4,7 @@ home-auth,/home,Home Auth,1,
home-about,/home/{id}/about,Home About,1
login,/login,Login,1,0,
logout,/logout,Logout,1,0,
recreate-api-key,/recreate-api-key,Buat ulang API Key,1
rpc,/rpc,RPC,1,1,
change-password,/password/{code},Ubah password,1,
password,/password,Ubah password,1,
...
...
@@ -94,7 +95,6 @@ departemen-user-view,/departemen/user/{id}/view,User Organisasi view,1,0,
departemen-user-del,/departemen/user/{id}/del,User Organisasi Hapus,1,0,
departemen-user-rpt,/departemen/user/{rpt}/rpt,User Organisasi Report,1,0,
rpc-user,/rpc/user,WebService User Management,1,1,
recreate-api-key,/recreate-api-key,Buat ulang API Key,1,
googleOauth2,/googleOauth2,'Google OAuth2',1
googlesignin,/googlesignin, "Google SignIn",1
permission,/permission,Daftar Permission,1
...
...
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