{ "info": { "author": "Artem Vasin", "author_email": "nonameitem@me.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": "DRF Multiple Settings\n=======================\nDRF ViewSets supporting different settings for actions\n\n.. contents::\n **Table of Contents**\n :local:\n :depth: 2\n :backlinks: none\n\nRequirements\n------------\n**Django REST Framework** 3.0+\n\nInstallation\n------------\n\nInstall using pip:\n\n.. code-block:: sh\n\n pip install drf-multiple-settings\n\nUsage\n-----\n\n**drf-multiple-settings** provides you with class ``GenericMultipleSettingsViewSet`` which is a subclass of DRF's ``GenericViewSet`` with added support of different settings for actions.\n\nThis ViewSet does not contain any actions, so before you using it you should inherit this class adding mixins with desired actions (e.g. ``mixins.RetrieveModelMixin``, ``mixins.ListModelMixin`` to add ``retrieve`` and ``list`` actions)\n\nInstead of parametrize entire viewset with ``serializer_class``, ``filterset_class``, ``ordering_fields`` and ``ordering``, you should give this parameters to each action. To do so, declare next dictionaries with keys equal action names.\n\nSerializer settings\n~~~~~~~~~~~~~~~~~~~\n\nYou must provide ``serializer_classes`` dictionary to configure serializers in views, using ``GenericMultipleSettingsViewSet``. This dictionary is equivalent of GenericAPIView ``serializer_class`` field and it's value should contain values of same type.\n\nIf ``serializer_classes`` is not provided or does not contain value for processed action ``ViewConfigurationError`` exception will be raised\n\nFilters settings\n~~~~~~~~~~~~~~~~\n\nIf you wish to use different filtersets for different actions as well (which seems logical), your ViewSet should use filter backend from ``drf_multiple_settings.filter_backends`` package. As of now it contains only ``FilterBackend`` which overrides ``django_filters.rest_framework.DjangoFilterBackend`` and gives you access to ``filterset_classes`` dictionary. This dictionary is equivalent ``filterset_class`` field and it's value should contain values of same type. For more information on ``filterset_class`` and ``django-filter`` visit `django-filter documentation`_.\n\n.. _`django-filter documentation`: https://django-filter.readthedocs.io/en/master/\n\n\nIf you are using filtering backend which does not have implementation in ``drf_multiple_settings.filter_backends`` look at implementation for django-filter and write your own it's pretty straightforward. Feel free to contact me at github so I can include your implementation of other FilterBackend in package.\n\nOrdering settings\n~~~~~~~~~~~~~~~~~\n\nIf you wish to use different ordering setting for different actions as well (which also seems logical), your ViewSet\nshould use ``MultipleSettingsOrderingFilter`` which gives you access to this dictionaries:\n\n* Ordering fields dictionary: ``ordering_fields_set``\n* Default ordering dictionary: ``ordering_set``\n\nEach dictionary value should have type of corresponding normal GenericAPIView parameters. See Django REST Framework\ndocumentation if you unsure what it is.\n\n``get_response`` method\n-----------------------\n``GenericMultipleSettingsViewSet`` also provides `get_response` method for rendering response from action using whatever data you wish using current action's settings.\n\n.. code-block:: python\n\n def get_response(self, data, many):\n\nThis method gets QuerySet from ``data`` parameter paginate it if needed, then serialize it using serializer, set to this action and return serialized data as ``Response``. Parameter ``many`` tells serializer if it should serialize more then one element. Example of using this method can be found in Example section.\n\nMethod designed to be used inside an action-decorated methods. Usage outside actions was not tested.\n\n``ModelViewSet`` and ``ReadonlyModelViewSet``\n---------------------------------------------\n\n**DRF** provides two default ViewSets:\n\n* ``ModelViewSet`` for CRUD operations with model\n* ``ReadOnlyModelViewSet`` for read operations with model (``list`` and ``retrieve`` actions)\n\nTo ease it's usage **drf-multiple-settings** provides ``GenericMultipleSettingsViewSet`` subclasses with same functionality:\n\n* ``ModelMultipleSettingsViewSet``\n* ``ReadOnlyModelMultipleSettingsViewSet``\n\nExample\n-------\n\nFor this example we assume that we have following:\n\n* Two models `Title` and `Issue`\n* Three serializers\n\n * ``TitleListSerializer`` - serializer with main info about title\n * ``TitleDetailDerializer`` - serializer with detail info about title\n * ``IssueListSerializer``\n\n* Two FilterSet classes\n\n * ``TitleFilter`` - title filters\n * ``IssueFilter`` - issue filters\n\nAnd we wish create readonly API with following url structure\n\n* ``/title/`` - list of all titles\n* ``/title/{id}`` - detail info of title with id={id}\n* ``/title/{id}/issues`` - list of all issues of title with id={id}\n\nAdditionally we want to allow sorting titles by `name` and issues by `name`, `number` and `publish_date` with default ordering on ``name`` ascending and ``publish_date`` descending accordingly and allow user to filter results using corresponding FilterSet classes.\n\nWe can use **drf-multiple-settings** to implement this API as follows (views.py):\n\n.. code-block:: python\n\n from django.shortcuts import get_object_or_404\n from drf_multiple_settings.filter_backends.django_filters import FilterBackend\n from drf_multiple_settings.viewsets import ReadOnlyModelMultipleSettingsViewSet, MultipleSettingsOrderingFilter\n from rest_framework.decorators import action\n\n # ... Models and serializers imports...\n\n class TitleViewSet(ComicsDBBaseViewSet):\n queryset = models.Title.objects.all()\n filter_backends = (MultipleSettingsOrderingFilter, FilterBackend,)\n\n # Serializers\n serializer_classes = {\n 'list': TitleListSerializer,\n 'retrieve': TitleDetailSerializer,\n 'issues': IssueListSerializer\n }\n\n # FilterSets\n filterset_classes = {\n 'list': TitleFilter,\n 'issues': IssueFilter\n }\n\n # Ordering Parameters\n ordering_fields_set = {\n 'list': (\"name\",),\n 'issues': (\"name\", \"number\", \"publish_date\")\n }\n ordering_set = {\n 'list': (\"name\", ),\n 'issues': (\"-publish_date\", ),\n }\n\n @action(detail=True) # detail = True needed so DRF router include {id} in url\n def issues(self, request, pk):\n title = get_object_or_404(models.Title, pk=pk)\n titles = title.issues.all()\n titles = self.filter_queryset(titles)\n return self.get_response(titles, True)\n\n", "description_content_type": "text/x-rst", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/NoNameItem/drf-multiple-settings", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "drf-multiple-settings", "package_url": "https://pypi.org/project/drf-multiple-settings/", "platform": "", "project_url": "https://pypi.org/project/drf-multiple-settings/", "project_urls": { "Homepage": "https://github.com/NoNameItem/drf-multiple-settings" }, "release_url": "https://pypi.org/project/drf-multiple-settings/1.0.1/", "requires_dist": [ "djangorestframework (>=3.0)" ], "requires_python": "", "summary": "DRF ViewSets supporting different settings for actions", "version": "1.0.1" }, "last_serial": 4953996, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "46572be761c625aeb64c063edd318c9c", "sha256": "4c136c8661d04e453bcc8637a9c4e99d1804089d73bc6e645e2a253400c952f5" }, "downloads": -1, "filename": "drf_multiple_settings-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "46572be761c625aeb64c063edd318c9c", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 7962, "upload_time": "2019-03-05T19:14:42", "url": "https://files.pythonhosted.org/packages/60/79/c164438d514748620e4467fe34cea205f666565a4979a420d17016ed6d18/drf_multiple_settings-1.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "8c88ad87ad4e7b3fdf0fb7ba6a354b61", "sha256": "96540575cfd444b7a5cd0edd8635a0a262237ddfb940aa804cc3254f7efc393f" }, "downloads": -1, "filename": "drf-multiple-settings-1.0.0.tar.gz", "has_sig": false, "md5_digest": "8c88ad87ad4e7b3fdf0fb7ba6a354b61", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5635, "upload_time": "2019-03-05T19:14:44", "url": "https://files.pythonhosted.org/packages/2b/27/d9c7cc3b481ac8a8971e9da0a84121440a56583e6e56acdde619edae48aa/drf-multiple-settings-1.0.0.tar.gz" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "d1b4ec38b78ea3bc0e73a9e29e7a9624", "sha256": "55395329e8266ecda82b4bd9464d7eaca791274572e2fb45d88d597e603605a3" }, "downloads": -1, "filename": "drf_multiple_settings-1.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "d1b4ec38b78ea3bc0e73a9e29e7a9624", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 7953, "upload_time": "2019-03-18T13:49:40", "url": "https://files.pythonhosted.org/packages/fb/d5/b3443d8229b91fb52a037ac642778089613ebe3db547c62c34f7d315c3c4/drf_multiple_settings-1.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "141c1932b86e6776fbbacd3b55ba3e99", "sha256": "240b4b994a5997f9bce1de8cc7fc9d2759787222817bb440215a9703fb16d236" }, "downloads": -1, "filename": "drf-multiple-settings-1.0.1.tar.gz", "has_sig": false, "md5_digest": "141c1932b86e6776fbbacd3b55ba3e99", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5631, "upload_time": "2019-03-18T13:49:41", "url": "https://files.pythonhosted.org/packages/b9/af/ed589ec3f10e6f5d34f5674b341589057959d3965309331d971525fab5da/drf-multiple-settings-1.0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "d1b4ec38b78ea3bc0e73a9e29e7a9624", "sha256": "55395329e8266ecda82b4bd9464d7eaca791274572e2fb45d88d597e603605a3" }, "downloads": -1, "filename": "drf_multiple_settings-1.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "d1b4ec38b78ea3bc0e73a9e29e7a9624", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 7953, "upload_time": "2019-03-18T13:49:40", "url": "https://files.pythonhosted.org/packages/fb/d5/b3443d8229b91fb52a037ac642778089613ebe3db547c62c34f7d315c3c4/drf_multiple_settings-1.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "141c1932b86e6776fbbacd3b55ba3e99", "sha256": "240b4b994a5997f9bce1de8cc7fc9d2759787222817bb440215a9703fb16d236" }, "downloads": -1, "filename": "drf-multiple-settings-1.0.1.tar.gz", "has_sig": false, "md5_digest": "141c1932b86e6776fbbacd3b55ba3e99", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5631, "upload_time": "2019-03-18T13:49:41", "url": "https://files.pythonhosted.org/packages/b9/af/ed589ec3f10e6f5d34f5674b341589057959d3965309331d971525fab5da/drf-multiple-settings-1.0.1.tar.gz" } ] }