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
d31e5a56
Commit
d31e5a56
authored
Jun 02, 2020
by
Vladislav Rykov
Browse files
admin: user application add device view added
parent
d4b024ed
Changes
5
Hide whitespace changes
Inline
Side-by-side
app/app/__pycache__/views.cpython-37.pyc
View file @
d31e5a56
No preview for this file type
app/app/__pycache__/views_admin.cpython-37.pyc
View file @
d31e5a56
No preview for this file type
app/app/templates/new/admin/user-add-device.html
0 → 100644
View file @
d31e5a56
{% extends 'logged_layout.html' %}
{% block title %} Administration - {{ user }} - Add Device - HPC
&
A IoT {% endblock %}
{% block location %}
<a
class=
"h4 mb-0 text-white text-uppercase d-none d-lg-inline-block"
href=
"/administration"
>
Administration
</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=
"/administration/users"
>
Users
</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=
"/administration/users/{{ user }}"
>
{{ user }}
</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=
"/administration/users/{{ user }}/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=
"/administration/users/{{ user }}/application/{{ app[1] }}"
>
{{ app[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"
>
Add Device
</h3>
</div>
<div
class=
"card-body"
>
<form
action=
"/administration/users/{{ user }}/application/{{ app[1] }}/add-device"
method=
"post"
>
<div
class=
"form-group"
>
<label>
Name:
</label><br>
<input
type=
"text"
maxlength=
"30"
class=
"form-control"
id=
"devname"
name=
"devname"
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>
<br>
<div
class=
"form-group"
>
<label>
dev_id: {{ free_ids }}
</label><br>
<input
type=
"number"
size=
"3"
min=
"1"
max=
"255"
class=
"form-control"
id=
"devid"
name=
"devid"
required
><br>
</div>
<br>
<div
class=
"form-group"
>
<button
type=
"submit"
class=
"btn btn-primary"
>
Add Device
</button>
</div>
</form>
</div>
</div>
</div>
</div>
{% endblock %}
app/app/views.py
View file @
d31e5a56
...
@@ -435,7 +435,7 @@ def dev():
...
@@ -435,7 +435,7 @@ def dev():
last
=
data
.
get_last_n
(
session
[
'appkey'
],
session
[
'devid'
],
1
)
last
=
data
.
get_last_n
(
session
[
'appkey'
],
session
[
'devid'
],
1
)
ltup
=
'Device ha
ve
not sent data yet'
ltup
=
'Device ha
s
not sent data yet'
if
last
[
0
]:
if
last
[
0
]:
ltup
=
last
[
1
][
0
][
1
]
ltup
=
last
[
1
][
0
][
1
]
...
...
app/app/views_admin.py
View file @
d31e5a56
...
@@ -77,6 +77,7 @@ def administration_users_user_applications(name):
...
@@ -77,6 +77,7 @@ def administration_users_user_applications(name):
@
app
.
route
(
'/administration/users/<name>/new-application'
,
methods
=
[
'GET'
,
'POST'
])
@
app
.
route
(
'/administration/users/<name>/new-application'
,
methods
=
[
'GET'
,
'POST'
])
@
restricted
(
access_level
=
'admin'
)
def
administration_users_user_application_create
(
name
):
def
administration_users_user_application_create
(
name
):
if
request
.
method
==
'GET'
:
if
request
.
method
==
'GET'
:
return
render_template
(
'new/admin/user-new-application.html'
,
user
=
name
)
return
render_template
(
'new/admin/user-new-application.html'
,
user
=
name
)
...
@@ -118,6 +119,30 @@ def administration_users_user_application(name, appkey):
...
@@ -118,6 +119,30 @@ def administration_users_user_application(name, appkey):
return
render_template
(
'new/admin/user-application.html'
,
app
=
ap
,
devs
=
devs
,
user
=
name
)
return
render_template
(
'new/admin/user-application.html'
,
app
=
ap
,
devs
=
devs
,
user
=
name
)
@
app
.
route
(
'/administration/users/<name>/application/<appkey>/add-device'
,
methods
=
[
'GET'
,
'POST'
])
@
restricted
(
access_level
=
'admin'
)
def
administration_users_user_application_add_device
(
name
,
appkey
):
if
request
.
method
==
'GET'
:
ap
=
ad
.
get
(
appkey
)
dev_list
=
dd
.
get_list
(
appkey
)
return
render_template
(
'new/admin/user-add-device.html'
,
app
=
ap
[
1
],
free_ids
=
misc
.
prep_id_range
(
dev_list
[
1
]),
user
=
name
)
elif
request
.
method
==
'POST'
:
res
=
dd
.
create
(
request
.
form
[
'devname'
],
request
.
form
[
'devid'
],
appkey
,
request
.
form
[
'devdesc'
])
if
not
res
[
0
]:
flash
(
'Error: {}'
.
format
(
res
[
1
]),
'danger'
)
return
render_template
(
request
.
url
)
else
:
res
=
data
.
create_table
(
appkey
,
request
.
form
[
'devid'
])
if
not
res
[
0
]:
dd
.
delete
(
appkey
,
request
.
form
[
'devid'
])
flash
(
'Error: {}'
.
format
(
res
[
1
]),
'danger'
)
return
render_template
(
request
.
url
)
else
:
return
redirect
(
url_for
(
'administration_users_user_application'
,
name
=
name
,
appkey
=
appkey
))
@
app
.
route
(
'/administration/users/<name>/application/<appkey>/device/<devid>'
)
@
app
.
route
(
'/administration/users/<name>/application/<appkey>/device/<devid>'
)
@
restricted
(
access_level
=
'admin'
)
@
restricted
(
access_level
=
'admin'
)
def
administration_users_user_application_device
(
name
,
appkey
,
devid
):
def
administration_users_user_application_device
(
name
,
appkey
,
devid
):
...
@@ -127,7 +152,7 @@ def administration_users_user_application_device(name, appkey, devid):
...
@@ -127,7 +152,7 @@ def administration_users_user_application_device(name, appkey, devid):
ld
=
data
.
get_last_range
(
appkey
,
devid
,
[
MAX_PG_ENTRIES_DATA
,
0
])
ld
=
data
.
get_last_range
(
appkey
,
devid
,
[
MAX_PG_ENTRIES_DATA
,
0
])
cnt
=
data
.
get_count
(
appkey
,
devid
)
cnt
=
data
.
get_count
(
appkey
,
devid
)
ltup
=
'Device ha
ve
not any sent data yet'
ltup
=
'Device ha
s
not any sent data yet'
if
ld
[
0
]
and
ld
[
1
][
0
]
!=
[]:
if
ld
[
0
]
and
ld
[
1
][
0
]
!=
[]:
ltup
=
ld
[
1
][
0
][
1
]
ltup
=
ld
[
1
][
0
][
1
]
...
...
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