{
"info": {
"author": "Funkbit AS",
"author_email": "post@funkbit.no",
"bugtrack_url": null,
"classifiers": [],
"description": "# django-dynamicresponse\n\ndjango-dynamicresponse is a lightweight framework for easily providing REST API's for Django applications.\n\nThe framework is intentionally very lightweight and minimalistic, and is designed to interoperate with existing Django code (such as form validation), without major changes.\n\nIn most cases, the only changes needed to add full REST API to an existing Django application is modifying the return statements in your views to return one of the response classes described below instead of a standard Django `HttpResponse`.\n\n## Features\n\n* Easy integration with existing code\n* Reuse same views and logic for both API and normal requests (no need for separate API handlers)\n* Decodes submitted JSON into `request.POST`, fully compatible with Django forms\n* Built-in support for HTTP Basic authentication\n\n## Installation\n\nInstall `django-dynamicresponse`:\n\n\tpip install django-dynamicresponse\n\nAlternatively, download the source code and manually add it to your `PYTHONPATH`.\n\nAdd the two middleware classes to `MIDDLEWARE_CLASSES` in your `settings.py`:\n \n\tMIDDLEWARE_CLASSES = (\n\t 'dynamicresponse.middleware.api.APIMiddleware',\n\t 'dynamicresponse.middleware.dynamicformat.DynamicFormatMiddleware',\n\t)\n\t\n`APIMiddleware` detects incoming API requests based on HTTP headers and provides support for Basic authentication.\n\n`DynamicFormatMiddleware` decodes incoming JSON content into `request.POST`, as well as rendering appropriate responses based on the returned value from your views.\n\n## Settings\n\nThese are the available configurable settings, along with their default values:\n\n
\n \n | Name | \n Default | \n Description | \n
\n \n DYNAMICRESPONSE_JSON_FORM_ERRORS | \n False | \n Outputs form errors in JSON | \n
\n \n DYNAMICRESPONSE_BASIC_REALM_NAME | \n 'API' | \n The name of the Basic Auth realm | \n
\n \n DYNAMICRESPONSE_DJANGO_USER_FIELDS | \n ('id', 'email', 'first_name', 'last_name') | \n Defines which fields to include when serializing a Django auth User object | \n
\n
\n\n## Tests\n\nRun unit tests by running python setup.py test\n\n## Usage\n\nSee the included [sample project](http://github.com/funkbit/django-dynamicresponse/tree/master/examples/) for sample code using the framework to implement a simple blog application.\n\nImport `dynamicresponse` in the views you want to use it:\n\n```\nfrom dynamicresponse.response import *\n```\n\nReturn an instance of the appropriate response class depending on your view logic:\n\n @login_required\n def customer_list(request):\n \"\"\"Lists all customers.\"\"\"\n \n customers = Customer.objects.all()\n return SerializeOrRender('customers/list.html', { 'customers': customers })\n\nThe framework provides two response classes; `SerializeOrRender` and `SerializeOrRedirect`.\n\nAs the names imply, these response classes serialize the supplied context as JSON for API requests, and renders a template or redirects to a URL for normal requests. The first argument of both classes specifies the template to be rendered or the URL to redirect the user to.\n\nTo implement a REST API, you simply use `SerializeOrRender` in situations where you would typically use `render_to_response`, and `SerializeOrRedirect` in cases where you would otherwise return an `HttpResponseRedirect` instance.\n\nFor API requests, the second argument of the constructor is the context to be serialized for API requests. When rendering templates, it is often useful to pass additional context (such as forms and paginators) that is only useful when rendering the template, even though they are not relevant for API requests. The `SerializeOrRender` class supports additional context via a third argument, `extra`:\n\n @login_required\n def customer_list(request):\n \"\"\"Lists all customers.\"\"\"\n \n customers = Customer.objects.all()\n return SerializeOrRender('customers/list.html', { 'customers': customers }, extra={ 'somevalue': 'something' })\n\nIn this case, only `customers` are serialized in API responses, while both `customers` and `somevalue` is accessible when the template is rendered for normal requests.\n\n### Status codes\n\nContent is normally returned as JSON with HTTP status code `200`. If you want to return a different status code, set the `status` argument to one of the following values:\n\n\n \n | Constant | \n HTTP status | \n Description | \n
\n \n CR_OK | \n 200 | \n Default status | \n
\n \n CR_INVALID_DATA | \n 400 | \n One or more forms are invalid | \n
\n \n CR_NOT_FOUND | \n 404 | \n Not found (optional alternative to HttpResponseNotFound for consistency) | \n
\n \n CR_CONFIRM | \n 405 | \n Confirm action with HTTP POST (use with SerializeOrRender with confirmation template) | \n
\n \n CR_DELETED | \n 204 | \n The resource has been deleted | \n
\n
\n\nYou can add custom status values by defining them as a tuple consisting of a string constant and the HTTP status code to return:\n\n\tCR_REQUIRES_UPGRADE = ('REQUIRES_UPGRADE', 402)\n\n### Customizing serialization\n\nBy default, all fields not starting with an underscore (_) on the models will be serialized when returning a JSON response for API requests.\n\nYou can override this behavior by adding a serialize_fields method to your models, returning the fields to include:\n\n\tclass BlogPost(models.Model):\n\n\t title = models.CharField('Title', max_length=255)\n\t text = models.TextField('Text')\n\n\t def serialize_fields(self):\n\t \"\"\"Only these fields will be included in API responses.\"\"\"\n \n\t return [\n\t 'id',\n\t 'title',\n\t 'content',\n\t ]\n\nThis behavior also extends to nested objects. For instance, if the model above had included a foreign key to an author, only the fields defined in the author's serialize_fields method would have been included.\n\nBy default, callables are not included in the serialization. However, you can include names of callables in serialize_fields to explicitly include them in the serialization. This can for instance be useful to provide API users with useful dynamically computed information.",
"description_content_type": null,
"docs_url": null,
"download_url": "UNKNOWN",
"downloads": {
"last_day": -1,
"last_month": -1,
"last_week": -1
},
"home_page": "https://github.com/funkbit/django-dynamicresponse",
"keywords": null,
"license": "BSD",
"maintainer": null,
"maintainer_email": null,
"name": "django-dynamicresponse",
"package_url": "https://pypi.org/project/django-dynamicresponse/",
"platform": "UNKNOWN",
"project_url": "https://pypi.org/project/django-dynamicresponse/",
"project_urls": {
"Download": "UNKNOWN",
"Homepage": "https://github.com/funkbit/django-dynamicresponse"
},
"release_url": "https://pypi.org/project/django-dynamicresponse/0.5.0/",
"requires_dist": null,
"requires_python": null,
"summary": "Lightweight framework for easily providing REST APIs for web apps built with Django.",
"version": "0.5.0"
},
"last_serial": 789523,
"releases": {
"0.1": [
{
"comment_text": "",
"digests": {
"md5": "5fb9ee400f1be13b50cc482759987b78",
"sha256": "6aafa84a74d3ffaf77a3009b383acbf3a9575f685b5d417d965b54d4b5a58fe0"
},
"downloads": -1,
"filename": "django-dynamicresponse-0.1.tar.gz",
"has_sig": false,
"md5_digest": "5fb9ee400f1be13b50cc482759987b78",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 8737,
"upload_time": "2010-12-09T22:32:45",
"url": "https://files.pythonhosted.org/packages/fc/2c/b7ac7eeb41808b1b367d351a3157574118f322a75188d0c86176a0f54f59/django-dynamicresponse-0.1.tar.gz"
}
],
"0.1.1": [
{
"comment_text": "",
"digests": {
"md5": "e716c978b0714183ad87a29f6b7e36fc",
"sha256": "4b16c08b1bb68ba0b3068ac6f5609b233b449976d79626139516d1628d27b178"
},
"downloads": -1,
"filename": "django-dynamicresponse-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "e716c978b0714183ad87a29f6b7e36fc",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 8760,
"upload_time": "2010-12-09T22:58:05",
"url": "https://files.pythonhosted.org/packages/ef/8b/6b118dc5a15489c9303c2981a15f144a7eacd4753f47fe252ecc8d50a4b3/django-dynamicresponse-0.1.1.tar.gz"
}
],
"0.1.2": [
{
"comment_text": "",
"digests": {
"md5": "d2356282f4099e7fc60c5d466026379a",
"sha256": "06d7a152ae684528eacc18847670ae1e256b1791c4e7a83d005b8a3723ded4b8"
},
"downloads": -1,
"filename": "django-dynamicresponse-0.1.2.tar.gz",
"has_sig": false,
"md5_digest": "d2356282f4099e7fc60c5d466026379a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 8804,
"upload_time": "2011-02-19T15:48:18",
"url": "https://files.pythonhosted.org/packages/b7/4a/f50cf1275d6123518b6a1e08b1c4c3c28514e328d0d1f1b4b57776c8d098/django-dynamicresponse-0.1.2.tar.gz"
}
],
"0.1.3": [
{
"comment_text": "",
"digests": {
"md5": "f4696573f6b44361a60e12d9ff84e2da",
"sha256": "092e4cd2abc39c2a37b69d3bfd7fec5de87e381002b0ba7a10ba62ef81cee8aa"
},
"downloads": -1,
"filename": "django-dynamicresponse-0.1.3.tar.gz",
"has_sig": false,
"md5_digest": "f4696573f6b44361a60e12d9ff84e2da",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 8999,
"upload_time": "2011-02-23T15:11:32",
"url": "https://files.pythonhosted.org/packages/ee/68/f9b31388d547f1de6675c0b75b1a05bba89f0f6742090486a60835a8859a/django-dynamicresponse-0.1.3.tar.gz"
}
],
"0.1.4": [
{
"comment_text": "",
"digests": {
"md5": "f2f19110c4fa003a3e2e754bb106081d",
"sha256": "2a96b8ebac661032bf964c81d288b01aaf17f23b2db709656c7af4d6ae5d5064"
},
"downloads": -1,
"filename": "django-dynamicresponse-0.1.4.tar.gz",
"has_sig": false,
"md5_digest": "f2f19110c4fa003a3e2e754bb106081d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 8988,
"upload_time": "2011-03-02T17:25:39",
"url": "https://files.pythonhosted.org/packages/65/f1/75b88ecd0f67b11ea9d2c60fbb9c1b97a1c4e1c80dd310ec0ae3a2526157/django-dynamicresponse-0.1.4.tar.gz"
}
],
"0.1.5": [
{
"comment_text": "",
"digests": {
"md5": "808dbf44c7a797f8e554c52e847fbb2e",
"sha256": "74463c627cb16e870b926ac5e07616cec6dfdfc33d56065641b1ab8ca8087515"
},
"downloads": -1,
"filename": "django-dynamicresponse-0.1.5.tar.gz",
"has_sig": false,
"md5_digest": "808dbf44c7a797f8e554c52e847fbb2e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 9039,
"upload_time": "2011-03-18T14:20:12",
"url": "https://files.pythonhosted.org/packages/99/0d/15b4d450ea857039ba04794d213ab9e6ab41e477d266d152cf5e4de1cdad/django-dynamicresponse-0.1.5.tar.gz"
}
],
"0.1.6": [
{
"comment_text": "",
"digests": {
"md5": "4c37ff42d3d052fc5352a3741420e20c",
"sha256": "659b959fde640057236c2611b1d76f8309b89d80f369dd3a3ef9f14eb1dcce94"
},
"downloads": -1,
"filename": "django-dynamicresponse-0.1.6.tar.gz",
"has_sig": false,
"md5_digest": "4c37ff42d3d052fc5352a3741420e20c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 11218,
"upload_time": "2012-02-09T13:33:27",
"url": "https://files.pythonhosted.org/packages/ef/87/387de6b9130d3629624caf18476b7704b85a14db6be9279fb3b41486db91/django-dynamicresponse-0.1.6.tar.gz"
}
],
"0.2.0": [
{
"comment_text": "",
"digests": {
"md5": "1a29ca1fa5fafa1f1e8752bc8e09544c",
"sha256": "ae9d08e341a764b40c7bbecbe5935ae47fea99a56be3d2786bb2bfc1746374ea"
},
"downloads": -1,
"filename": "django-dynamicresponse-0.2.0.tar.gz",
"has_sig": false,
"md5_digest": "1a29ca1fa5fafa1f1e8752bc8e09544c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 11250,
"upload_time": "2012-02-16T12:00:51",
"url": "https://files.pythonhosted.org/packages/22/06/1e0b4e16b88e0defe74f268b43bb64884b4c4a90f6731fada0b5abd14fde/django-dynamicresponse-0.2.0.tar.gz"
}
],
"0.3.0": [
{
"comment_text": "",
"digests": {
"md5": "ab4025e10fa9944287bc2cc1e2e4f546",
"sha256": "fd5fe4630b843501fb675383266ffe2465c10f6fde455a5cbe51f15bf225f591"
},
"downloads": -1,
"filename": "django-dynamicresponse-0.3.0.tar.gz",
"has_sig": false,
"md5_digest": "ab4025e10fa9944287bc2cc1e2e4f546",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 11747,
"upload_time": "2012-04-19T14:31:09",
"url": "https://files.pythonhosted.org/packages/17/74/5c39e2186f5098ecb5ae50218a8cdfb415d9171088fd1e41f81a18a444bf/django-dynamicresponse-0.3.0.tar.gz"
}
],
"0.4.0": [
{
"comment_text": "",
"digests": {
"md5": "1a0f5fd4e895599fdc4fcfe143b8ae3c",
"sha256": "aa0998516687448b5df4e55753245656554ed7c1eea08840d620691405ed837f"
},
"downloads": -1,
"filename": "django-dynamicresponse-0.4.0.tar.gz",
"has_sig": false,
"md5_digest": "1a0f5fd4e895599fdc4fcfe143b8ae3c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 11831,
"upload_time": "2012-05-15T17:04:53",
"url": "https://files.pythonhosted.org/packages/4f/28/cd3a15de3ce080359c0d050d02db5d7091cdec60561b89d3a911c79141f4/django-dynamicresponse-0.4.0.tar.gz"
}
],
"0.4.1": [
{
"comment_text": "",
"digests": {
"md5": "0c0fc2465dfc9d40c5ffdaec9b667aef",
"sha256": "faa5165b399d220158025cf8a23d46f9e2b65b0bddf40666da0c0e2d68117a0e"
},
"downloads": -1,
"filename": "django-dynamicresponse-0.4.1.tar.gz",
"has_sig": false,
"md5_digest": "0c0fc2465dfc9d40c5ffdaec9b667aef",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 12210,
"upload_time": "2012-08-28T16:09:45",
"url": "https://files.pythonhosted.org/packages/c7/c7/eaad28b1f218f34d76368bb8dce7e0c0a2f648fc901cd76d2beae41b3bfc/django-dynamicresponse-0.4.1.tar.gz"
}
],
"0.5.0": [
{
"comment_text": "",
"digests": {
"md5": "b9f670cc2f3434a00e39b6e979ca58de",
"sha256": "a487c951ca81e3f518adf9bf2b2ee075a1ad7116ba92c8f99a42e2587ccbe182"
},
"downloads": -1,
"filename": "django-dynamicresponse-0.5.0.tar.gz",
"has_sig": false,
"md5_digest": "b9f670cc2f3434a00e39b6e979ca58de",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 12158,
"upload_time": "2013-02-15T14:50:00",
"url": "https://files.pythonhosted.org/packages/23/97/a8e467bc3c532c7b6f3d3c2a7b4aa802b074c72d61061570bcd635e91372/django-dynamicresponse-0.5.0.tar.gz"
}
]
},
"urls": [
{
"comment_text": "",
"digests": {
"md5": "b9f670cc2f3434a00e39b6e979ca58de",
"sha256": "a487c951ca81e3f518adf9bf2b2ee075a1ad7116ba92c8f99a42e2587ccbe182"
},
"downloads": -1,
"filename": "django-dynamicresponse-0.5.0.tar.gz",
"has_sig": false,
"md5_digest": "b9f670cc2f3434a00e39b6e979ca58de",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 12158,
"upload_time": "2013-02-15T14:50:00",
"url": "https://files.pythonhosted.org/packages/23/97/a8e467bc3c532c7b6f3d3c2a7b4aa802b074c72d61061570bcd635e91372/django-dynamicresponse-0.5.0.tar.gz"
}
]
}