Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Vladislav Rykov
THSO.server
Commits
6b335653
Commit
6b335653
authored
Apr 17, 2020
by
Vladislav Rykov
Browse files
app dao changed
parent
4040f3f9
Changes
5
Show whitespace changes
Inline
Side-by-side
dao/application/application.py
View file @
6b335653
import
psycopg2
import
bcrypt
from
misc
import
with_psql
class
ApplicationDao
:
def
__init__
(
self
):
pass
# decorator implementation
def
with_psql
(
f
):
def
_with_psql
(
*
args
,
**
kwargs
):
conn
=
psycopg2
.
connect
(
'dbname=gateway'
)
cur
=
conn
.
cursor
()
try
:
res
=
f
(
cur
,
*
args
,
**
kwargs
)
except
(
Exception
,
psycopg2
.
DatabaseError
)
as
error
:
conn
.
rollback
()
res
=
(
False
,
error
)
else
:
conn
.
commit
()
finally
:
cur
.
close
()
conn
.
close
()
return
res
return
_with_psql
@
staticmethod
@
with_psql
def
create
(
cur
,
name
,
appkey
,
username
,
desc
):
@
with_psql
def
create
(
cur
,
name
,
appkey
,
username
,
desc
):
query
=
"""
INSERT INTO
applications
...
...
@@ -40,9 +12,8 @@ class ApplicationDao:
return
(
True
,)
@
staticmethod
@
with_psql
def
delete
(
cur
,
appkey
):
@
with_psql
def
delete
(
cur
,
appkey
):
query
=
"""
DELETE FROM
applications
...
...
@@ -53,9 +24,8 @@ class ApplicationDao:
return
(
True
,)
@
staticmethod
@
with_psql
def
get
(
cur
,
appkey
):
@
with_psql
def
get
(
cur
,
appkey
):
query
=
"""
SELECT * FROM
applications
...
...
@@ -71,9 +41,8 @@ class ApplicationDao:
return
(
True
,
app
)
@
staticmethod
@
with_psql
def
get_list
(
cur
,
username
):
@
with_psql
def
get_list
(
cur
,
username
):
query
=
"""
SELECT * FROM
applications
...
...
@@ -84,9 +53,8 @@ class ApplicationDao:
return
(
True
,
cur
.
fetchall
())
@
staticmethod
@
with_psql
def
update
(
cur
,
appkey
,
name
,
desc
):
@
with_psql
def
update
(
cur
,
appkey
,
name
,
desc
):
query
=
"""
UPDATE
applications
...
...
dao/application/application.pyc
View file @
6b335653
No preview for this file type
misc.py
View file @
6b335653
...
...
@@ -39,3 +39,25 @@ def prep_id_range(devlist):
s
+=
str
(
r
[
-
1
])
+
']'
return
s
import
psycopg2
# decorator implementation
def
with_psql
(
f
):
def
_with_psql
(
*
args
,
**
kwargs
):
conn
=
psycopg2
.
connect
(
'dbname=gateway'
)
cur
=
conn
.
cursor
()
try
:
res
=
f
(
cur
,
*
args
,
**
kwargs
)
except
(
Exception
,
psycopg2
.
DatabaseError
)
as
error
:
conn
.
rollback
()
res
=
(
False
,
error
)
else
:
conn
.
commit
()
finally
:
cur
.
close
()
conn
.
close
()
return
res
return
_with_psql
misc.pyc
View file @
6b335653
No preview for this file type
server.py
View file @
6b335653
...
...
@@ -19,8 +19,7 @@ server = Flask(__name__, template_folder='templates/')
@
server
.
route
(
'/'
)
def
index
():
if
'name'
in
session
and
len
(
session
[
'name'
])
>
0
:
ah
=
ad
.
ApplicationDao
()
apps
=
ah
.
get_list
(
session
[
'name'
].
encode
(
'utf-8'
))
apps
=
ad
.
get_list
(
session
[
'name'
].
encode
(
'utf-8'
))
session
.
pop
(
'appkey'
,
None
)
# print('apps: ', apps)
...
...
@@ -98,13 +97,12 @@ def new_application():
@
server
.
route
(
'/app'
,
methods
=
[
'GET'
,
'POST'
])
def
app
():
if
'name'
in
session
:
ah
=
ad
.
ApplicationDao
()
if
request
.
method
==
'GET'
:
dh
=
dd
.
DeviceDao
()
session
[
'appkey'
]
=
request
.
args
.
get
(
'appkey'
)
app
=
a
h
.
get
(
session
[
'appkey'
])
app
=
a
d
.
get
(
session
[
'appkey'
])
devs
=
dh
.
get_list
(
app
[
1
][
1
])
try
:
...
...
@@ -122,7 +120,7 @@ def app():
return
render_template
(
'new-app.html'
,
feedback
=
error
)
else
:
appkey
=
misc
.
rand_str
(
APP_KEY_LEN
)
res
=
a
h
.
create
(
request
.
form
[
'appname'
],
appkey
,
session
[
'name'
],
request
.
form
[
'appdesc'
])
res
=
a
d
.
create
(
request
.
form
[
'appname'
],
appkey
,
session
[
'name'
],
request
.
form
[
'appdesc'
])
if
not
res
[
0
]:
return
render_template
(
'new-app.html'
,
feedback
=
res
[
1
])
...
...
@@ -131,7 +129,7 @@ def app():
res
=
dh
.
create_table
(
appkey
)
if
not
res
[
0
]:
a
h
.
delete
(
appkey
)
a
d
.
delete
(
appkey
)
return
render_template
(
'new-app.html'
,
feedback
=
res
[
1
])
return
redirect
(
url_for
(
'index'
))
...
...
@@ -149,8 +147,7 @@ def delete_app():
dh
.
delete_table
(
session
[
'appkey'
])
ah
=
ad
.
ApplicationDao
()
res
=
ah
.
delete
(
session
[
'appkey'
])
res
=
ad
.
delete
(
session
[
'appkey'
])
if
not
res
[
0
]:
return
redirect
(
url_for
(
'app'
))
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
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 comment