Ticket #5590: 5590.diff

File 5590.diff, 1.7 KB (added by Jeremy Dunck, 15 years ago)

Updated patch to apply to the 1.2 alpha.

  • django/core/serializers/json.py

    diff --git a/django/core/serializers/json.py b/django/core/serializers/json.py
    index 27c7c30..d7e5b15 100644
    a b from django.core.serializers.python import Serializer as PythonSerializer  
    99from django.core.serializers.python import Deserializer as PythonDeserializer
    1010from django.utils import datetime_safe
    1111from django.utils import simplejson
     12from django.utils.functional import Promise
    1213
    1314try:
    1415    import decimal
    class DjangoJSONEncoder(simplejson.JSONEncoder):  
    6162            return o.strftime(self.TIME_FORMAT)
    6263        elif isinstance(o, decimal.Decimal):
    6364            return str(o)
     65        elif isinstance(o, Promise):
     66            # The input is the result of a gettext_lazy() call.
     67            return unicode(o).encode('utf-8', 'strict')
    6468        else:
    6569            return super(DjangoJSONEncoder, self).default(o)
    6670
  • tests/regressiontests/i18n/tests.py

    diff --git a/tests/regressiontests/i18n/tests.py b/tests/regressiontests/i18n/tests.py
    index c2a39cd..fae061e 100644
    a b class TranslationTests(TestCase):  
    3939        self.assertEqual(True, s == s2)
    4040        s4 = ugettext_lazy('Some other string')
    4141        self.assertEqual(False, s == s4)
     42       
     43        #it should be possible to serialize *_lazy objects.
     44        from django.core.serializers import json
     45        from django.utils import simplejson
     46        serialized = simplejson.dumps(ugettext_lazy('Yet another string'),
     47            cls=json.DjangoJSONEncoder)
     48        self.assertEqual('"Yet another string"', serialized)
    4249
    4350    def test_string_concat(self):
    4451        """
Back to Top