diff --git a/README.rst b/README.rst index 124b2a49..c143cce0 100644 --- a/README.rst +++ b/README.rst @@ -94,7 +94,7 @@ Rest Framework. Settings ^^^^^^^^ -One can either add ``rest_framework_ember.parsers.EmberJSONParser`` and +One can either add ``rest_framework_ember.parsers.JSONParser`` and ``rest_framework_ember.renderers.JSONRenderer`` to each ``ViewSet`` class, or override ``settings.REST_FRAMEWORK``:: @@ -104,9 +104,9 @@ override ``settings.REST_FRAMEWORK``:: 'PAGINATE_BY_PARAM': 'page_size', 'MAX_PAGINATE_BY': 100, 'DEFAULT_PAGINATION_SERIALIZER_CLASS': - 'rest_framework_ember.pagination.EmberPaginationSerializer', + 'rest_framework_ember.pagination.PaginationSerializer', 'DEFAULT_PARSER_CLASSES': ( - 'rest_framework_ember.parsers.EmberJSONParser', + 'rest_framework_ember.parsers.JSONParser', 'rest_framework.parsers.FormParser', 'rest_framework.parsers.MultiPartParser' ), diff --git a/example/api/api.py b/example/api/api.py index f21e0778..270fc101 100644 --- a/example/api/api.py +++ b/example/api/api.py @@ -62,7 +62,7 @@ class UserEmber(User): resource_name = 'data' renderer_classes = (renderers.JSONRenderer, ) - parser_classes = (parsers.EmberJSONParser, ) + parser_classes = (parsers.JSONParser, ) class EmberUserModelViewSet(viewsets.ModelViewSet): @@ -70,7 +70,7 @@ class EmberUserModelViewSet(viewsets.ModelViewSet): serializer_class = IdentitySerializer allowed_methods = ['GET', 'POST', 'PUT', ] renderer_classes = (renderers.JSONRenderer, ) - parser_classes = (parsers.EmberJSONParser, ) + parser_classes = (parsers.JSONParser, ) class MultipleIDMixinUserModelViewSet(mixins.MultipleIDMixin, diff --git a/example/settings.py b/example/settings.py index ae6c0286..1474fb72 100644 --- a/example/settings.py +++ b/example/settings.py @@ -38,9 +38,9 @@ 'PAGINATE_BY_PARAM': 'page_size', 'MAX_PAGINATE_BY': 100, 'DEFAULT_PAGINATION_SERIALIZER_CLASS': - 'rest_framework_ember.pagination.EmberPaginationSerializer', + 'rest_framework_ember.pagination.PaginationSerializer', 'DEFAULT_PARSER_CLASSES': ( - # 'rest_framework_ember.parsers.EmberJSONParser', + # 'rest_framework_ember.parsers.JSONParser', 'rest_framework.parsers.FormParser', 'rest_framework.parsers.MultiPartParser' ), @@ -49,7 +49,6 @@ 'rest_framework.renderers.JSONRenderer', 'rest_framework.renderers.BrowsableAPIRenderer', ), - 'DATETIME_FORMAT': '%Y-%m-%d %H:%M:%S', } diff --git a/rest_framework_ember/pagination.py b/rest_framework_ember/pagination.py index f1aaeeb5..dab6e929 100644 --- a/rest_framework_ember/pagination.py +++ b/rest_framework_ember/pagination.py @@ -70,7 +70,7 @@ def to_representation(self, value): -class EmberPaginationSerializer(pagination.BasePaginationSerializer): +class PaginationSerializer(pagination.BasePaginationSerializer): next = NextPageField(source='*') next_link = NextPageLinkField(source='*') page = PageField(source='*') @@ -79,3 +79,10 @@ class EmberPaginationSerializer(pagination.BasePaginationSerializer): count = serializers.ReadOnlyField(source='paginator.count') total = serializers.ReadOnlyField(source='paginator.num_pages') + +class EmberPaginationSerializer(PaginationSerializer): + """ + Backwards compatibility for name change + """ + pass + diff --git a/rest_framework_ember/parsers.py b/rest_framework_ember/parsers.py index 7587c05a..b9e3ee32 100644 --- a/rest_framework_ember/parsers.py +++ b/rest_framework_ember/parsers.py @@ -1,13 +1,13 @@ """ Parsers """ -from rest_framework.parsers import JSONParser +from rest_framework import parsers from rest_framework_ember.utils import get_resource_name from .utils import format_keys -class EmberJSONParser(JSONParser): +class JSONParser(parsers.JSONParser): """ By default, EmberJS sends a payload that looks like the following:: @@ -26,7 +26,15 @@ def parse(self, stream, media_type=None, parser_context=None): """ Parses the incoming bytestream as JSON and returns the resulting data """ - result = super(EmberJSONParser, self).parse(stream, media_type=None, + result = super(JSONParser, self).parse(stream, media_type=None, parser_context=None) resource = result.get(get_resource_name(parser_context.get('view', None))) return format_keys(resource, 'underscore') + + +class EmberJSONParser(JSONParser): + """ + Backward compatability for our first uniquely named parser + """ + pass +