diff --git a/Makefile b/Makefile index b382b7e..226e944 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ clean-pyc: find . -name '*~' -exec rm -f {} + lint: - flake8 djangorestframework_camel_case tests + flake8 django_rest_framework_camel_case tests test: python setup.py test @@ -32,7 +32,7 @@ test-all: tox coverage: - coverage run --source djangorestframework_camel_case setup.py test + coverage run --source django_rest_framework_camel_case setup.py test coverage report -m coverage html open htmlcov/index.html diff --git a/README.rst b/README.rst index 9a6f94e..0793e68 100644 --- a/README.rst +++ b/README.rst @@ -26,31 +26,49 @@ Add the render and parser to your django settings file. REST_FRAMEWORK = { 'DEFAULT_RENDERER_CLASSES': ( - 'djangorestframework_camel_case.render.CamelCaseJSONRenderer', + 'django_rest_framework_camel_case.render.CamelCaseJSONRenderer', # Any other renders ), 'DEFAULT_PARSER_CLASSES': ( - 'djangorestframework_camel_case.parser.CamelCaseJSONParser', + 'django_rest_framework_camel_case.parser.CamelCaseJSONParser', # Any other parsers ), } # ... ================= -Swapping Renderer +Swapping Renderer and Parser ================= -By default the package uses `rest_framework.renderers.JSONRenderer`. If you want -to use another renderer (the only possible alternative is -`rest_framework.renderers.UnicodeJSONRenderer`, only available in DRF < 3.0), you must specify it in your django -settings file. +By default the package uses `rest_framework.renderers.JSONRenderer` and `rest_framework.parsers.JSONParser`. +If you want to use another renderer or parser, you must specify it in your django settings file. + +Currently Support + +.. code-block:: python + + 'RENDERER_CLASS': ( + 'rest_framework.renderers.JSONRenderer', + 'rest_framework.renderers.UnicodeJSONRenderer', # only available in DRF < 3.0 + 'rest_framework_google_json_style_api.renderers.JSONRenderer', + 'rest_framework_json_api.renderers.JSONRenderer', + ), + 'PARSER_CLASS': ( + 'rest_framework.parsers.JSONParser', + 'rest_framework_google_json_style_api.parsers.JSONParser', + 'rest_framework_json_api.parsers.JSONParser', + ) + + +Specify it in your django settings file. .. code-block:: python # ... JSON_CAMEL_CASE = { - 'RENDERER_CLASS': 'rest_framework.renderers.UnicodeJSONRenderer' + 'RENDERER_CLASS': 'rest_framework_google_json_style_api.renderers.JSONRenderer', + 'PARSER_CLASS': 'rest_framework_google_json_style_api.parsers.JSONParser', } # ... diff --git a/django_rest_framework_camel_case/__init__.py b/django_rest_framework_camel_case/__init__.py new file mode 100755 index 0000000..2fe5a6d --- /dev/null +++ b/django_rest_framework_camel_case/__init__.py @@ -0,0 +1,8 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +__author__ = 'Pocheng, playma' +__email__ = 'pcghuang@gmail.com, scott820914@gmail.com' +__url__ = 'https://github.com/Envive/djangorestframework-camel-case' +__comapny__ = 'envive.tw' +__version__ = 'v2.0.0' diff --git a/djangorestframework_camel_case/parser.py b/django_rest_framework_camel_case/parser.py similarity index 83% rename from djangorestframework_camel_case/parser.py rename to django_rest_framework_camel_case/parser.py index 8f55dbe..0b06515 100644 --- a/djangorestframework_camel_case/parser.py +++ b/django_rest_framework_camel_case/parser.py @@ -4,8 +4,8 @@ from django.conf import settings from rest_framework.parsers import ParseError, six -from djangorestframework_camel_case.settings import api_settings -from djangorestframework_camel_case.util import underscoreize +from django_rest_framework_camel_case.settings import api_settings +from django_rest_framework_camel_case.util import underscoreize class CamelCaseJSONParser(api_settings.PARSER_CLASS): diff --git a/djangorestframework_camel_case/render.py b/django_rest_framework_camel_case/render.py similarity index 68% rename from djangorestframework_camel_case/render.py rename to django_rest_framework_camel_case/render.py index 1825beb..52ced03 100644 --- a/djangorestframework_camel_case/render.py +++ b/django_rest_framework_camel_case/render.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from djangorestframework_camel_case.settings import api_settings -from djangorestframework_camel_case.util import camelize +from django_rest_framework_camel_case.settings import api_settings +from django_rest_framework_camel_case.util import camelize class CamelCaseJSONRenderer(api_settings.RENDERER_CLASS): diff --git a/djangorestframework_camel_case/settings.py b/django_rest_framework_camel_case/settings.py similarity index 82% rename from djangorestframework_camel_case/settings.py rename to django_rest_framework_camel_case/settings.py index 7324564..dde7de1 100644 --- a/djangorestframework_camel_case/settings.py +++ b/django_rest_framework_camel_case/settings.py @@ -26,9 +26,13 @@ 'RENDERER_CLASS': ( 'rest_framework.renderers.JSONRenderer', 'rest_framework.renderers.UnicodeJSONRenderer', + 'rest_framework_google_json_style_api.renderers.JSONRenderer', + 'rest_framework_json_api.renderers.JSONRenderer', ), 'PARSER_CLASS': ( 'rest_framework.parsers.JSONParser', + 'rest_framework_google_json_style_api.parsers.JSONParser', + 'rest_framework_json_api.parsers.JSONParser', ) } diff --git a/djangorestframework_camel_case/util.py b/django_rest_framework_camel_case/util.py similarity index 100% rename from djangorestframework_camel_case/util.py rename to django_rest_framework_camel_case/util.py diff --git a/djangorestframework_camel_case/__init__.py b/djangorestframework_camel_case/__init__.py deleted file mode 100755 index 9a3c87e..0000000 --- a/djangorestframework_camel_case/__init__.py +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -__author__ = 'Vitaly Babiy' -__email__ = 'vbabiy86@gmail.com' -__version__ = '1.0b1' diff --git a/setup.py b/setup.py index 3f3be92..89a1866 100755 --- a/setup.py +++ b/setup.py @@ -16,26 +16,26 @@ readme = open('README.rst').read() history = open('HISTORY.rst').read().replace('.. :changelog:', '') -import djangorestframework_camel_case +import django_rest_framework_camel_case setup( - name='djangorestframework-camel-case', - version=djangorestframework_camel_case.__version__, + name='django-rest-framework-camel-case', + version=django_rest_framework_camel_case.__version__, description='Camel case JSON support for Django REST framework.', long_description=readme + '\n\n' + history, - author='Vitaly Babiy', - author_email='vbabiy86@gmail.com', - url='https://github.com/vbabiy/djangorestframework-camel-case', + author=django_rest_framework_camel_case.__author__, + author_email=django_rest_framework_camel_case.__email__, + url=django_rest_framework_camel_case.__url__, packages=[ - 'djangorestframework_camel_case', + 'django_rest_framework_camel_case', ], - package_dir={'djangorestframework_camel_case': 'djangorestframework_camel_case'}, + package_dir={'django_rest_framework_camel_case': 'django_rest_framework_camel_case'}, include_package_data=True, install_requires=[ ], license="BSD", zip_safe=False, - keywords='djangorestframework_camel_case', + keywords='django_rest_framework_camel_case', classifiers=[ 'Development Status :: 2 - Pre-Alpha', 'Intended Audience :: Developers', diff --git a/tests.py b/tests.py index 04729c5..3c7f4db 100644 --- a/tests.py +++ b/tests.py @@ -3,7 +3,7 @@ from copy import deepcopy from unittest import TestCase -from djangorestframework_camel_case.util import camelize, underscoreize +from django_rest_framework_camel_case.util import camelize, underscoreize class UnderscoreToCamelTestCase(TestCase):