Commit Graph

33 Commits

Author SHA1 Message Date
Tom Christie
549210b50f Don't strip microseconds in JSON output. (#4256) 2016-07-11 14:34:23 +01:00
Tom Christie
6ff9840bde Schemas & client libraries. (#4179)
* Added schema generation support.
* New tutorial section.
* API guide on schema generation.
* Topic guide on API clients.
2016-07-04 16:38:17 +01:00
Tom Christie
9bffd35432 Handle bytestrings in JSON. Closes #4185. (#4191) 2016-06-13 10:41:50 +01:00
José Padilla
7351a3f6ca Sort imports with isort 2015-06-25 16:55:51 -04:00
José Padilla
83c9136c90 Cleanup import following PEP 8 style guide 2015-06-25 16:10:17 -04:00
Tom Christie
6065cdbd93 Merge master 2015-01-19 15:16:57 +00:00
Tom Christie
da1db34a36 Handle UUID objects in JSONEncoder. Closes #2433. 2015-01-19 14:19:01 +00:00
Fabien Bochu
5484d570cb Fix timedelta JSON serialization on Python 2.6. 2015-01-19 13:09:08 +01:00
Tom Christie
a68d9331fc YAML encoder fix for 3.0 serializers. 2014-12-18 12:17:46 +00:00
Tom Christie
baaa356489 Merge master 2014-12-12 15:37:43 +00:00
Tymur Maryokhin
d54c67d79d Removed custom StringIO, force_text, smart_text compat 2014-12-04 03:11:42 +01:00
José Padilla
731c8421af Remove YAML support from core 2014-11-29 14:43:05 -04:00
Tom Christie
4e001dbb7a Drop usage of SortedDict. Closes #2027. 2014-11-06 12:00:30 +00:00
Omer Katz
79e91dff92 The encoder now returns tuples instead of lists.
Tuples take a little less memory which is significant when serializing a lot of objects.
2014-10-02 16:44:20 +03:00
Tom Christie
381771731f Use six.text_type instead of str everywhere 2014-10-01 13:09:14 +01:00
Tom Christie
22af49bf8f Tidy up JSONEncoder 2014-09-12 11:50:20 +01:00
Tom Christie
040bfcc09c NotImplemented stubs for Field, and DecimalField improvements 2014-09-11 21:48:54 +01:00
Tom Christie
4ac4676a40 First pass 2014-08-29 16:46:26 +01:00
Tom Christie
bf09c32de8 Code linting and added runtests.py 2014-08-19 13:28:07 +01:00
Xavier Ordoquy
d08536ad9d Merge remote-tracking branch 'origin/master' into 2.4.0
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-04-13 00:05:57 +02:00
Mathieu Pillard
f034cb595a Encode django QuerySets to lists and not dicts in JSONEncoder 2014-01-17 13:05:10 +01:00
Tom Christie
9c41c007af Merge branch 'master' into 2.4.0
Conflicts:
	.travis.yml
	docs/api-guide/routers.md
	docs/topics/release-notes.md
	rest_framework/compat.py
2013-12-13 16:32:34 +00:00
Tom Christie
ddd17c69e7 Fix compat issues for #1231 2013-12-09 09:24:10 +00:00
Malcolm Box
263281d71d Fix issue #1231: JSONEncoder doesn't handle dict-like objects
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-11-21 20:09:48 +00:00
badaud_t
b730aec0f4 Fix decimal support with YAMLRenderer 2013-10-17 01:08:24 +02:00
Tom Christie
e441f85109 Drop 1.3 support 2013-09-25 10:30:04 +01:00
David Pretty
d489c5c881 Let JSONEncoder handle Numpy data types.
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-09-13 13:36:18 +10:00
Tom Christie
fcaee6e580 Clean up OPTIONS implementation 2013-05-24 23:44:23 +01:00
Tom Christie
b052c92ac3 Cleanup imports
Mostly adding `from __future__ import unicode_literals` everywhere.
2013-02-04 20:55:35 +00:00
James Cleveland
4fc3b1ba56 Add timedelta encoder to the JSONEncoder class.
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-15 13:08:52 +00:00
Juan Riaza
a061e3d9e2 deprecate simplejson 2013-01-05 13:40:02 +01:00
Tom Christie
d905d1cbd3 Fix yaml rendering 2012-10-10 16:34:00 +01:00
Tom Christie
4b691c4027 Change package name: djangorestframework -> rest_framework 2012-09-20 13:06:27 +01:00