Skip to content
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

Support two different kinds of style api #47

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
34 changes: 26 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
# ...

Expand Down
8 changes: 8 additions & 0 deletions django_rest_framework_camel_case/__init__.py
Original file line number Diff line number Diff line change
@@ -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'
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
)
}

Expand Down
6 changes: 0 additions & 6 deletions djangorestframework_camel_case/__init__.py

This file was deleted.

18 changes: 9 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down