djangorestframework-camel-case


Namedjangorestframework-camel-case JSON
Version 1.3.0 PyPI version JSON
download
home_pagehttps://github.com/vbabiy/djangorestframework-camel-case
SummaryCamel case JSON support for Django REST framework.
upload_time2021-12-14 13:30:31
maintainer
docs_urlNone
authorVitaly Babiy
requires_python>=3.5
licenseBSD
keywords djangorestframework_camel_case
VCS
bugtrack_url
requirements djangorestframework django
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ====================================
Django REST Framework JSON CamelCase
====================================

.. image:: https://travis-ci.org/vbabiy/djangorestframework-camel-case.svg?branch=master
        :target: https://travis-ci.org/vbabiy/djangorestframework-camel-case

.. image:: https://badge.fury.io/py/djangorestframework-camel-case.svg
    :target: https://badge.fury.io/py/djangorestframework-camel-case

Camel case JSON support for Django REST framework.

============
Installation
============

At the command line::

    $ pip install djangorestframework-camel-case

Add the render and parser to your django settings file.

.. code-block:: python

    # ...
    REST_FRAMEWORK = {

        'DEFAULT_RENDERER_CLASSES': (
            'djangorestframework_camel_case.render.CamelCaseJSONRenderer',
            'djangorestframework_camel_case.render.CamelCaseBrowsableAPIRenderer',
            # Any other renders
        ),

        'DEFAULT_PARSER_CLASSES': (
            # If you use MultiPartFormParser or FormParser, we also have a camel case version
            'djangorestframework_camel_case.parser.CamelCaseFormParser',
            'djangorestframework_camel_case.parser.CamelCaseMultiPartParser',
            'djangorestframework_camel_case.parser.CamelCaseJSONParser',
            # Any other parsers
        ),
    }
    # ...

=================
Swapping Renderer
=================

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.

.. code-block:: python

    # ...
    JSON_CAMEL_CASE = {
        'RENDERER_CLASS': 'rest_framework.renderers.UnicodeJSONRenderer'
    }
    # ...

=====================
Underscoreize Options
=====================


**No Underscore Before Number**


As raised in `this comment <https://github.com/krasa/StringManipulation/issues/8#issuecomment-121203018>`_
there are two conventions of snake case.

.. code-block:: text

    # Case 1 (Package default)
    v2Counter -> v_2_counter
    fooBar2 -> foo_bar_2

    # Case 2
    v2Counter -> v2_counter
    fooBar2 -> foo_bar2


By default, the package uses the first case. To use the second case, specify it in your django settings file.

.. code-block:: python

    REST_FRAMEWORK = {
        # ...
        'JSON_UNDERSCOREIZE': {
            'no_underscore_before_number': True,
        },
        # ...
    }

Alternatively, you can change this behavior on a class level by setting `json_underscoreize`:

.. code-block:: python

    from djangorestframework_camel_case.parser import CamelCaseJSONParser
    from rest_framework.generics import CreateAPIView

    class NoUnderscoreBeforeNumberCamelCaseJSONParser(CamelCaseJSONParser):
        json_underscoreize = {'no_underscore_before_number': True}

    class MyView(CreateAPIView):
        queryset = MyModel.objects.all()
        serializer_class = MySerializer
        parser_classes = (NoUnderscoreBeforeNumberCamelCaseJSONParser,)

=============
Ignore Fields
=============

You can also specify fields which should not have their data changed.
The specified field(s) would still have their name change, but there would be no recursion.
For example:

.. code-block:: python

    data = {"my_key": {"do_not_change": 1}}

Would become:

.. code-block:: python

    {"myKey": {"doNotChange": 1}}

However, if you set in your settings:

.. code-block:: python

    REST_FRAMEWORK = {
        # ...
        "JSON_UNDERSCOREIZE": {
            # ...
            "ignore_fields": ("my_key",),
            # ...
        },
        # ...
    }

The `my_key` field would not have its data changed:

.. code-block:: python

    {"myKey": {"do_not_change": 1}}

=============
Running Tests
=============

To run the current test suite, execute the following from the root of he project::

    $ python -m unittest discover


=======
License
=======

* Free software: BSD license




History
=======
1.3.0 (2021-11-14)
------------------
- Merge pull request #104
- Merge pull request #99
- Merge pull request #100
- Merge pull request #90
- Merge pull request #92


1.2.0 (2020-06-16)
------------------

- added ignore_fields
- Merge pull request #88
- Merge pull request #84
- Merge pull request #77
- Merge pull request #73

1.1.2 (2019-10-22)
------------------

- Merge pull request #63
- Merge pull request #70
- Merge pull request #71

1.1.1 (2019-09-09)
------------------

- Add json_underscoreize as CamelCaseJSONParser class attribute #44

1.1.0 (2019-09-09)
------------------

Long awaited stable release:

Changes can be viewed:
https://github.com/vbabiy/djangorestframework-camel-case/compare/e6db468...39ae6bb

0.1.0 (2013-12-20)
------------------

* First release on PyPI.
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/vbabiy/djangorestframework-camel-case",
    "name": "djangorestframework-camel-case",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.5",
    "maintainer_email": "",
    "keywords": "djangorestframework_camel_case",
    "author": "Vitaly Babiy",
    "author_email": "vbabiy86@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/28/0a/58370bdcd0a780bfb92ecf34cfdcf702080c9ede8607d5e601846971a927/djangorestframework-camel-case-1.3.0.tar.gz",
    "platform": "",
    "description": "====================================\nDjango REST Framework JSON CamelCase\n====================================\n\n.. image:: https://travis-ci.org/vbabiy/djangorestframework-camel-case.svg?branch=master\n        :target: https://travis-ci.org/vbabiy/djangorestframework-camel-case\n\n.. image:: https://badge.fury.io/py/djangorestframework-camel-case.svg\n    :target: https://badge.fury.io/py/djangorestframework-camel-case\n\nCamel case JSON support for Django REST framework.\n\n============\nInstallation\n============\n\nAt the command line::\n\n    $ pip install djangorestframework-camel-case\n\nAdd the render and parser to your django settings file.\n\n.. code-block:: python\n\n    # ...\n    REST_FRAMEWORK = {\n\n        'DEFAULT_RENDERER_CLASSES': (\n            'djangorestframework_camel_case.render.CamelCaseJSONRenderer',\n            'djangorestframework_camel_case.render.CamelCaseBrowsableAPIRenderer',\n            # Any other renders\n        ),\n\n        'DEFAULT_PARSER_CLASSES': (\n            # If you use MultiPartFormParser or FormParser, we also have a camel case version\n            'djangorestframework_camel_case.parser.CamelCaseFormParser',\n            'djangorestframework_camel_case.parser.CamelCaseMultiPartParser',\n            'djangorestframework_camel_case.parser.CamelCaseJSONParser',\n            # Any other parsers\n        ),\n    }\n    # ...\n\n=================\nSwapping Renderer\n=================\n\nBy default the package uses `rest_framework.renderers.JSONRenderer`. If you want\nto use another renderer (the only possible alternative is\n`rest_framework.renderers.UnicodeJSONRenderer`, only available in DRF < 3.0), you must specify it in your django\nsettings file.\n\n.. code-block:: python\n\n    # ...\n    JSON_CAMEL_CASE = {\n        'RENDERER_CLASS': 'rest_framework.renderers.UnicodeJSONRenderer'\n    }\n    # ...\n\n=====================\nUnderscoreize Options\n=====================\n\n\n**No Underscore Before Number**\n\n\nAs raised in `this comment <https://github.com/krasa/StringManipulation/issues/8#issuecomment-121203018>`_\nthere are two conventions of snake case.\n\n.. code-block:: text\n\n    # Case 1 (Package default)\n    v2Counter -> v_2_counter\n    fooBar2 -> foo_bar_2\n\n    # Case 2\n    v2Counter -> v2_counter\n    fooBar2 -> foo_bar2\n\n\nBy default, the package uses the first case. To use the second case, specify it in your django settings file.\n\n.. code-block:: python\n\n    REST_FRAMEWORK = {\n        # ...\n        'JSON_UNDERSCOREIZE': {\n            'no_underscore_before_number': True,\n        },\n        # ...\n    }\n\nAlternatively, you can change this behavior on a class level by setting `json_underscoreize`:\n\n.. code-block:: python\n\n    from djangorestframework_camel_case.parser import CamelCaseJSONParser\n    from rest_framework.generics import CreateAPIView\n\n    class NoUnderscoreBeforeNumberCamelCaseJSONParser(CamelCaseJSONParser):\n        json_underscoreize = {'no_underscore_before_number': True}\n\n    class MyView(CreateAPIView):\n        queryset = MyModel.objects.all()\n        serializer_class = MySerializer\n        parser_classes = (NoUnderscoreBeforeNumberCamelCaseJSONParser,)\n\n=============\nIgnore Fields\n=============\n\nYou can also specify fields which should not have their data changed.\nThe specified field(s) would still have their name change, but there would be no recursion.\nFor example:\n\n.. code-block:: python\n\n    data = {\"my_key\": {\"do_not_change\": 1}}\n\nWould become:\n\n.. code-block:: python\n\n    {\"myKey\": {\"doNotChange\": 1}}\n\nHowever, if you set in your settings:\n\n.. code-block:: python\n\n    REST_FRAMEWORK = {\n        # ...\n        \"JSON_UNDERSCOREIZE\": {\n            # ...\n            \"ignore_fields\": (\"my_key\",),\n            # ...\n        },\n        # ...\n    }\n\nThe `my_key` field would not have its data changed:\n\n.. code-block:: python\n\n    {\"myKey\": {\"do_not_change\": 1}}\n\n=============\nRunning Tests\n=============\n\nTo run the current test suite, execute the following from the root of he project::\n\n    $ python -m unittest discover\n\n\n=======\nLicense\n=======\n\n* Free software: BSD license\n\n\n\n\nHistory\n=======\n1.3.0 (2021-11-14)\n------------------\n- Merge pull request #104\n- Merge pull request #99\n- Merge pull request #100\n- Merge pull request #90\n- Merge pull request #92\n\n\n1.2.0 (2020-06-16)\n------------------\n\n- added ignore_fields\n- Merge pull request #88\n- Merge pull request #84\n- Merge pull request #77\n- Merge pull request #73\n\n1.1.2 (2019-10-22)\n------------------\n\n- Merge pull request #63\n- Merge pull request #70\n- Merge pull request #71\n\n1.1.1 (2019-09-09)\n------------------\n\n- Add json_underscoreize as CamelCaseJSONParser class attribute #44\n\n1.1.0 (2019-09-09)\n------------------\n\nLong awaited stable release:\n\nChanges can be viewed:\nhttps://github.com/vbabiy/djangorestframework-camel-case/compare/e6db468...39ae6bb\n\n0.1.0 (2013-12-20)\n------------------\n\n* First release on PyPI.",
    "bugtrack_url": null,
    "license": "BSD",
    "summary": "Camel case JSON support for Django REST framework.",
    "version": "1.3.0",
    "split_keywords": [
        "djangorestframework_camel_case"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "d275b70af18854daf54e52d622bb2662",
                "sha256": "df591362ffa448c8f0a354c56ae8a53fb7abbb15e222951d0c6f5f781633907e"
            },
            "downloads": -1,
            "filename": "djangorestframework-camel-case-1.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "d275b70af18854daf54e52d622bb2662",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.5",
            "size": 8209,
            "upload_time": "2021-12-14T13:30:31",
            "upload_time_iso_8601": "2021-12-14T13:30:31.509740Z",
            "url": "https://files.pythonhosted.org/packages/28/0a/58370bdcd0a780bfb92ecf34cfdcf702080c9ede8607d5e601846971a927/djangorestframework-camel-case-1.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2021-12-14 13:30:31",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "vbabiy",
    "github_project": "djangorestframework-camel-case",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "djangorestframework",
            "specs": [
                [
                    ">=",
                    "2.0.0"
                ]
            ]
        },
        {
            "name": "django",
            "specs": [
                [
                    ">=",
                    "2.2"
                ]
            ]
        }
    ],
    "tox": true,
    "lcname": "djangorestframework-camel-case"
}
        
Elapsed time: 0.07651s