Ticket #5590: django-json-lazy.diff
File django-json-lazy.diff, 1.4 KB (added by , 17 years ago) |
---|
-
django/core/serializers/json.py
5 5 import datetime 6 6 from django.utils import simplejson 7 7 from django.utils.simplejson import decoder 8 from django.utils.functional import Promise 8 9 from django.core.serializers.python import Serializer as PythonSerializer 9 10 from django.core.serializers.python import Deserializer as PythonDeserializer 10 11 try: … … 57 58 return o.strftime(self.TIME_FORMAT) 58 59 elif isinstance(o, decimal.Decimal): 59 60 return str(o) 61 elif isinstance(o, Promise): 62 # The input is the result of a gettext_lazy() call. 63 return unicode(o).encode('utf-8', 'strict') 60 64 else: 61 65 return super(DjangoJSONEncoder, self).default(o) 62 66 -
tests/regressiontests/i18n/tests.py
30 30 >>> s4 = ugettext_lazy('Some other string') 31 31 >>> s == s4 32 32 False 33 34 >>> from django.core.serializers import json 35 >>> from django.utils import simplejson 36 >>> s5 = ugettext_lazy('Yet another string') 37 >>> simplejson.dumps(s5, cls=json.DjangoJSONEncoder) 38 '"Yet another string"' 39 33 40 """