changed last seen datetime formater for gateway from timestamp to strftime
parent
9624b75414
commit
15ca471b83
|
@ -23,7 +23,7 @@
|
||||||
<td class="text-center">{{ gateway.id }}</td>
|
<td class="text-center">{{ gateway.id }}</td>
|
||||||
<td class="text-center">{{ gateway.name }}</td>
|
<td class="text-center">{{ gateway.name }}</td>
|
||||||
<td class="text-center">{{ gateway.token}}</td>
|
<td class="text-center">{{ gateway.token}}</td>
|
||||||
<td class="text-center">{{ gateway.last_seen_datetime | date:'yyyy-MM-dd HH:mm:ss'}}</td>
|
<td class="text-center">{{ gateway.last_seen_datetime }}</td>
|
||||||
<td class="text-center">
|
<td class="text-center">
|
||||||
<a class="btn btn-primary btn-rounded btn-xs" ng-click="editGateway(gateway)" >{{'SETTING.EDIT' | translate}}</a>
|
<a class="btn btn-primary btn-rounded btn-xs" ng-click="editGateway(gateway)" >{{'SETTING.EDIT' | translate}}</a>
|
||||||
<a ng-click="deleteGateway(gateway)" class="btn btn-danger btn-rounded btn-xs" >{{'SETTING.DELETE' | translate}}</a>
|
<a ng-click="deleteGateway(gateway)" class="btn btn-danger btn-rounded btn-xs" >{{'SETTING.DELETE' | translate}}</a>
|
||||||
|
|
|
@ -3,7 +3,7 @@ import simplejson as json
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
import config
|
import config
|
||||||
import uuid
|
import uuid
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone, timedelta
|
||||||
from core.userlogger import user_logger
|
from core.userlogger import user_logger
|
||||||
|
|
||||||
|
|
||||||
|
@ -30,14 +30,22 @@ class GatewayCollection:
|
||||||
cursor.close()
|
cursor.close()
|
||||||
cnx.disconnect()
|
cnx.disconnect()
|
||||||
|
|
||||||
|
timezone_offset = int(config.utc_offset[1:3]) * 60 + int(config.utc_offset[4:6])
|
||||||
|
if config.utc_offset[0] == '-':
|
||||||
|
timezone_offset = -timezone_offset
|
||||||
|
|
||||||
result = list()
|
result = list()
|
||||||
if rows is not None and len(rows) > 0:
|
if rows is not None and len(rows) > 0:
|
||||||
for row in rows:
|
for row in rows:
|
||||||
|
if isinstance(row['last_seen_datetime_utc'], datetime):
|
||||||
|
last_seen_datetime_local = row['last_seen_datetime_utc'].replace(tzinfo=timezone.utc) + \
|
||||||
|
timedelta(minutes=timezone_offset)
|
||||||
|
last_seen_datetime = last_seen_datetime_local.strftime('%Y-%m-%dT%H:%M:%S')
|
||||||
|
else:
|
||||||
|
last_seen_datetime = None
|
||||||
meta_result = {"id": row['id'], "name": row['name'], "uuid": row['uuid'],
|
meta_result = {"id": row['id'], "name": row['name'], "uuid": row['uuid'],
|
||||||
"token": row['token'],
|
"token": row['token'],
|
||||||
"last_seen_datetime":
|
"last_seen_datetime": last_seen_datetime
|
||||||
row['last_seen_datetime_utc'].replace(tzinfo=timezone.utc).timestamp() * 1000
|
|
||||||
if isinstance(row['last_seen_datetime_utc'], datetime) else None,
|
|
||||||
}
|
}
|
||||||
result.append(meta_result)
|
result.append(meta_result)
|
||||||
|
|
||||||
|
@ -117,13 +125,22 @@ class GatewayItem:
|
||||||
raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND',
|
raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND',
|
||||||
description='API.GATEWAY_NOT_FOUND')
|
description='API.GATEWAY_NOT_FOUND')
|
||||||
|
|
||||||
|
timezone_offset = int(config.utc_offset[1:3]) * 60 + int(config.utc_offset[4:6])
|
||||||
|
if config.utc_offset[0] == '-':
|
||||||
|
timezone_offset = -timezone_offset
|
||||||
|
|
||||||
|
if isinstance(row['last_seen_datetime_utc'], datetime):
|
||||||
|
last_seen_datetime_local = row['last_seen_datetime_utc'].replace(tzinfo=timezone.utc) + \
|
||||||
|
timedelta(minutes=timezone_offset)
|
||||||
|
last_seen_datetime = last_seen_datetime_local.strftime('%Y-%m-%dT%H:%M:%S')
|
||||||
|
else:
|
||||||
|
last_seen_datetime = None
|
||||||
|
|
||||||
result = {"id": row['id'],
|
result = {"id": row['id'],
|
||||||
"name": row['name'],
|
"name": row['name'],
|
||||||
"uuid": row['uuid'],
|
"uuid": row['uuid'],
|
||||||
"token": row['token'],
|
"token": row['token'],
|
||||||
"last_seen_datetime":
|
"last_seen_datetime": last_seen_datetime}
|
||||||
row['last_seen_datetime_utc'].replace(tzinfo=timezone.utc).timestamp()*1000
|
|
||||||
if isinstance(row['last_seen_datetime_utc'], datetime) else None}
|
|
||||||
|
|
||||||
resp.body = json.dumps(result)
|
resp.body = json.dumps(result)
|
||||||
|
|
||||||
|
@ -250,6 +267,10 @@ class GatewayDataSourceCollection:
|
||||||
raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND',
|
raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND',
|
||||||
description='API.GATEWAY_NOT_FOUND')
|
description='API.GATEWAY_NOT_FOUND')
|
||||||
|
|
||||||
|
timezone_offset = int(config.utc_offset[1:3]) * 60 + int(config.utc_offset[4:6])
|
||||||
|
if config.utc_offset[0] == '-':
|
||||||
|
timezone_offset = -timezone_offset
|
||||||
|
|
||||||
result = list()
|
result = list()
|
||||||
query_data_source = (" SELECT id, name, uuid, "
|
query_data_source = (" SELECT id, name, uuid, "
|
||||||
" protocol, connection, last_seen_datetime_utc "
|
" protocol, connection, last_seen_datetime_utc "
|
||||||
|
@ -258,17 +279,20 @@ class GatewayDataSourceCollection:
|
||||||
" ORDER BY name ")
|
" ORDER BY name ")
|
||||||
cursor.execute(query_data_source, (id_,))
|
cursor.execute(query_data_source, (id_,))
|
||||||
rows_data_source = cursor.fetchall()
|
rows_data_source = cursor.fetchall()
|
||||||
now = datetime.utcnow().replace(second=0, microsecond=0, tzinfo=None)
|
|
||||||
if rows_data_source is not None and len(rows_data_source) > 0:
|
if rows_data_source is not None and len(rows_data_source) > 0:
|
||||||
for row in rows_data_source:
|
for row in rows_data_source:
|
||||||
|
if isinstance(row['last_seen_datetime_utc'], datetime):
|
||||||
|
last_seen_datetime_local = row['last_seen_datetime_utc'].replace(tzinfo=timezone.utc) + \
|
||||||
|
timedelta(minutes=timezone_offset)
|
||||||
|
last_seen_datetime = last_seen_datetime_local.strftime('%Y-%m-%dT%H:%M:%S')
|
||||||
|
else:
|
||||||
|
last_seen_datetime = None
|
||||||
meta_result = {"id": row['id'],
|
meta_result = {"id": row['id'],
|
||||||
"name": row['name'],
|
"name": row['name'],
|
||||||
"uuid": row['uuid'],
|
"uuid": row['uuid'],
|
||||||
"protocol": row['protocol'],
|
"protocol": row['protocol'],
|
||||||
"connection": row['connection'],
|
"connection": row['connection'],
|
||||||
"last_seen_datetime":
|
"last_seen_datetime": last_seen_datetime,
|
||||||
row['last_seen_datetime_utc'].replace(tzinfo=timezone.utc).timestamp()*1000
|
|
||||||
if isinstance(row['last_seen_datetime_utc'], datetime) else None,
|
|
||||||
}
|
}
|
||||||
result.append(meta_result)
|
result.append(meta_result)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue