Skip to content

Commit

Permalink
Updated names so renderer, parser, and pagination are the same format
Browse files Browse the repository at this point in the history
  • Loading branch information
jerel committed Dec 16, 2014
1 parent 4575958 commit 0d9a4cf
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 12 deletions.
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``::

Expand All @@ -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'
),
Expand Down
4 changes: 2 additions & 2 deletions example/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ class UserEmber(User):
resource_name = 'data'

renderer_classes = (renderers.JSONRenderer, )
parser_classes = (parsers.EmberJSONParser, )
parser_classes = (parsers.JSONParser, )


class EmberUserModelViewSet(viewsets.ModelViewSet):
queryset = auth_models.User.objects.all()
serializer_class = IdentitySerializer
allowed_methods = ['GET', 'POST', 'PUT', ]
renderer_classes = (renderers.JSONRenderer, )
parser_classes = (parsers.EmberJSONParser, )
parser_classes = (parsers.JSONParser, )


class MultipleIDMixinUserModelViewSet(mixins.MultipleIDMixin,
Expand Down
5 changes: 2 additions & 3 deletions example/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
),
Expand All @@ -49,7 +49,6 @@
'rest_framework.renderers.JSONRenderer',
'rest_framework.renderers.BrowsableAPIRenderer',
),
'DATETIME_FORMAT': '%Y-%m-%d %H:%M:%S',
}


Expand Down
9 changes: 8 additions & 1 deletion rest_framework_ember/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -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='*')
Expand All @@ -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

14 changes: 11 additions & 3 deletions rest_framework_ember/parsers.py
Original file line number Diff line number Diff line change
@@ -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::
Expand All @@ -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

0 comments on commit 0d9a4cf

Please sign in to comment.