aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/utils/encoders.py
AgeCommit message (Collapse)Author
2015-01-19Merge masterTom Christie
2015-01-19Handle UUID objects in JSONEncoder. Closes #2433.Tom Christie
2015-01-19Fix timedelta JSON serialization on Python 2.6.Fabien Bochu
2014-12-18YAML encoder fix for 3.0 serializers.Tom Christie
2014-12-12Merge masterTom Christie
2014-12-04Removed custom StringIO, force_text, smart_text compatTymur Maryokhin
2014-11-29Remove YAML support from coreJosé Padilla
2014-11-06Drop usage of SortedDict. Closes #2027.Tom Christie
2014-10-02The encoder now returns tuples instead of lists.Omer Katz
Tuples take a little less memory which is significant when serializing a lot of objects.
2014-10-01Use six.text_type instead of str everywhereTom Christie
2014-09-12Tidy up JSONEncoderTom Christie
2014-09-11NotImplemented stubs for Field, and DecimalField improvementsTom Christie
2014-08-29First passTom Christie
2014-08-19Code linting and added runtests.pyTom Christie
2014-04-13Merge remote-tracking branch 'origin/master' into 2.4.0Xavier Ordoquy
Conflicts: .travis.yml docs/api-guide/fields.md docs/api-guide/routers.md docs/topics/release-notes.md rest_framework/authentication.py rest_framework/serializers.py rest_framework/templatetags/rest_framework.py rest_framework/tests/test_authentication.py rest_framework/tests/test_filters.py rest_framework/tests/test_hyperlinkedserializers.py rest_framework/tests/test_serializer.py rest_framework/tests/test_testing.py rest_framework/utils/encoders.py tox.ini
2014-01-17Encode django QuerySets to lists and not dicts in JSONEncoderMathieu Pillard
2013-12-13Merge branch 'master' into 2.4.0Tom Christie
Conflicts: .travis.yml docs/api-guide/routers.md docs/topics/release-notes.md rest_framework/compat.py
2013-12-09Fix compat issues for #1231Tom Christie
2013-11-21Fix issue #1231: JSONEncoder doesn't handle dict-like objectsMalcolm Box
Check for __getitem__ and then attempt to convert to a dict. The check for __getitem__ is there as there's no universal way to check if an object is a mapping type, but this is a likely proxy
2013-10-17Fix decimal support with YAMLRendererbadaud_t
2013-09-25Drop 1.3 supportTom Christie
2013-09-13Let JSONEncoder handle Numpy data types.David Pretty
json.JSONEncoder cannot serialize Numpy data types. Numpy arrays and array scalars have a tolist() method which casts the object to a standard python data type.
2013-05-24Clean up OPTIONS implementationTom Christie
2013-02-04Cleanup importsTom Christie
Mostly adding `from __future__ import unicode_literals` everywhere.
2013-01-15Add timedelta encoder to the JSONEncoder class.James Cleveland
Whilst this commit adds *encoding* of timedeltas to a string of a floating point value of the seconds, you must add your own serializer field for whatever timedelta model field you are using. This is because Django doesn't support any kind of timedelta field out-of-the-box, so you have to either implement your own or use django-timedelta. If this is the case and you want to serialise timedelta input, you will have to implement your own special field to use for the timedelta, which is not included in core as it is based on a 3rd party library. Here is an example: import datetime import timedelta from django import forms from django.core import validators from django.core.exceptions import ValidationError from django.utils.translation import ugettext_lazy as _ from rest_framework.fields import WritableField class TimedeltaField(WritableField): type_name = 'TimedeltaField' form_field_class = forms.FloatField default_error_messages = { 'invalid': _("'%s' value must be in seconds."), } def from_native(self, value): if value in validators.EMPTY_VALUES: return None try: return datetime.timedelta(seconds=float(value)) except (TypeError, ValueError): msg = self.error_messages['invalid'] % value raise ValidationError(msg) Which is based on the FloatField. This field can then be used in your serializer like this: from yourapp.fields import TimedeltaField class YourSerializer(serializers.ModelSerializer): duration = TimedeltaField()
2013-01-05deprecate simplejsonJuan Riaza
2012-10-10Fix yaml renderingTom Christie
2012-09-20Change package name: djangorestframework -> rest_frameworkTom Christie