From a4ce8ff800a15fe271d10d05b7b25d50094371e4 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Fri, 25 Feb 2011 12:20:14 +0100 Subject: [PATCH] more datetime support --- ox/django/shortcuts.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ox/django/shortcuts.py b/ox/django/shortcuts.py index 0908da8..bdb7902 100644 --- a/ox/django/shortcuts.py +++ b/ox/django/shortcuts.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # vi:si:et:sw=4:sts=4:ts=4 -from datetime import datetime +import datetime from django.http import HttpResponse, Http404 try: import simplejson as json @@ -18,9 +18,9 @@ def json_response(data=None, status=200, text='ok'): return {'status': {'code': status, 'text': text}, 'data': data} def _to_json(python_object): - if isinstance(python_object, datetime): - python_object.strftime('%Y-%m-%dT%H:%M:%SZ') - raise TypeError(repr(python_object) + ' is not JSON serializable') + if isinstance(python_object, datetime.datetime): + return python_object.strftime('%Y-%m-%dT%H:%M:%SZ') + raise TypeError(u'%s %s is not JSON serializable' % (repr(python_object), type(python_object))) def render_to_json_response(dictionary, content_type="text/json", status=200): indent=None