From 6d6132850983626a6a250f61730261beda69bc79 Mon Sep 17 00:00:00 2001
From: Renaud Le Gac <renaud.legac@free.fr>
Date: Sat, 26 Mar 2011 17:12:03 +0000
Subject: [PATCH] Improved  JsonEncoder to understand date, datetime and time.

---
 modules/plugin_dbui/directsvc.py | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/modules/plugin_dbui/directsvc.py b/modules/plugin_dbui/directsvc.py
index 2657946f..98d765d2 100644
--- a/modules/plugin_dbui/directsvc.py
+++ b/modules/plugin_dbui/directsvc.py
@@ -4,13 +4,13 @@
 
 __version__ = "$Revision$"
 
-
+import datetime
+import json
 import pprint
 import traceback
 import sys
 
 from basesvc import BaseSvc
-from gluon.contrib import simplejson as json
 from gluon.http import HTTP
 from helper import as_list
 
@@ -18,6 +18,21 @@ DBUI = 'Dbui'
 PROC_KEY = '%s.%s'
 
 
+class MyJsonEncoder(json.JSONEncoder):
+    """Add date, datetime and time to the standard encoder.
+    
+    """
+    def default(self, obj):
+        
+        if isinstance(obj, (datetime.date,
+                            datetime.datetime,
+                            datetime.time)):
+            return obj.isoformat().replace('T', ' ')
+        
+        return json.JSONEncoder.default(self, obj)
+
+        
+    
 class DirectSvc(BaseSvc):
     """Generic service to implement the Ext.Direct protocol on the server side
     Specification: http://www.sencha.com/products/extjs/extdirect/
@@ -126,6 +141,6 @@ class DirectSvc(BaseSvc):
             li.append(di)
             
         self.dbg('End directSvc.call', li)
-        return json.dumps(li)
+        return json.dumps(li, cls=MyJsonEncoder)
         
         
\ No newline at end of file
-- 
GitLab