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
bea47a83
Commit
bea47a83
authored
Oct 07, 2020
by
Vladislav Rykov
Browse files
*_ddm cleaned
parent
2f8a8810
Changes
8
Hide whitespace changes
Inline
Side-by-side
app/app.log
View file @
bea47a83
...
...
@@ -7,3 +7,5 @@
[2020-10-01 15:11:29,771] INFO in views: superuser admin failed to add new device tricky for application 8cc6f4b1. Cause: existing devid
[2020-10-01 15:11:42,083] INFO in views: superuser admin added new device tricky for application 8cc6f4b1
[2020-10-01 15:11:55,695] INFO in views: superuser admin deleted for application 8cc6f4b1 device 2
[2020-10-07 17:18:50,561] INFO in views: Logged in superuser admin
[2020-10-07 17:19:21,368] INFO in views: Logged in superuser admin
app/app/__pycache__/views.cpython-37.pyc
View file @
bea47a83
No preview for this file type
app/app/__pycache__/views_admin.cpython-37.pyc
View file @
bea47a83
No preview for this file type
app/app/dao/data/__pycache__/data.cpython-37.pyc
View file @
bea47a83
No preview for this file type
app/app/dao/data/data.py
View file @
bea47a83
...
...
@@ -2,21 +2,9 @@ from psycopg2 import sql
from
app.helpers.misc
import
with_psql
from
datetime
import
datetime
@
with_psql
def
create_table
(
cur
,
appkey
,
devid
):
tn
=
'dev_'
+
str
(
appkey
)
+
'_'
+
str
(
devid
)
cur
.
execute
(
sql
.
SQL
(
"""CREATE TABLE {} (
utc NUMERIC(10) NOT NULL,
timedate VARCHAR(100) NOT NULL,
data json NOT NULL
)"""
).
format
(
sql
.
Identifier
(
tn
)))
return
(
True
,)
@
with_psql
def
create_table
_ddm
(
cur
,
appkey
,
devid
):
def
create_table
(
cur
,
appkey
,
devid
):
tn
=
'dev_'
+
str
(
appkey
)
+
'_'
+
str
(
devid
)
cur
.
execute
(
sql
.
SQL
(
...
...
@@ -28,6 +16,7 @@ def create_table_ddm(cur, appkey, devid):
).
format
(
sql
.
Identifier
(
tn
)))
return
(
True
,)
@
with_psql
def
delete_table
(
cur
,
appkey
,
devid
):
tn
=
'dev_'
+
str
(
appkey
)
+
'_'
+
str
(
devid
)
...
...
app/app/dao/device/__pycache__/device.cpython-37.pyc
View file @
bea47a83
No preview for this file type
app/app/dao/device/device.py
View file @
bea47a83
...
...
@@ -3,21 +3,9 @@ from app.helpers.misc import with_psql
import
app.dao.application.application
as
ad
import
json
@
with_psql
def
create_datatable
(
cur
,
appkey
,
dev_id
):
tn
=
'dev_'
+
str
(
appkey
)
+
'_'
+
str
(
dev_id
)
cur
.
execute
(
sql
.
SQL
(
"""CREATE TABLE {} (
utc NUMERIC(10) DEFAULT EXTRACT(EPOCH FROM now())::int NOT NULL,
timedate VARCHAR(100) NOT NULL,
data json NOT NULL
)"""
).
format
(
sql
.
Identifier
(
tn
)))
return
(
True
,)
@
with_psql
def
create_datatable
_ddm
(
cur
,
appkey
,
dev_id
,
model
):
def
create_datatable
(
cur
,
appkey
,
dev_id
,
model
):
tn
=
'dev_'
+
str
(
appkey
)
+
'_'
+
str
(
dev_id
)
cur
.
execute
(
sql
.
SQL
(
...
...
@@ -29,7 +17,8 @@ def create_datatable_ddm(cur, appkey, dev_id, model):
).
format
(
sql
.
Identifier
(
tn
)))
return
(
True
,)
@
with_psql
def
delete_datatable
(
cur
,
appkey
,
dev_id
):
tn
=
'dev_'
+
str
(
appkey
)
+
'_'
+
str
(
dev_id
)
...
...
@@ -39,21 +28,9 @@ def delete_datatable(cur, appkey, dev_id):
).
format
(
sql
.
Identifier
(
tn
)))
return
(
True
,)
@
with_psql
def
create_table
(
cur
,
appkey
):
tn
=
'devices_'
+
str
(
appkey
)
cur
.
execute
(
sql
.
SQL
(
"""CREATE TABLE {} (
name VARCHAR(30) NOT NULL,
dev_id NUMERIC(3) PRIMARY KEY,
description VARCHAR(200)
)"""
).
format
(
sql
.
Identifier
(
tn
)))
return
(
True
,)
@
with_psql
def
create_table
_ddm
(
cur
,
appkey
):
def
create_table
(
cur
,
appkey
):
tn
=
'devices_'
+
str
(
appkey
)
cur
.
execute
(
sql
.
SQL
(
...
...
@@ -75,21 +52,9 @@ def delete_table(cur, appkey):
).
format
(
sql
.
Identifier
(
tn
)))
return
(
True
,)
@
with_psql
def
create
(
cur
,
name
,
dev_id
,
appkey
,
desc
):
tn
=
'devices_'
+
str
(
appkey
)
query
=
"""
INSERT INTO
{}
VALUES
(%s, %s, %s)
"""
cur
.
execute
(
sql
.
SQL
(
query
).
format
(
sql
.
Identifier
(
tn
)),
[
name
,
dev_id
,
desc
])
return
(
True
,)
@
with_psql
def
create
_ddm
(
cur
,
name
,
dev_id
,
appkey
,
desc
,
ddm
):
def
create
(
cur
,
name
,
dev_id
,
appkey
,
desc
,
ddm
):
tn
=
'devices_'
+
str
(
appkey
)
query
=
"""
INSERT INTO
...
...
@@ -138,23 +103,7 @@ def get(cur, appkey, dev_id):
@
with_psql
def
update
(
cur
,
appkey
,
devid
,
name
,
desc
):
tn
=
'devices_'
+
appkey
query
=
"""
UPDATE
{}
SET
name = %s,
description = %s
WHERE
dev_id = %s
"""
.
format
(
tn
)
cur
.
execute
(
query
,
(
name
,
desc
,
devid
))
return
(
True
,)
@
with_psql
def
update_ddm
(
cur
,
appkey
,
devid
,
name
,
desc
,
ddm
):
def
update
(
cur
,
appkey
,
devid
,
name
,
desc
,
ddm
):
tn
=
'devices_'
+
appkey
query
=
"""
UPDATE
...
...
app/app/views.py
View file @
bea47a83
...
...
@@ -145,7 +145,7 @@ def application_create():
flash
(
'Error: {}'
.
format
(
res
[
1
]),
'danger'
)
return
redirect
(
request
.
url
)
res
=
dd
.
create_table
_ddm
(
appkey
)
res
=
dd
.
create_table
(
appkey
)
if
not
res
[
0
]:
ad
.
delete
(
appkey
)
...
...
@@ -220,13 +220,13 @@ def application_add_device(appkey):
if
dd
.
check_devid
(
appkey
,
request
.
form
[
'devid'
]):
ddmin
=
ddm
.
extract
(
request
)
res
=
dd
.
create
_ddm
(
request
.
form
[
'devname'
],
request
.
form
[
'devid'
],
appkey
,
request
.
form
[
'devdesc'
],
ddmin
)
res
=
dd
.
create
(
request
.
form
[
'devname'
],
request
.
form
[
'devid'
],
appkey
,
request
.
form
[
'devdesc'
],
ddmin
)
if
not
res
[
0
]:
app
.
logger
.
error
(
'%s %s failed to add device for application %s - %s'
,
session
[
'role'
],
session
[
'name'
],
appkey
,
res
[
1
])
flash
(
'Error: {}'
.
format
(
res
[
1
]),
'danger'
)
return
redirect
(
request
.
url
)
else
:
res
=
data
.
create_table
_ddm
(
appkey
,
request
.
form
[
'devid'
])
res
=
data
.
create_table
(
appkey
,
request
.
form
[
'devid'
])
if
not
res
[
0
]:
app
.
logger
.
error
(
'%s %s failed to add device for application %s - %s'
,
session
[
'role'
],
session
[
'name'
],
appkey
,
res
[
1
])
dd
.
delete
(
session
[
'appkey'
],
request
.
form
[
'devid'
])
...
...
@@ -644,7 +644,7 @@ def application_device_settings(appkey, devid):
return
render_template
(
'views/public/device-settings.html'
,
app
=
ap
[
1
],
dev
=
dev
[
1
],
models
=
ddm
.
MODELS
)
elif
request
.
method
==
'POST'
:
ddmin
=
ddm
.
extract
(
request
)
res
=
dd
.
update
_ddm
(
appkey
,
devid
,
request
.
form
[
'devname'
],
request
.
form
[
'devdesc'
],
ddmin
)
res
=
dd
.
update
(
appkey
,
devid
,
request
.
form
[
'devname'
],
request
.
form
[
'devdesc'
],
ddmin
)
if
not
res
[
0
]:
flash
(
'Error: {}'
.
format
(
res
[
1
]),
'danger'
)
...
...
@@ -663,5 +663,6 @@ def map():
last_activity
=
md
.
get_user_data_count_per_day
(
session
[
'name'
])[
1
][
0
]
info
=
[
created_apps
,
active_devices
,
total_activity
,
last_activity
]
print
(
'render'
)
return
render_template
(
'views/public/map.html'
,
info
=
info
)
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