Commit ae3700a3 authored by Vladislav Rykov's avatar Vladislav Rykov
Browse files

download data integrated, filename improved

parent 70d47c00
This diff is collapsed.
This diff is collapsed.
......@@ -121,7 +121,7 @@
<a href="./{{ dev[1] }}/configure"><button type="submit" class="btn btn-primary btn-block">Configure</button></a>
</div>
<div class="col-lg-4">
<button type="submit" class="btn btn-primary btn-block">Download CSV</button>
<a href="./{{ dev[1] }}/download-csv"<button type="submit" class="btn btn-primary btn-block">Download CSV</button></a>
</div>
<div class="col-lg-4">
<button type="submit" class="btn btn-primary btn-block">Settings</button>
......
......@@ -272,6 +272,33 @@ def application_device_configuration(appkey, devid):
return redirect(url_for('login'))
@app.route('/application/<appkey>/device/<devid>/download-csv')
def application_device_download_csv(appkey, devid):
if 'name' in session:
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)
else:
return redirect(utl_for('login'))
@app.route('/new-app')
def new_app():
......
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