Commit 5558b6df authored by Vladislav Rykov's avatar Vladislav Rykov
Browse files

recent actity in json packet possibility added

parent 168f75d4
...@@ -11,3 +11,5 @@ ...@@ -11,3 +11,5 @@
[2020-10-07 17:19:21,368] INFO in views: Logged in superuser admin [2020-10-07 17:19:21,368] INFO in views: Logged in superuser admin
[2020-10-07 19:11:04,501] INFO in views: superuser admin added new device testgeo for application 8cc6f4b1 [2020-10-07 19:11:04,501] INFO in views: superuser admin added new device testgeo for application 8cc6f4b1
[2020-10-07 22:22:21,007] INFO in views: Logged in superuser admin [2020-10-07 22:22:21,007] INFO in views: Logged in superuser admin
[2020-10-27 11:05:02,900] INFO in views: Logged in superuser admin
[2020-10-27 11:05:37,214] INFO in views: Logged in superuser admin
...@@ -177,6 +177,36 @@ def get_recent_activity(cur, username, n=5): ...@@ -177,6 +177,36 @@ def get_recent_activity(cur, username, n=5):
else: else:
return (True, []) return (True, [])
@with_psql
def get_recent_activity_json(cur, username, n=5):
apps = ad.get_list(username)[1]
devs = []
for a in apps:
devs.append(dd.get_list(a[1])[1])
if apps != [] and devs != [[]]:
query = 'SELECT row_to_json(r) FROM ('
for a in apps:
devs = dd.get_list(a[1])
for d in devs[1]:
query += """
(SELECT timedate, appname, devname, data, utc, appkey, devid from
(SELECT utc, timedate, data from dev_{}_{} ORDER BY utc DESC limit {}) AS utc,
(SELECT text '{}' as appname) AS appname,
(SELECT text '{}' as appkey) AS appkey,
(SELECT text '{}' as devid) AS devid,
(SELECT text '{}' as devname) AS devname)
UNION ALL""".format(a[1],d[1], n, a[0],a[1], d[1],d[0])
query = query[0:-9]
query += ' ORDER BY utc DESC LIMIT {}) r'.format(n)
cur.execute(query, ())
return (True, cur.fetchall())
else:
return (True, {})
def get_devices_locations(username): def get_devices_locations(username):
devlocs = {} devlocs = {}
apps = ad.get_list(username)[1] apps = ad.get_list(username)[1]
......
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