diff options
author | Lars Wirzenius <liw@liw.fi> | 2017-10-06 13:01:02 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2017-10-06 13:38:40 +0300 |
commit | 52b398761f0550c5a637007ab2aa780e9e1c53fe (patch) | |
tree | 35582eaa65f320cc5587a19bee98298672b4eb70 | |
parent | 8948adf5981b45087665e00fe2dbc031c357f9dd (diff) | |
download | qvisqve-52b398761f0550c5a637007ab2aa780e9e1c53fe.tar.gz |
Fix: sort notifications by timestamp
-rw-r--r-- | qvarn/api.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/qvarn/api.py b/qvarn/api.py index 125a4d3..909e202 100644 --- a/qvarn/api.py +++ b/qvarn/api.py @@ -405,6 +405,10 @@ class QvarnAPI: return wrapper def get_notifications_list_callback(self): # pragma: no cover + def timestamp(pair): + _, obj = pair + return obj['timestamp'] + def wrapper(content_type, body, **kwargs): rid = kwargs['id'] cond = qvarn.All( @@ -412,15 +416,16 @@ class QvarnAPI: qvarn.Equal('listener_id', rid) ) pairs = self._store.find_objects(cond) + ordered = sorted(pairs, key=timestamp) qvarn.log.log( 'trace', msg_text='Found notifications', - notifications=pairs) + notifications=ordered) body = { 'resources': [ { 'id': keys['obj_id'] } - for keys, _ in pairs + for keys, _ in ordered ] } return ok_response(body) @@ -524,7 +529,11 @@ class QvarnAPI: return False def get_current_timestamp(self): # pragma: no cover - return time.strftime('%Y-%m-%dT%H:%M:%S') + t = time.time() + tm = time.gmtime(t) + ss = t - int(t) + secs = '%f' % ss + return time.strftime('%Y-%m-%dT%H:%M:%S', tm) + secs[1:] def get_post_callback(self, coll): # pragma: no cover def wrapper(content_type, body, **kwargs): |