Commit 77e9f22d authored by Vladislav Rykov's avatar Vladislav Rykov
Browse files

admin:user app dev download csv added

parent 58c52665
{% 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"> &nbsp;-&nbsp; </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"> &nbsp;-&nbsp; </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">&times;</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 %}
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):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment