Commit 9f3cc723 authored by Vladislav Rykov's avatar Vladislav Rykov
Browse files

recent activity fixed

parent 355d9257
...@@ -161,11 +161,13 @@ def get_recent_activity(cur, username, n=5): ...@@ -161,11 +161,13 @@ def get_recent_activity(cur, username, n=5):
devs = dd.get_list(a[1]) devs = dd.get_list(a[1])
for d in devs[1]: for d in devs[1]:
query += """ query += """
(SELECT timedate, appname, devname, data, utc from (SELECT timedate, appname, devname, data, utc, appkey, devid from
(SELECT utc, timedate, data from dev_{}_{} ORDER BY utc DESC limit 5) AS utc, (SELECT utc, timedate, data from dev_{}_{} ORDER BY utc DESC limit 5) AS utc,
(SELECT '{}' as appname) AS appname, (SELECT '{}' as appname) AS appname,
(SELECT '{}' as appkey) AS appkey,
(SELECT '{}' as devid) AS devid,
(SELECT '{}' as devname) AS devname) (SELECT '{}' as devname) AS devname)
UNION ALL""".format(a[1],d[1], a[0],d[0]) UNION ALL""".format(a[1],d[1], a[0],a[1], d[1],d[0])
query = query[0:-9] query = query[0:-9]
query += ' ORDER BY utc DESC LIMIT {}'.format(n) query += ' ORDER BY utc DESC LIMIT {}'.format(n)
......
...@@ -245,6 +245,7 @@ def application_device_delete(appkey, devid): ...@@ -245,6 +245,7 @@ def application_device_delete(appkey, devid):
data.delete_table(appkey, devid) data.delete_table(appkey, devid)
res = dd.delete(appkey, devid) res = dd.delete(appkey, devid)
flash('Device removed.', 'success')
return redirect(url_for('application', appkey=appkey)) return redirect(url_for('application', appkey=appkey))
else: else:
return redirect(utl_for('login')) return redirect(utl_for('login'))
...@@ -327,10 +328,13 @@ def chart_update(): ...@@ -327,10 +328,13 @@ def chart_update():
def recent_activity(): def recent_activity():
if 'name' in session: if 'name' in session:
recent_activity = md.get_recent_activity(session['name'])[1] recent_activity = md.get_recent_activity(session['name'])[1]
ra = '' ra = ''
for r in recent_activity: for r in recent_activity:
ra += '<tr><th scope="row">'+r[1]+'</th><th>'+r[2]+'</th><th>'+r[0]+'</th><th>'+str(r[3])+'</th></tr>' print(r)
dev = dd.get(r[5], r[6])[1]
ra += '<tr><th scope="row">'+r[1]+'</th><th>'+r[2]+'</th><th>'+r[0]+'</th><th>'+str(ddm.read_data(r[3], dev[3]))+'</th></tr>'
return ra, 200 return ra, 200
else: else:
...@@ -355,11 +359,11 @@ def application_device_configuration_remove(appkey, devid): ...@@ -355,11 +359,11 @@ def application_device_configuration_remove(appkey, devid):
@app.route('/application/<appkey>/device/<devid>/variables') @app.route('/application/<appkey>/device/<devid>/variables')
def application_device_variables(appkey, devid): def application_device_variables(appkey, devid):
if 'name' in session: if 'name' in session:
last = data.get_last_n(appkey, devid, 1) dmodel = dd.get(appkey, devid)
if last[0]: if dmodel[0]:
select = '<select class="form-control" id="varname" name="varname" onchange="validate_form();" required>' select = '<select class="form-control" id="varname" name="varname" onchange="validate_form();" required>'
select += '<option value="-">Select Variable</option>' select += '<option value="-">Select Variable</option>'
for k in last[1][0][2]: for k in dmodel[1][3]['format']:
select += '<option>'+k+'</option>' select += '<option>'+k+'</option>'
select += '</select>' select += '</select>'
return select return select
......
...@@ -136,7 +136,7 @@ def administration_users_user_application_add_device(name, appkey): ...@@ -136,7 +136,7 @@ def administration_users_user_application_add_device(name, appkey):
flash('Error: {}'.format(res[1]), 'danger') flash('Error: {}'.format(res[1]), 'danger')
return redirect(request.url) return redirect(request.url)
else: else:
res = data.create_table(appkey, request.form['devid']) res = data.create_table_ddm(appkey, request.form['devid'])
if not res[0]: if not res[0]:
dd.delete(appkey, request.form['devid']) dd.delete(appkey, request.form['devid'])
......
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