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 362ea986
authored
Nov 02, 2021
by
aa.gusti
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
perbaikan tools dan initiaize
1 parent
7ef21837
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
22 additions
and
17 deletions
opensipkd/base/alembic/env.py
opensipkd/base/models/__init__.py
opensipkd/base/scripts/initializedb.py
opensipkd/base/tools/api.py
opensipkd/base/tools/buttons.py
opensipkd/base/tools/captcha.py
opensipkd/base/alembic/env.py
View file @
362ea98
...
...
@@ -35,7 +35,7 @@ def run_migrations_offline():
"""
context
.
configure
(
url
=
settings
[
'sqlalchemy.url'
],
version_table
=
'alembic_
pbb_pelayanan
'
)
version_table
=
'alembic_
base
'
)
with
context
.
begin_transaction
():
context
.
run_migrations
()
...
...
@@ -54,8 +54,8 @@ def run_migrations_online():
connection
=
connection
,
target_metadata
=
target_metadata
,
helpers
=
helpers
,
version_table
=
'alembic_
pbb_pelayanan
'
,
version_table_schema
=
'p
bb
'
version_table
=
'alembic_
base
'
,
version_table_schema
=
'p
ublic
'
)
try
:
with
context
.
begin_transaction
():
...
...
opensipkd/base/models/__init__.py
View file @
362ea98
...
...
@@ -2,7 +2,8 @@ from datetime import datetime
import
sqlalchemy
as
sa
import
ziggurat_foundations.models
from
pyramid.security
import
(
Allow
,
Authenticated
,
ALL_PERMISSIONS
)
# from pyramid.security import (Allow, Authenticated, ALL_PERMISSIONS)
from
pyramid.authorization
import
(
Allow
,
Authenticated
,
ALL_PERMISSIONS
)
from
sqlalchemy
import
(
Column
,
Integer
,
DateTime
,
ForeignKey
,
String
,
SmallInteger
,
func
)
from
sqlalchemy.ext.hybrid
import
hybrid_property
...
...
opensipkd/base/scripts/initializedb.py
View file @
362ea98
...
...
@@ -116,13 +116,13 @@ def restore_csv(table, filename, get_file_func=get_file, db_session=None):
# sperti salah route url asalkan kode msh sama
def
append_csv
(
table
,
filename
,
keys
,
get_file_func
=
get_file
,
db_session
=
DBSession
,
update_exist
=
False
):
print
(
table
,
filename
)
with
get_file_func
(
filename
)
as
f
:
reader
=
csv
.
DictReader
(
f
)
filter_
=
dict
()
foreigns
=
dict
()
is_first
=
True
fmap
=
dict
()
print
(
f
,
reader
)
for
cf
in
reader
:
if
is_first
:
is_first
=
False
...
...
@@ -136,9 +136,19 @@ def append_csv(table, filename, keys, get_file_func=get_file,
raise
e
fname_orig
=
t
[
0
]
schema
=
"public"
if
t
[
1
:]:
foreign_table
,
foreign_field
=
t
[
1
]
.
split
(
'.'
)
foreign_table
=
Table
(
foreign_table
,
Base
.
metadata
,
autoload
=
True
)
t_array
=
t
[
1
]
.
split
(
'.'
)
if
len
(
t_array
)
==
2
:
foreign_table
=
t_array
[
0
]
foreign_field
=
t_array
[
1
]
else
:
schema
=
t_array
[
0
]
foreign_table
=
t_array
[
1
]
foreign_field
=
t_array
[
2
]
foreign_table
=
Table
(
foreign_table
,
Base
.
metadata
,
autoload
=
True
,
schema
=
schema
)
foreign_field
=
getattr
(
foreign_table
.
c
,
foreign_field
)
foreigns
[
fname
]
=
(
foreign_table
,
foreign_field
)
...
...
@@ -151,7 +161,6 @@ def append_csv(table, filename, keys, get_file_func=get_file,
if
fname
in
foreigns
:
foreign_table
,
foreign_field
=
foreigns
[
fname
]
value
=
cf
[
fname
]
vala
=
value
sql
=
select
([
foreign_table
])
.
where
(
foreign_field
==
value
)
q
=
Base
.
metadata
.
bind
.
execute
(
sql
)
row
=
q
.
fetchone
()
...
...
@@ -174,7 +183,6 @@ def append_csv(table, filename, keys, get_file_func=get_file,
for
fname
in
cf
:
if
not
fname
:
continue
fname_orig
=
fmap
[
fname
]
val
=
data
[
fname_orig
]
if
not
val
:
...
...
@@ -183,7 +191,6 @@ def append_csv(table, filename, keys, get_file_func=get_file,
user
=
True
password
=
val
else
:
print
(
fname_orig
)
setattr
(
row
,
fname_orig
,
val
)
db_session
.
add
(
row
)
...
...
@@ -195,10 +202,8 @@ def append_csv(table, filename, keys, get_file_func=get_file,
db_session
.
add
(
row
)
db_session
.
flush
()
transaction
.
commit
()
# diperlukan commit per record khususnya untuk yang internal link
def
ask_password
(
name
):
while
True
:
pass1
=
getpass
(
'Tulis password untuk {}: '
.
format
(
name
))
...
...
opensipkd/base/tools/api.py
View file @
362ea98
...
...
@@ -55,11 +55,11 @@ def renew_token(user_device):
def
get_user_device
(
request
,
user
):
user_device
=
UserDeviceModel
.
query
()
\
.
filter_by
(
user_id
=
user
.
id
,
kode
=
request
.
headers
.
environ
[
"HTTP_USER_AGENT"
])
.
first
()
kode
=
request
.
environ
[
"HTTP_USER_AGENT"
])
.
first
()
if
not
user_device
:
user_device
=
UserDeviceModel
()
user_device
.
user_id
=
user
.
id
user_device
.
kode
=
request
.
headers
.
environ
[
"HTTP_USER_AGENT"
]
user_device
.
kode
=
request
.
environ
[
"HTTP_USER_AGENT"
]
user_device
.
token
=
get_random_string
(
32
)
DBSession
.
add
(
user_device
)
DBSession
.
flush
()
...
...
opensipkd/base/tools/buttons.py
View file @
362ea98
from
..
import
log
log
.
warning
(
"opensipkd.base.buttons depreciated use opensipkd.tools.buttons"
)
from
opensipkd.tools.buttons
import
*
log
.
warning
(
"opensipkd.base.buttons depreciated use opensipkd.tools.buttons"
)
opensipkd/base/tools/captcha.py
View file @
362ea98
from
..
import
log
from
opensipkd.tools.captcha
import
*
log
.
warning
(
"opensipkd.base.captcha depreciated use opensipkd.tools.captcha"
)
# from ...tools.captcha import *
\ No newline at end of file
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