diff -r 956e97430c68 django/core/serializers/json.py
|
a
|
b
|
|
| 21 | 21 | self.options.pop('stream', None) |
| 22 | 22 | self.options.pop('fields', None) |
| 23 | 23 | self.options.pop('use_natural_keys', None) |
| | 24 | if self.options.get('indent'): |
| | 25 | # The default is (', ', ': '). To eliminate useless whitespaces |
| | 26 | # after comma, the representation is changed to (',', ': ') only |
| | 27 | # if indent is used |
| | 28 | self.options['separators'] = (',', ': ') |
| 24 | 29 | simplejson.dump(self.objects, self.stream, cls=DjangoJSONEncoder, **self.options) |
| 25 | 30 | |
| 26 | 31 | def getvalue(self): |
diff -r 956e97430c68 tests/modeltests/serializers/models.py
|
a
|
b
|
|
| 8 | 8 | |
| 9 | 9 | from decimal import Decimal |
| 10 | 10 | from django.db import models |
| | 11 | from django.test.testcases import TestCase |
| 11 | 12 | |
| 12 | 13 | class Category(models.Model): |
| 13 | 14 | name = models.CharField(max_length=20) |
| … |
… |
|
| 342 | 343 | except ImportError: |
| 343 | 344 | pass |
| 344 | 345 | |
| | 346 | |
| | 347 | |
| | 348 | _json_expected="""[ |
| | 349 | { |
| | 350 | "pk": 1, |
| | 351 | "model": "serializers.score", |
| | 352 | "fields": { |
| | 353 | "score": 5.0 |
| | 354 | } |
| | 355 | }, |
| | 356 | { |
| | 357 | "pk": 2, |
| | 358 | "model": "serializers.score", |
| | 359 | "fields": { |
| | 360 | "score": 6.0 |
| | 361 | } |
| | 362 | } |
| | 363 | ]""" |
| | 364 | |
| | 365 | |
| | 366 | class TestJsonSerializerIndentation(TestCase): |
| | 367 | def test_indentation_whitespace(self): |
| | 368 | from django.core.serializers.json import Serializer |
| | 369 | Score.objects.create(score=5.0) |
| | 370 | Score.objects.create(score=6.0) |
| | 371 | qset = Score.objects.all() |
| | 372 | |
| | 373 | s = Serializer() |
| | 374 | self.assertEqual(s.serialize(qset,indent=2),_json_expected) |