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 5a70556c
authored
Mar 13, 2023
by
aagusti
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
perbaikan dan penambahan args kwargs
1 parent
87c73145
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
24 deletions
README.md
opensipkd/base/views/base_views.py
opensipkd/models/base.py
README.md
View file @
5a70556
...
@@ -15,14 +15,14 @@ Biasanya pada home directory::
...
@@ -15,14 +15,14 @@ Biasanya pada home directory::
$ ~/env/bin/pip install --upgrade pip setuptools
$ ~/env/bin/pip install --upgrade pip setuptools
$ ~/env/bin/pip install wheel
$ ~/env/bin/pip install wheel
##Instalasi
##
Instalasi
###Production:
###
Production:
$ ~/env/bin/pip install git+https://git.opensipkd.com/aa.gusti/base.git@latest
$ ~/env/bin/pip install git+https://git.opensipkd.com/aa.gusti/base.git@latest
$ cp ~/env/etc/live_opensipkd.tpl ~/env/etc/live_opensipkd.ini
$ cp ~/env/etc/live_opensipkd.tpl ~/env/etc/live_opensipkd.ini
###Install Development::
###
Install Development::
$ source ~/env/bin/activate
$ source ~/env/bin/activate
$ mkdir apps
$ mkdir apps
$ cd apps
$ cd apps
...
@@ -30,11 +30,11 @@ Biasanya pada home directory::
...
@@ -30,11 +30,11 @@ Biasanya pada home directory::
$ env/bin/pip install -e base
[
dev
]
$ env/bin/pip install -e base
[
dev
]
$ cp ~/env/etc/test_opensipkd.tpl ~/env/etc/test_opensipkd.ini
$ cp ~/env/etc/test_opensipkd.tpl ~/env/etc/test_opensipkd.ini
##Sesuaikan konfigurasi
##
Sesuaikan konfigurasi
Konfigurasi tergantung pada jenis instalasi
``test_opensipkd.ini``
atau
Konfigurasi tergantung pada jenis instalasi
``test_opensipkd.ini``
atau
``live_opensipkd.ini``
pada baris berikut ini::
``live_opensipkd.ini``
pada baris berikut ini::
###Database Koneksi:
###
Database Koneksi:
[
app:main
]
[
app:main
]
sqlalchemy.url = postgresql://user:password@localhost:5432/db
sqlalchemy.url = postgresql://user:password@localhost:5432/db
session.url = postgresql://user:password@localhost:5432/db
session.url = postgresql://user:password@localhost:5432/db
...
@@ -48,7 +48,7 @@ Konfigurasi tergantung pada jenis instalasi ``test_opensipkd.ini`` atau
...
@@ -48,7 +48,7 @@ Konfigurasi tergantung pada jenis instalasi ``test_opensipkd.ini`` atau
sqlalchemy.url = postgresql://user:password@localhost:5432/db
sqlalchemy.url = postgresql://user:password@localhost:5432/db
script_location = opensipkd.base:alembic
script_location = opensipkd.base:alembic
###Login/Register:
###
Login/Register:
[
app:main
]
[
app:main
]
captcha_files=
captcha_files=
# static folder untuk image captcha
# static folder untuk image captcha
...
@@ -65,7 +65,7 @@ Konfigurasi tergantung pada jenis instalasi ``test_opensipkd.ini`` atau
...
@@ -65,7 +65,7 @@ Konfigurasi tergantung pada jenis instalasi ``test_opensipkd.ini`` atau
# diisi nama template login apabila akan menggunakan template yang berbeda
# diisi nama template login apabila akan menggunakan template yang berbeda
###Handling Log File:
###
Handling Log File:
Logging dapat dilakukan console, file atau tabel
Logging dapat dilakukan console, file atau tabel
...
@@ -100,7 +100,7 @@ Logging dapat dilakukan console, file atau tabel
...
@@ -100,7 +100,7 @@ Logging dapat dilakukan console, file atau tabel
sqlalchemy.url = postgresql://user:password@localhost:5432/db
sqlalchemy.url = postgresql://user:password@localhost:5432/db
script_location = alembic
script_location = alembic
```
```
###Google Integrated dan Custom Register Form
###
Google Integrated dan Custom Register Form
Aplikasi sudah bisa terintegrsi dengan google oauth2
Aplikasi sudah bisa terintegrsi dengan google oauth2
Konfigurasi merupakan bagian dari "main"
Konfigurasi merupakan bagian dari "main"
...
@@ -112,7 +112,7 @@ Konfigurasi merupakan bagian dari "main"
...
@@ -112,7 +112,7 @@ Konfigurasi merupakan bagian dari "main"
```
```
##Buat tabelnya::
##
Buat tabelnya::
Perintah untuk membuat tabel
Perintah untuk membuat tabel
...
...
opensipkd/base/views/base_views.py
View file @
5a70556
...
@@ -32,7 +32,6 @@ from ...detable import DeTable
...
@@ -32,7 +32,6 @@ from ...detable import DeTable
log
=
logging
.
getLogger
(
__name__
)
log
=
logging
.
getLogger
(
__name__
)
class
UploadSchema
(
colander
.
Schema
):
class
UploadSchema
(
colander
.
Schema
):
upload
=
colander
.
SchemaNode
(
upload
=
colander
.
SchemaNode
(
FileData
(),
FileData
(),
...
@@ -165,14 +164,18 @@ class BaseView(object):
...
@@ -165,14 +164,18 @@ class BaseView(object):
def
delete_msg
(
self
,
row
):
def
delete_msg
(
self
,
row
):
return
f
'Data ID {row.id} sudah dihapus.'
return
f
'Data ID {row.id} sudah dihapus.'
def
route_list
(
self
,
msg
=
None
,
error
=
""
):
def
route_list
(
self
,
msg
=
None
,
error
=
""
,
**
kwargs
):
if
msg
:
if
msg
:
self
.
ses
.
flash
(
msg
,
error
)
self
.
ses
.
flash
(
msg
,
error
)
list_url
=
kwargs
.
get
(
"list_url"
,
None
)
if
not
list_url
:
list_url
=
self
.
req
.
route_url
(
self
.
list_route
)
if
self
.
headers
:
if
self
.
headers
:
return
HTTPFound
(
location
=
get_urls
(
self
.
req
.
route_url
(
self
.
list_route
)
),
return
HTTPFound
(
location
=
get_urls
(
list_url
),
headers
=
self
.
headers
)
headers
=
self
.
headers
)
else
:
else
:
return
HTTPFound
(
location
=
get_urls
(
self
.
req
.
route_url
(
self
.
list_route
)
))
return
HTTPFound
(
location
=
get_urls
(
list_url
))
def
form_validator
(
self
,
form
,
value
):
def
form_validator
(
self
,
form
,
value
):
pass
pass
...
@@ -220,8 +223,11 @@ class BaseView(object):
...
@@ -220,8 +223,11 @@ class BaseView(object):
allow_delete
=
kwargs
.
get
(
"allow_delete"
,
True
)
allow_delete
=
kwargs
.
get
(
"allow_delete"
,
True
)
schema
=
self
.
list_schema
()
schema
=
self
.
list_schema
()
schema
=
schema
.
bind
(
request
=
self
.
req
)
schema
=
schema
.
bind
(
request
=
self
.
req
)
list_url
=
kwargs
.
get
(
"list_url"
,
None
)
if
not
list_url
:
list_url
=
self
.
req
.
route_url
(
self
.
list_route
)
table
=
DeTable
(
schema
,
table
=
DeTable
(
schema
,
action
=
get_urls
(
self
.
req
.
route_url
(
self
.
list_route
))
,
action
=
list_url
,
action_suffix
=
"/grid/act"
,
action_suffix
=
"/grid/act"
,
buttons
=
self
.
list_buttons
,
buttons
=
self
.
list_buttons
,
request
=
self
.
req
,
request
=
self
.
req
,
...
@@ -258,7 +264,7 @@ class BaseView(object):
...
@@ -258,7 +264,7 @@ class BaseView(object):
result
=
self
.
next_view
(
form
,
row
=
row
)
result
=
self
.
next_view
(
form
,
row
=
row
)
if
result
:
if
result
:
return
result
return
result
return
self
.
route_list
(
)
return
self
.
after_view
(
row
=
row
)
values
=
self
.
get_values
(
row
)
values
=
self
.
get_values
(
row
)
if
not
values
:
if
not
values
:
...
@@ -328,11 +334,17 @@ class BaseView(object):
...
@@ -328,11 +334,17 @@ class BaseView(object):
def
validation_failure
(
self
,
value
):
def
validation_failure
(
self
,
value
):
return
value
return
value
def
cancel_act
(
self
):
def
cancel_act
(
self
,
**
kwargs
):
return
self
.
route_list
()
return
self
.
route_list
(
**
kwargs
)
def
after_add
(
self
,
row
,
values
):
def
after_add
(
self
,
**
kwargs
):
return
return
self
.
route_list
(
**
kwargs
)
def
after_edit
(
self
,
**
kwargs
):
return
self
.
route_list
(
**
kwargs
)
def
after_view
(
self
,
**
kwargs
):
return
self
.
route_list
(
**
kwargs
)
def
next_act
(
self
):
def
next_act
(
self
):
url_dict
=
self
.
req
.
matchdict
url_dict
=
self
.
req
.
matchdict
...
@@ -347,6 +359,9 @@ class BaseView(object):
...
@@ -347,6 +359,9 @@ class BaseView(object):
'rows'
:
rows
,
'rows'
:
rows
,
}
}
return
csv_response
(
self
.
req
,
value
,
filename
)
return
csv_response
(
self
.
req
,
value
,
filename
)
elif
url_dict
[
'act'
]
==
'pdf'
:
pass
raise
HTTPNotFound
raise
HTTPNotFound
def
list_join
(
self
,
query
):
def
list_join
(
self
,
query
):
...
@@ -433,13 +448,13 @@ class BaseView(object):
...
@@ -433,13 +448,13 @@ class BaseView(object):
js
=
resources
[
"js"
])
js
=
resources
[
"js"
])
values
=
dict
(
c
)
values
=
dict
(
c
)
row
=
self
.
save_request
(
values
)
row
=
self
.
save_request
(
values
)
self
.
after_add
(
row
,
value
s
)
return
self
.
after_add
(
row
=
row
,
**
kwarg
s
)
elif
"cancel"
in
self
.
req
.
POST
or
'batal'
in
self
.
req
.
POST
or
"close"
in
self
.
req
.
POST
:
elif
"cancel"
in
self
.
req
.
POST
or
'batal'
in
self
.
req
.
POST
or
"close"
in
self
.
req
.
POST
:
self
.
cancel_act
()
self
.
cancel_act
()
else
:
else
:
return
self
.
next_add
(
form
,
table
=
table
,
resources
=
resources
)
return
self
.
next_add
(
form
,
table
=
table
,
resources
=
resources
)
return
self
.
route_list
()
return
self
.
route_list
(
**
kwargs
)
values
=
self
.
before_add
()
values
=
self
.
before_add
()
form
.
set_appstruct
(
values
)
form
.
set_appstruct
(
values
)
return
dict
(
form
=
form
.
render
(),
table
=
table
and
table
.
render
()
or
None
,
return
dict
(
form
=
form
.
render
(),
table
=
table
and
table
.
render
()
or
None
,
...
@@ -478,11 +493,11 @@ class BaseView(object):
...
@@ -478,11 +493,11 @@ class BaseView(object):
values
[
k
]
=
v
values
[
k
]
=
v
return
self
.
save
(
values
,
self
.
req
.
user
,
row
)
return
self
.
save
(
values
,
self
.
req
.
user
,
row
)
def
id_not_found
(
self
):
def
id_not_found
(
self
,
**
kwargs
):
msg
=
f
"Data yang dicari Tidak Ditemukan ID:"
\
msg
=
f
"Data yang dicari Tidak Ditemukan ID:"
\
f
" {self.req.matchdict['id']}."
f
" {self.req.matchdict['id']}."
self
.
req
.
session
.
flash
(
msg
,
'error'
)
self
.
req
.
session
.
flash
(
msg
,
'error'
)
return
self
.
route_list
()
return
self
.
route_list
(
**
kwargs
)
def
get_values
(
self
,
row
,
istime
=
False
):
def
get_values
(
self
,
row
,
istime
=
False
):
d
=
row
.
to_dict
()
d
=
row
.
to_dict
()
...
@@ -503,7 +518,7 @@ class BaseView(object):
...
@@ -503,7 +518,7 @@ class BaseView(object):
request
=
self
.
req
request
=
self
.
req
row
=
self
.
query_id
()
.
first
()
row
=
self
.
query_id
()
.
first
()
if
not
row
:
if
not
row
:
return
self
.
id_not_found
()
return
self
.
id_not_found
(
**
kwargs
)
if
not
self
.
bindings
:
if
not
self
.
bindings
:
self
.
bindings
=
self
.
get_bindings
(
row
)
self
.
bindings
=
self
.
get_bindings
(
row
)
form
=
self
.
get_form
(
self
.
edit_schema
,
**
kwargs
)
form
=
self
.
get_form
(
self
.
edit_schema
,
**
kwargs
)
...
@@ -530,6 +545,7 @@ class BaseView(object):
...
@@ -530,6 +545,7 @@ class BaseView(object):
js
=
resources
[
"js"
])
js
=
resources
[
"js"
])
c
=
dict
(
controls
)
c
=
dict
(
controls
)
self
.
save_request
(
c
,
row
)
self
.
save_request
(
c
,
row
)
return
self
.
after_edit
(
row
=
row
,
**
kwargs
)
else
:
else
:
return
self
.
next_edit
(
form
,
row
=
row
)
return
self
.
next_edit
(
form
,
row
=
row
)
...
...
opensipkd/models/base.py
View file @
5a70556
...
@@ -99,6 +99,13 @@ class DefaultModel(CommonModel):
...
@@ -99,6 +99,13 @@ class DefaultModel(CommonModel):
return
query
return
query
@classmethod
@classmethod
def
query_from
(
cls
,
db_session
=
DBSession
,
columns
=
None
,
filters
=
None
):
query
=
db_session
.
query
()
.
select_from
(
cls
)
for
c
in
columns
:
query
=
query
.
add_columns
(
c
.
sqla_expr
)
return
query
@classmethod
def
query_id
(
cls
,
row_id
,
db_session
=
DBSession
):
def
query_id
(
cls
,
row_id
,
db_session
=
DBSession
):
return
cls
.
query
(
db_session
)
.
filter_by
(
id
=
row_id
)
return
cls
.
query
(
db_session
)
.
filter_by
(
id
=
row_id
)
...
...
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