{ "info": { "author": "3YOURMIND", "author_email": "01tonythomas@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "# drf-payload-customizer\n\n[![License](https://img.shields.io/github/license/3yourmind/drf-payload-customizer.svg)](./LICENSE)\n[![Contributing](https://img.shields.io/badge/PR-welcome-green.svg)](https://github.com/3YOURMIND/drf-payload-customizer/pulls)\n[![3yourminD-Careers](https://img.shields.io/badge/3YOURMIND-Hiring-brightgreen.svg)](https://www.3yourmind.com/career)\n[![Stars](https://img.shields.io/github/stars/3YOURMIND/drf-payload-customizer.svg?style=social&label=Stars)](https://github.com/3YOURMIND/drf-payload-customizer/stargazers)\n\nThis package allows you to customize your `django-rest-framework` serializer i/o to make modern frontend frameworks happy.\nThe following modifications are supported: \n1. **Transformation**: Convert all `keys` in API output to `camelCase`. Also\n on reception of an input on an API, transform all inputs to `snake_case`. \n2. **Translation**: Rename a `key` in your API schema. (works in both \ndirection). \n3. **Nullify/Balankify**: Replace `\"\"` with `None` on output direction and \nvice versa in the other direction. \n\nWe introduce 3 seperate `Mixins` that can you can subclass your `APIView` \nfrom to achieve 1-3. They are: \n1. `PayloadTransformationMixin`: Perform transformation (1) above. Has an \noptional parameter `PAYLOAD_TRANSFORM_NESTED` (see tests) which you can set \nto `True` in your `Serializer.Meta` class to recursively convert all nested \ndictionaries. This feature only works in the output direction. \n2. `PayloadTranslationMixin`: Perform translation (2) above. You can specify\n custom mappings using a `field_mappings` dict in your `Serializer.Meta` \n class.\n3. `PayloadNoNullOrNoneMixin`: Perform nullify/blankify (3) above. \n\n## Requirements\nThe `mixin` requires you to have the following dependencies:\n```\ndjangorestframework==3.8.2\n```\nWe are positive it would work with other versions of Django Rest Framework \nas well. However, you will require `Django==2.1.2` to run the unit tests. \n\n## Use it in your project\n\nYou can use all three of the mixins together like this in your project using\nour `drf_payload_customizer.mixins.PayloadConverterMixin` mixin. The mixin \nperforms (1-3) modifications listed above. Here is how it is implemented:\n```\nclass PayloadConverterMixin(PayloadTransformationMixin,\n PayloadTranslationMixin,\n PayloadNoNullOrNoneMixin):\n \"\"\"\n Use this mixin in all of our Serializers, to convert the JSON into a\n format that is easier consumed by modern front-ends.\n \"\"\"\n\n def to_representation(self, instance):\n return super().to_representation(instance)\n\n def to_internal_value(self, camel_cased):\n return super().to_internal_value(camel_cased)\n``` \nNow, subclass your `APIViews` with `PayloadConverterMixin` as given below:\n\n```\nfrom drf_payload_customizer.mixins import PayloadConverterMixin\n\nclass CustomTestModelSerializer(PayloadConverterMixin, ModelSerializer):\n class Meta:\n model = TestModel\n fields = ('parama', 'param_b',)\n PAYLOAD_TRANSFORM_NESTED = True\n # The mapping is the snake_case of your expected o/p\n field_mappings = {\n 'parama': 'param_a' \n }\n \n# Now your serializer would output: \ntest_serializer = CustomTestModelSerializer(obj)\nJSONRenderer().render(test_serializer.data)\n> {'paramA': '', 'paramB': None}\n\n# Your serializer also admits input in the same format: \ncontent = json.dumps({'paramA': 'testA', 'paramB': 3}).encode()\nstream = BytesIO(content)\ndata = JSONParser().parse(stream)\nserializer = CustomTestModelSerializer(data=data)\nself.assertTrue(serializer.is_valid())\n> True\n```\n\n## To run tests \n\n```sh\ncd drf_payload_customizer\n# Make sure you change to a virutal environment according to your project setup\npython setup.py install \npip install -r requirements.txt \ncd tests/test_app/ \npython manage.py test \n```", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/3YOURMIND/drf-payload-customizer", "keywords": "django drf rest converter mapping case transformation", "license": "Apache License 2.0", "maintainer": "", "maintainer_email": "", "name": "drf-payload-customizer", "package_url": "https://pypi.org/project/drf-payload-customizer/", "platform": "", "project_url": "https://pypi.org/project/drf-payload-customizer/", "project_urls": { "Homepage": "https://github.com/3YOURMIND/drf-payload-customizer" }, "release_url": "https://pypi.org/project/drf-payload-customizer/0.0.4/", "requires_dist": null, "requires_python": "", "summary": "This package allows you to customize your django-rest-framework serializer i/o to make modern frontend frameworks happy.", "version": "0.0.4" }, "last_serial": 4993213, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "23f36ae41d84e4471897bb9dfc389a7d", "sha256": "9c7b10d83bd1639ae8064c9a049a4b7ef8b2c91b096a25e11bc27118661af605" }, "downloads": -1, "filename": "drf_payload_customizer-0.0.1-py3.6.egg", "has_sig": false, "md5_digest": "23f36ae41d84e4471897bb9dfc389a7d", "packagetype": "bdist_egg", "python_version": "3.6", "requires_python": null, "size": 10867, "upload_time": "2018-11-03T09:57:01", "url": "https://files.pythonhosted.org/packages/97/cc/bd18a4eb05659c55c02f70f33830871a2def9a9765100886218113ec0e93/drf_payload_customizer-0.0.1-py3.6.egg" }, { "comment_text": "", "digests": { "md5": "09a6ac449c30f56970d6053bdbe83ba2", "sha256": "0543b5eb5957bf9703f005b400811c78768e03ce62dfa33ac749ea51454d545b" }, "downloads": -1, "filename": "drf-payload-customizer-0.0.1.tar.gz", "has_sig": false, "md5_digest": "09a6ac449c30f56970d6053bdbe83ba2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3973, "upload_time": "2018-11-03T09:57:02", "url": "https://files.pythonhosted.org/packages/7b/67/77db37e079651542f69d9bc8621a342bb959701bc9d8e8c9ea4c9cedc6ba/drf-payload-customizer-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "5c1a78ab2feb2a957ac1684176f30420", "sha256": "ca9cdd045943e11fbbfb65c43db17c2b55acc22d2d3abc0c1cf7477287561cc5" }, "downloads": -1, "filename": "drf_payload_customizer-0.0.2-py3.6.egg", "has_sig": false, "md5_digest": "5c1a78ab2feb2a957ac1684176f30420", "packagetype": "bdist_egg", "python_version": "3.6", "requires_python": null, "size": 11655, "upload_time": "2018-11-06T09:57:04", "url": "https://files.pythonhosted.org/packages/db/ce/92d5c44a69a8b2a77b1061ab2815ff4705ecfb31e199ffd162093969a152/drf_payload_customizer-0.0.2-py3.6.egg" }, { "comment_text": "", "digests": { "md5": "e6796f1d13c5d92f9f9edd93d998ce18", "sha256": "9af9b403e6eb6a99b2b3b56c0b329a0840b30cac93ce009782bc507a7a63d361" }, "downloads": -1, "filename": "drf-payload-customizer-0.0.2.tar.gz", "has_sig": false, "md5_digest": "e6796f1d13c5d92f9f9edd93d998ce18", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4770, "upload_time": "2018-11-03T10:17:42", "url": "https://files.pythonhosted.org/packages/0e/df/2b0821528580f25564e97d7c5b4654c6602c75cdafdae404723342e0c803/drf-payload-customizer-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "9ffc6605e0bd35f6fc57022b17b7752e", "sha256": "908baa39256425808ba7cbd285b0e29394f143da9ff3a96aea2f2af5043a4350" }, "downloads": -1, "filename": "drf_payload_customizer-0.0.3-py3.6.egg", "has_sig": false, "md5_digest": "9ffc6605e0bd35f6fc57022b17b7752e", "packagetype": "bdist_egg", "python_version": "3.6", "requires_python": null, "size": 11655, "upload_time": "2018-11-06T09:57:06", "url": "https://files.pythonhosted.org/packages/1f/1c/b343ce520fde13d5245cdacf524e8c9891479d840ce6e1bc61fd06b0d962/drf_payload_customizer-0.0.3-py3.6.egg" }, { "comment_text": "", "digests": { "md5": "fabc73f8845e844a39ca34905785faf9", "sha256": "d2d21e423e96fa93d01c48d0307f1d5aeb2196436e59cb82ddd18e8aa99a4ab1" }, "downloads": -1, "filename": "drf-payload-customizer-0.0.3.tar.gz", "has_sig": false, "md5_digest": "fabc73f8845e844a39ca34905785faf9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4798, "upload_time": "2018-11-06T10:00:49", "url": "https://files.pythonhosted.org/packages/d9/d3/8431e4f21136a7d442d74c277bea041330bc5de9fee783482022f4c4d54e/drf-payload-customizer-0.0.3.tar.gz" } ], "0.0.4": [ { "comment_text": "", "digests": { "md5": "8a3b83c61202232724fcbb3ff687bd84", "sha256": "811ac3bbd6eb8e1dc0cbf4f888f090e96e3a5e129fa9fcd7fd4405030c4419be" }, "downloads": -1, "filename": "drf-payload-customizer-0.0.4.tar.gz", "has_sig": false, "md5_digest": "8a3b83c61202232724fcbb3ff687bd84", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4795, "upload_time": "2018-11-06T10:06:17", "url": "https://files.pythonhosted.org/packages/e3/c6/d765a1d431a47316dd3570721f9ac52cccb437cfff604bef270ee171dbd7/drf-payload-customizer-0.0.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "8a3b83c61202232724fcbb3ff687bd84", "sha256": "811ac3bbd6eb8e1dc0cbf4f888f090e96e3a5e129fa9fcd7fd4405030c4419be" }, "downloads": -1, "filename": "drf-payload-customizer-0.0.4.tar.gz", "has_sig": false, "md5_digest": "8a3b83c61202232724fcbb3ff687bd84", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4795, "upload_time": "2018-11-06T10:06:17", "url": "https://files.pythonhosted.org/packages/e3/c6/d765a1d431a47316dd3570721f9ac52cccb437cfff604bef270ee171dbd7/drf-payload-customizer-0.0.4.tar.gz" } ] }