{ "info": { "author": "jozo", "author_email": "hi@jozo.io", "bugtrack_url": null, "classifiers": [ "Operating System :: OS Independent", "Programming Language :: Python :: 2", "Programming Language :: Python :: 3" ], "description": "# django-rest-framework-condition\n\n[![Build Status](https://travis-ci.com/jozo/django-rest-framework-condition.svg?branch=master)](https://travis-ci.com/jozo/django-rest-framework-condition)\n[![codecov](https://codecov.io/gh/jozo/django-rest-framework-condition/branch/master/graph/badge.svg)](https://codecov.io/gh/jozo/django-rest-framework-condition)\n\n\nThis package allows you to use [`@condition`](https://docs.djangoproject.com/en/2.1/topics/conditional-view-processing/) decorator from Django on ViewSet or\nAPIView from Django Rest Framework. In other words, you can use http headers \nETag and Last-modified with you APIs.\n\nIt doesn't create custom implementation of etags or last-modified header but uses ones from Django which means you can be sure it will be updated by Django's authors. \n\nSimilarly as in Django you can use shortcut decorators `@last_modified` and\n`@etag`.\n\nTested with:\n* Python: 2.7, 3.7\n* Django: 1.11, 2.0, 2.1, 2.2\n* Django Rest Framework: 3.8, 3.9\n\n\nInstallation\n------------\n\n```bash\npip install django-rest-framework-condition\n```\n\n\nUsage\n-----\n\nUse decorators same way as with Django views.\n\n**Last-modified example**\n\n```python\nfrom datetime import datetime\n\nfrom rest_framework.response import Response\nfrom rest_framework.views import APIView\nfrom rest_framework_condition import last_modified\n\n\nclass LastModifiedApiView(APIView):\n @last_modified(lambda _: datetime(2019, 1, 1))\n def get(self, request):\n return Response({'data': 'I have Last-Modified header!'})\n```\n\n**ETag example**\n\n```python\nimport hashlib\n\nfrom rest_framework.response import Response\nfrom rest_framework.views import APIView\nfrom rest_framework_condition import etag\n\n\ndef my_etag(request, *args, **kwargs):\n return hashlib.md5(':'.join(request.GET.dict().values()).encode('utf-8')).hexdigest()\n\n\nclass EtagApiView(APIView):\n @etag(my_etag)\n def get(self, request):\n return Response({'data': 'I have Etag!'})\n```\n\n**Both ETag and Last-Modified example**\n\n```python\nimport hashlib\nfrom datetime import datetime\n\nfrom rest_framework.response import Response\nfrom rest_framework.views import APIView\nfrom rest_framework_condition import condition\n\n\ndef my_etag(request, *args, **kwargs):\n return hashlib.md5(':'.join(request.GET.dict().values()).encode('utf-8')).hexdigest()\n\n\ndef my_last_modified(request, *args, **kwargs):\n return datetime(2019, 1, 1)\n\n\nclass ConditionApiView(APIView):\n @condition(etag_func=my_etag, last_modified_func=my_last_modified)\n def get(self, request):\n return Response({'data': 'I have both Last-Modified and Etag!'})\n```\n\n\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/jozo/django-rest-framework-condition", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "django-rest-framework-condition", "package_url": "https://pypi.org/project/django-rest-framework-condition/", "platform": "", "project_url": "https://pypi.org/project/django-rest-framework-condition/", "project_urls": { "Homepage": "https://github.com/jozo/django-rest-framework-condition" }, "release_url": "https://pypi.org/project/django-rest-framework-condition/0.1.1/", "requires_dist": [ "Django" ], "requires_python": "", "summary": "Decorators @condition, @last_modified and @etag for Django Rest Framework", "version": "0.1.1" }, "last_serial": 5113430, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "8c3f0a4561eca95508b14e7fc12085e3", "sha256": "a56fe65ff7c50cda351158c8890dec7493e4aec43b0f1d7985b4e4c8d122b768" }, "downloads": -1, "filename": "django_rest_framework_condition-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "8c3f0a4561eca95508b14e7fc12085e3", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 18395, "upload_time": "2019-03-21T20:25:50", "url": "https://files.pythonhosted.org/packages/bc/2c/815bb665aaf4b118461921559f7ffb67df35cd7d063fc3652114feb6a379/django_rest_framework_condition-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "f94a0aabfb9b1ad4e9159b64012bd1fb", "sha256": "1b11a5bc26d33bb3fb50694688a8fbf096f28822a38c33c4fb9da9ee43ae762f" }, "downloads": -1, "filename": "django-rest-framework-condition-0.1.0.tar.gz", "has_sig": false, "md5_digest": "f94a0aabfb9b1ad4e9159b64012bd1fb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4404, "upload_time": "2019-03-21T20:25:52", "url": "https://files.pythonhosted.org/packages/98/d5/27859aeb05adb3d65e8ef95fef205e64e277a497b2bca3695c6e8d6eea6d/django-rest-framework-condition-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "20a38c4b75a9e35cdda2d8acf326f37e", "sha256": "04c90e454a0370d974d5d79eb7aa7e906da32eababe3a65b2f4f77ae47629b7a" }, "downloads": -1, "filename": "django_rest_framework_condition-0.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "20a38c4b75a9e35cdda2d8acf326f37e", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 9044, "upload_time": "2019-04-08T11:53:07", "url": "https://files.pythonhosted.org/packages/b6/cf/f261dbb2f694170118852e673c6a5c2e3b43fefe2e46918760de45e00554/django_rest_framework_condition-0.1.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "8f17ec5844abe9efb48ea07d463350e2", "sha256": "e8fb77602013270fd86597aa213142ac2d9f086ab366da56e113f38d632ee0f9" }, "downloads": -1, "filename": "django-rest-framework-condition-0.1.1.tar.gz", "has_sig": false, "md5_digest": "8f17ec5844abe9efb48ea07d463350e2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4534, "upload_time": "2019-04-08T11:53:09", "url": "https://files.pythonhosted.org/packages/c5/95/4f5602e0ebf129a97bb97e21cda46c4f31acba288a19ff601ce4684638e2/django-rest-framework-condition-0.1.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "20a38c4b75a9e35cdda2d8acf326f37e", "sha256": "04c90e454a0370d974d5d79eb7aa7e906da32eababe3a65b2f4f77ae47629b7a" }, "downloads": -1, "filename": "django_rest_framework_condition-0.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "20a38c4b75a9e35cdda2d8acf326f37e", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 9044, "upload_time": "2019-04-08T11:53:07", "url": "https://files.pythonhosted.org/packages/b6/cf/f261dbb2f694170118852e673c6a5c2e3b43fefe2e46918760de45e00554/django_rest_framework_condition-0.1.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "8f17ec5844abe9efb48ea07d463350e2", "sha256": "e8fb77602013270fd86597aa213142ac2d9f086ab366da56e113f38d632ee0f9" }, "downloads": -1, "filename": "django-rest-framework-condition-0.1.1.tar.gz", "has_sig": false, "md5_digest": "8f17ec5844abe9efb48ea07d463350e2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4534, "upload_time": "2019-04-08T11:53:09", "url": "https://files.pythonhosted.org/packages/c5/95/4f5602e0ebf129a97bb97e21cda46c4f31acba288a19ff601ce4684638e2/django-rest-framework-condition-0.1.1.tar.gz" } ] }