{ "info": { "author": "Manjit Kumar", "author_email": "manjit1727@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta" ], "description": "drf-url-filters\r\n===============\r\n\r\n**drf-url-filters** is a simple django app to apply filters on drf\r\nmodelviewset's queryset in a clean, simple and configurable way. It also\r\nsupports validations on incoming query params and their values. A\r\nbeautiful python package\r\n`voluptouos `__ is being used\r\nfor validations on the incoming query parameters. The best part about\r\nvoluptouos is you can define your own validations as per your query\r\nparams requirements.\r\n\r\n# Quick start\r\n-------------\r\n\r\n**Installation**\r\n\r\n1. Download ``drf-url-filters`` app package from this git repo or can be\r\n installed using python-pip like ``pip install drf-url-filters``.\r\n\r\n2. Add ``filters`` in INSTALLED\\_APPS of settings.py file of django\r\n project.\r\n\r\n**How it works**\r\n\r\n1. Your View or ModelViewSet should inherit ``FiltersMixin`` from\r\n ``filters.mixins.FiltersMixin``.\r\n\r\n2. To apply filters using ``drf-url-filters`` we need to configure our\r\n view to have a dict mapping ``filter_mappings`` which converts\r\n incoming query parameters to query you want to make on the column\r\n name on the queryset.\r\n\r\n3. Optionally, to perform any preprocessing on the incoming values for\r\n query params, add another dict ``filter_value_transformations`` which\r\n maps incoming query parameters to functions that should be applied to\r\n the values corresponding to them. The resultant value is used in the\r\n final filtering.\r\n\r\nvalidations.py\r\n==============\r\n\r\n.. code:: python\r\n\r\n import six\r\n\r\n from filters.schema import base_query_params_schema\r\n from filters.validations import (\r\n CSVofIntegers,\r\n IntegerLike,\r\n DatetimeWithTZ\r\n )\r\n\r\n # make a validation schema for players filter query params\r\n players_query_schema = base_query_param_schema.extend(\r\n {\r\n \"id\": IntegerLike(),\r\n \"name\": six.text_type, # Depends on python version\r\n \"team_id\": CSVofIntegers(), # /?team_id=1,2,3\r\n \"install_ts\": DatetimeWithTZ(),\r\n \"update_ts\": DatetimeWithTZ(),\r\n \"taller_than\": IntegerLike(),\r\n }\r\n )\r\n\r\nviews.py\r\n========\r\n\r\n.. code:: python\r\n\r\n\r\n from rest_framework import (\r\n viewsets,\r\n filters,\r\n )\r\n\r\n from .models import Player, Team\r\n from .pagination import ResultSetPagination\r\n from .serializers import PlayerSerializer, TeamSerializer\r\n from .validations import teams_query_schema, players_query_schema\r\n from filters.mixins import (\r\n FiltersMixin,\r\n )\r\n\r\n\r\n class PlayersViewSet(FiltersMixin, viewsets.ModelViewSet):\r\n \"\"\"\r\n This viewset automatically provides `list`, `create`, `retrieve`,\r\n `update` and `destroy` actions.\r\n \"\"\"\r\n queryset = Player.objects.prefetch_related(\r\n 'teams' # use prefetch_related to minimize db hits.\r\n ).all()\r\n serializer_class = PlayerSerializer\r\n pagination_class = ResultSetPagination\r\n filter_backends = (filters.OrderingFilter,)\r\n ordering_fields = ('id', 'name', 'update_ts')\r\n ordering = ('id',)\r\n\r\n # add a mapping of query_params to db_columns(queries)\r\n filter_mappings = {\r\n 'id': 'id',\r\n 'name': 'name__icontains',\r\n 'team_id': 'teams',\r\n 'install_ts': 'install_ts',\r\n 'update_ts': 'update_ts',\r\n 'update_ts__gte': 'update_ts__gte',\r\n 'update_ts__lte': 'update_ts__lte',\r\n 'taller_than': 'height__gte',\r\n }\r\n\r\n field_value_transformations = {\r\n 'taller_than': lambda val: val / 30.48 # cm to ft\r\n }\r\n\r\n # add validation on filters\r\n filter_validation_schema = players_query_schema\r\n\r\nWith the use of ``drf-url-filters`` adding a new filter on a new column\r\nis as simple as adding a new key in the dict. Prohibitting a filter on\r\nparticular column is same as removing a key value mapping from the\r\n``filter_mappings`` dict.\r\n\r\nLICENSE\r\n=======\r\n\r\n`MIT License `__ Copyright (c) 2016 Manjit Kumar.\r\n\r\nCredits\r\n=======\r\n\r\nSpecial thanks to authors of\r\n`voluptouos `__ and friends\r\n`cdax `__ and\r\n`saurabhjha `__ who encourage people to\r\ncontribute into open source community.\r\n\r\nSupport\r\n=======\r\n\r\nPlease [open an issue]\r\n(https://github.com/manjitkumar/drf-url-filters/issues/new) for support.", "description_content_type": null, "docs_url": null, "download_url": "https://github.com/manjitkumar/drf-url-filters/archive/v0.5.1.tar.gz", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/manjitkumar/drf-url-filters", "keywords": "drf-url-filters,filters,queryparameters", "license": "UNKNOWN", "maintainer": "", "maintainer_email": "", "name": "drf-url-filters", "package_url": "https://pypi.org/project/drf-url-filters/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/drf-url-filters/", "project_urls": { "Download": "https://github.com/manjitkumar/drf-url-filters/archive/v0.5.1.tar.gz", "Homepage": "https://github.com/manjitkumar/drf-url-filters" }, "release_url": "https://pypi.org/project/drf-url-filters/0.5.1/", "requires_dist": null, "requires_python": null, "summary": "A django app to apply filters on drf querysets using query params with validations using voluptuous.", "version": "0.5.1" }, "last_serial": 2977063, "releases": { "0.1.0": [], "0.1.1": [], "0.1.2": [ { "comment_text": "", "digests": { "md5": "6c032f778cafde2c4722be8a4762290f", "sha256": "235069c29c7e4d53276cda0a0df3b4eaf7962d00644bffef67aa2f202848e170" }, "downloads": -1, "filename": "drf-url-filters-0.1.2.tar.gz", "has_sig": false, "md5_digest": "6c032f778cafde2c4722be8a4762290f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6866, "upload_time": "2016-04-14T16:49:26", "url": "https://files.pythonhosted.org/packages/35/c9/be09443673d37d000745e245bf234a943f3f5e98b6e20c9b35f261cbf31c/drf-url-filters-0.1.2.tar.gz" } ], "0.1.3": [ { "comment_text": "", "digests": { "md5": "684b974fb04fcc1f320d2e50660d0521", "sha256": "e6ad7bc74f5996ba64781340e24fe980556dd049b5eb4ffda1bf008c4d251be0" }, "downloads": -1, "filename": "drf-url-filters-0.1.3.tar.gz", "has_sig": false, "md5_digest": "684b974fb04fcc1f320d2e50660d0521", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6864, "upload_time": "2016-04-24T09:20:29", "url": "https://files.pythonhosted.org/packages/3d/b9/94f6cbf4db17f88a77a89d56af0b6330051bc5f99a3df00ad26102ff0929/drf-url-filters-0.1.3.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "fc8586728c87565461412cac0a1f8ea9", "sha256": "d92fbe2b97d2e7434d368c0d74305244f06539dec49de2bb7003bc521b8f07b8" }, "downloads": -1, "filename": "drf-url-filters-0.2.0.tar.gz", "has_sig": false, "md5_digest": "fc8586728c87565461412cac0a1f8ea9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7232, "upload_time": "2016-09-21T11:16:51", "url": "https://files.pythonhosted.org/packages/9e/8c/6c2bd7f98721d14051607b8dd28d621cd3e7e634a800b79166faf8cfe289/drf-url-filters-0.2.0.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "a102ca555b85dc2bb3ab8cb7a51cabd4", "sha256": "02e32e40838200498bbef7d23b8fc21f5b93502be11994e810d977fafcf7ed54" }, "downloads": -1, "filename": "drf-url-filters-0.2.1.tar.gz", "has_sig": false, "md5_digest": "a102ca555b85dc2bb3ab8cb7a51cabd4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6468, "upload_time": "2017-02-20T11:25:02", "url": "https://files.pythonhosted.org/packages/b5/66/273d4717b632560caa72dba9e49dc6e55cdefe66c33929ff5a254beafa54/drf-url-filters-0.2.1.tar.gz" } ], "0.5.1": [ { "comment_text": "", "digests": { "md5": "aa0a0c18fe7e470b139ace735f004a17", "sha256": "fdae4c970fd8ec7b19be825e238490d57b6155c76731732ed5edb250b044f973" }, "downloads": -1, "filename": "drf-url-filters-0.5.1.tar.gz", "has_sig": false, "md5_digest": "aa0a0c18fe7e470b139ace735f004a17", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8337, "upload_time": "2017-06-25T07:40:21", "url": "https://files.pythonhosted.org/packages/ef/e5/2eb2289a5fa80583721ed8a6d471eb72143d37bdbe68dcf577f02ec48c64/drf-url-filters-0.5.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "aa0a0c18fe7e470b139ace735f004a17", "sha256": "fdae4c970fd8ec7b19be825e238490d57b6155c76731732ed5edb250b044f973" }, "downloads": -1, "filename": "drf-url-filters-0.5.1.tar.gz", "has_sig": false, "md5_digest": "aa0a0c18fe7e470b139ace735f004a17", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8337, "upload_time": "2017-06-25T07:40:21", "url": "https://files.pythonhosted.org/packages/ef/e5/2eb2289a5fa80583721ed8a6d471eb72143d37bdbe68dcf577f02ec48c64/drf-url-filters-0.5.1.tar.gz" } ] }