Skip to content
Snippets Groups Projects
Commit 6d613285 authored by Renaud Le Gac's avatar Renaud Le Gac
Browse files

Improved JsonEncoder to understand date, datetime and time.

parent 1b891565
No related branches found
No related tags found
No related merge requests found
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment