annot-server/websockets.py
changeset 66 658561ea9e65
parent 42 926f0426ce78
child 76 029cdbeebf03
--- a/annot-server/websockets.py	Sat Oct 25 05:41:51 2014 +0200
+++ b/annot-server/websockets.py	Sat Oct 25 05:43:01 2014 +0200
@@ -79,6 +79,12 @@
         self.event = event_ids[0]
         self._init_props(self.factory.ws_factory, self.factory.conn)
 
+    def clean_annot(self, annot):
+        if 'ts' in annot:
+            annot['ts'] = annot['ts'].isoformat()
+        if 'uuid' in annot:
+            annot['uuid'] = str(annot['uuid'])
+
     #TODO: add error handling
     def onMessage(self, payload, isBinary):
         if isBinary:
@@ -94,15 +100,13 @@
 
         def error_callback(failure):
             res = params.copy()
+            self.clean_annot(res)
             res['status'] = 'KO'
             res['failure'] = str(failure)
             self.sendMessage(json.dumps(res))
 
         def annot_callback(res):
-            if 'ts' in res:
-                res['ts'] = res['ts'].isoformat()+'Z'
-            if 'uuid' in res:
-                res['uuid'] = str(res['uuid'])
+            self.clean_annot(res)
             res['status'] = 'OK'
             self.sendMessage(json.dumps(res))