New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom serializer for non-Resource responses #817

Closed
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
2 participants
@acdha
Copy link
Contributor

acdha commented Feb 14, 2013

Previously there was no way to use a custom Serializer class for
non-Resource views. This change adds a serializer_class option to the
Api base class which will be used for the top-level view.

@andrewaustin

This comment has been minimized.

Copy link
Contributor

andrewaustin commented Feb 15, 2013

As per the contribution guidelines, could you please provide a unittest?

https://github.com/toastdriven/django-tastypie/blob/master/CONTRIBUTING

@acdha

This comment has been minimized.

Copy link
Contributor

acdha commented Feb 15, 2013

@andrewaustin Sorry for omitting the context on that - that request was part of an IRC discussion yesterday and I wanted to see what people thought of the API change before building it out further. One of the questions which I had was whether it'd make sense to follow it up by having Resource classes use their Api's serializer by default so you could avoid needing to customize it resource by resource.

Allow custom serializer for non-Resource responses
Previously there was no way to use a custom `Serializer` class for
non-`Resource` views. This change adds a `serializer_class` option to the
`Api` base class which will be used for the top-level view.
@acdha

This comment has been minimized.

Copy link
Contributor

acdha commented Feb 20, 2013

I've updated this with some basic tests but I'm also wondering whether tastypie should also return an HTTP 406 any time the request's Accept header doesn't contain at least one supported format.

@acdha

This comment has been minimized.

Copy link
Contributor

acdha commented Feb 21, 2013

I added some related code in #832 which causes tastypie to return HTTP 406 when the client requests a specific formats in the Accept header but none of them are supported.

acdha added a commit to acdha/django-tastypie that referenced this pull request Feb 22, 2013

Make default serialization formats use a Django setting
While it's possible to configure or subclass Serializer to accomplish
the same goal (or will be when django-tastypie#817 lands) that requires repetitive code
changes for a simple site policy like 'We only support JSON and XML',
which can now be as simple as adding a setting::

    TASTYPIE_DEFAULT_FORMATS = ['json', 'xml']

Changes:
* Serializer: __init__ will apply TASTYPIE_DEFAULT_FORMATS when
  self.formats is the default Serializer.formats
* Serializer: restructured __init__ to improve locality for format-
  related settings
* Restructured serializers documentation so format-related info is
  in one place & added a link to the new setting doc for
  TASTYPIE_DEFAULT_FORMATS

@acdha acdha closed this in 905ae88 Mar 19, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment