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
77e9f22d
Commit
77e9f22d
authored
Jun 02, 2020
by
Vladislav Rykov
Browse files
admin:user app dev download csv added
parent
58c52665
Changes
3
Show whitespace changes
Inline
Side-by-side
app/app/__pycache__/views_admin.cpython-37.pyc
View file @
77e9f22d
No preview for this file type
app/app/templates/new/admin/user-device-settings.html
0 → 100644
View file @
77e9f22d
{% extends 'logged_layout.html' %}
{% block title %} HPC
&
A IoT - Device Settings {% endblock %}
{% block location %}
<a
class=
"h4 mb-0 text-white text-uppercase d-none d-lg-inline-block"
href=
"/applications"
>
Applications
</a>
<p
class=
"h4 mb-0 text-white text-uppercase d-none d-lg-inline-block"
>
-
</p>
<a
class=
"h4 mb-0 text-white text-uppercase d-none d-lg-inline-block"
href=
"/application/{{ app[1] }}"
>
{{ app[0] }}
</a>
<p
class=
"h4 mb-0 text-white text-uppercase d-none d-lg-inline-block"
>
-
</p>
<a
class=
"h4 mb-0 text-white text-uppercase d-none d-lg-inline-block"
href=
"/application/{{ app[1] }}/device/{{ dev[1] }}"
>
{{ dev[0] }}
</a>
{% endblock %}
{% block body %}
<!-- Page content -->
<div
class=
"container-fluid mt--7"
>
<!-- Table -->
<div
class=
"row"
>
<div
class=
"col"
>
<div
class=
"card shadow"
>
<div
class=
"card-header bg-transparent"
>
<h3
class=
"mb-0"
>
Device Settings
</h3>
</div>
<div
class=
"card-body"
>
<form
action=
"/application/{{ app[1] }}/device/{{ dev[1] }}/settings"
method=
"post"
id=
"devsettings"
>
<div
class=
"form-group"
>
<label>
Name:
</label><br>
<input
type=
"text"
maxlength=
"30"
class=
"form-control"
id=
"devname"
name=
"devname"
value=
"{{ dev[0] }}"
required
><br>
</div>
<div
class=
"form-group"
>
<label>
Description:
</label><br>
<textarea
id=
"devdesc"
maxlength=
"200"
class=
"form-control"
name=
"devdesc"
rows=
"5"
></textarea>
</div>
</form>
<br>
<div
class=
"row"
style=
"margin-top: 30px;"
>
<div
class=
"col-lg-3"
>
<button
type=
"submit"
form=
"devsettings"
class=
"btn btn-primary btn-block"
>
Save
</button>
</div>
<div
class=
"col-lg-3"
>
</div>
<div
class=
"col-lg-3"
>
</div>
<div
class=
"col-lg-3"
>
<button
type=
"button"
class=
"btn btn-danger btn-block"
data-toggle=
"modal"
data-target=
"#exampleModal"
>
Delete
</button>
<div
class=
"modal fade"
id=
"exampleModal"
tabindex=
"-1"
role=
"dialog"
aria-labelledby=
"exampleModalLabel"
aria-hidden=
"true"
>
<div
class=
"modal-dialog"
>
<div
class=
"modal-content"
>
<div
class=
"modal-header"
>
<h5
class=
"modal-title"
id=
"exampleModalLabel"
>
Are you sure?
</h5>
<button
type=
"button"
class=
"close"
data-dismiss=
"modal"
aria-label=
"Close"
>
<span
aria-hidden=
"true"
>
×
</span>
</button>
</div>
<div
class=
"modal-body"
>
This action will remove permanently the device and its corresponding data.
</div>
<div
class=
"modal-footer"
>
<button
type=
"button"
class=
"btn btn-secondary"
data-dismiss=
"modal"
>
Close
</button>
<a
href=
"/application/{{ app[1] }}/device/{{ dev[1] }}/delete"
><button
type=
"button"
class=
"btn btn-danger"
>
Delete Device
</button></a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block script %}
<script
type=
"text/javascript"
>
document
.
getElementById
(
"
devdesc
"
).
value
=
"
{{ dev[2] }}
"
;
</script>
{% endblock %}
app/app/views_admin.py
View file @
77e9f22d
from
app
import
app
from
flask
import
render_template
,
request
,
redirect
,
url_for
,
session
,
flash
from
flask
import
render_template
,
request
,
redirect
,
url_for
,
session
,
flash
,
after_this_request
,
send_from_directory
import
app.dao.user.user
as
ud
import
app.dao.application.application
as
ad
...
...
@@ -17,6 +17,7 @@ from app.helpers.misc import restricted
import
app.helpers.misc
as
misc
import
binascii
import
os
MAX_PG
=
5
...
...
@@ -381,6 +382,41 @@ def administration_users_user_application_device_configuration_remove(name, appk
return
''
,
200
@
app
.
route
(
'/administration/users/<name>/application/<appkey>/device/<devid>/download-csv'
)
@
restricted
(
access_level
=
'admin'
)
def
administration_users_user_application_device_download_csv
(
name
,
appkey
,
devid
):
@
after_this_request
def
clean_data_folder
(
response
):
try
:
filelist
=
[
f
for
f
in
os
.
listdir
(
app
.
config
[
'DATA_DOWNLOAD_DIR_OS'
])]
for
f
in
filelist
:
os
.
remove
(
app
.
config
[
'DATA_DOWNLOAD_DIR_OS'
]
+
'/'
+
f
)
except
OSError
:
pass
return
response
dumpd
=
data
.
get_all
(
appkey
,
devid
)
ap
=
ad
.
get
(
appkey
)[
1
]
dev
=
dd
.
get
(
appkey
,
devid
)[
1
]
fn
=
ap
[
0
]
+
'-'
+
dev
[
0
]
+
'-data.csv'
with
open
(
app
.
config
[
'DATA_DOWNLOAD_DIR_OS'
]
+
'/'
+
fn
,
'w+'
)
as
f
:
f
.
write
(
'utc,timestamp,'
)
for
d
in
dumpd
[
1
][
0
][
2
]:
f
.
write
(
d
)
f
.
write
(
','
)
f
.
write
(
'
\n
'
)
for
row
in
dumpd
[
1
]:
f
.
write
(
'{},{},'
.
format
(
row
[
0
],
row
[
1
]))
for
v
in
row
[
2
]:
f
.
write
(
str
(
row
[
2
][
v
]))
f
.
write
(
','
)
f
.
write
(
'
\n
'
)
return
send_from_directory
(
app
.
config
[
'DATA_DOWNLOAD_DIR'
],
fn
,
as_attachment
=
True
)
@
app
.
route
(
'/administration/users/<name>/chart-update'
)
@
restricted
(
access_level
=
'admin'
)
def
administration_users_user_chart_update
(
name
):
...
...
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