web/__init__.py
changeset 3777 3ef8cdb5fb1c
parent 2968 0e3460341023
parent 3758 d43c9709434d
child 3890 d7a270f50f54
--- a/web/__init__.py	Mon Oct 19 20:22:01 2009 +0200
+++ b/web/__init__.py	Wed Oct 21 17:32:20 2009 +0200
@@ -10,15 +10,13 @@
 __docformat__ = "restructuredtext en"
 _ = unicode
 
-from decimal import Decimal
-from datetime import datetime, date, timedelta
 from simplejson import dumps
 from urllib import quote as urlquote
 
 from logilab.common.deprecation import deprecated
 
 from cubicweb.web._exceptions import *
-
+from cubicweb.utils import CubicWebJsonEncoder
 
 INTERNAL_FIELD_VALUE = '__cubicweb_internal_field__'
 
@@ -47,22 +45,16 @@
 FACETTES = set()
 
 
-
 def json_dumps(value):
-    if isinstance(value, Decimal):
-        value = float(value)
-    elif isinstance(value, (date, datetime)):
-        value = value.strftime('%Y-%m-%d %H:%M')
-    elif isinstance(value, timedelta):
-        value = (value.days * 24*60*60) + value.seconds
-    try:
-        return dumps(value)
-    except TypeError:
-        return dumps(repr(value))
+    return dumps(value, cls=CubicWebJsonEncoder)
 
 def jsonize(function):
     def newfunc(*args, **kwargs):
-        return json_dumps(function(*args, **kwargs))
+        value = function(*args, **kwargs)
+        try:
+            return json_dumps(value)
+        except TypeError:
+            return json_dumps(repr(value))
     return newfunc
 
 @deprecated('[3.4] use req.build_ajax_replace_url() instead')