{ "info": { "author": "UNKNOWN", "author_email": "UNKNOWN", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Web Environment", "Framework :: Django", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Programming Language :: Python", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Topic :: Software Development :: Libraries :: Application Frameworks", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "====================================\nEmber Data and Django Rest Framework\n====================================\n\n.. image:: https://travis-ci.org/django-json-api/rest_framework_ember.svg?branch=master\n :target: https://travis-ci.org/django-json-api/rest_framework_ember\n\nThe default Ember Data REST Adapter conventions differ from the default\nDjango Rest Framework JSON request and response format. Instead of adding\na Django specific adapter to Ember Data we use this adapter in Django to\noutput and accept JSON in the format the Ember Data REST Adapter expects.\n\nBy default, Django REST Framework will produce a response like::\n\n {\n \"count\": 20,\n \"next\": \"http://example.com/api/1.0/identities/?page=2\",\n \"previous\": null,\n \"results\": [\n {\n \"id\": 1,\n \"username\": \"john\",\n \"full_name\": \"John Coltrane\"\n },\n {\n ...\n }\n ]\n }\n\n\nHowever, for an ``identity`` model in EmberJS, the Ember Data REST Adapter\nexpects a response to look like the following::\n\n {\n \"identity\": [\n {\n \"id\": 1,\n \"username\": \"john\",\n \"full_name\": \"John Coltrane\"\n },\n {\n ...\n }\n ],\n \"meta\": {\n \"count\": 20,\n \"next\": 2,\n \"next_link\": \"http://example.com/api/1.0/identities/?page=2\",\n \"page\": 1,\n \"previous\": null,\n \"previous_link\": null\n }\n }\n\n\n------------\nRequirements\n------------\n\n1. Django\n2. Django REST Framework\n\n------------\nInstallation\n------------\n\nFrom PyPI\n^^^^^^^^^\n\n::\n\n pip install rest_framework_ember\n\n\nFrom Source\n^^^^^^^^^^^\n\n::\n\n $ git clone https://github.com/ngenworks/rest_framework_ember.git\n $ cd rest_framework_ember && pip install -e .\n\n\nRunning Tests\n^^^^^^^^^^^^^\n\n::\n\n $ python runtests.py\n\n\n-----\nUsage\n-----\n\n\n``rest_framework_ember`` assumes you are using class-based views in Django\nRest Framework.\n\n\nSettings\n^^^^^^^^\n\nOne can either add ``rest_framework_ember.parsers.JSONParser`` and\n``rest_framework_ember.renderers.JSONRenderer`` to each ``ViewSet`` class, or\noverride ``settings.REST_FRAMEWORK``::\n\n\n REST_FRAMEWORK = {\n 'PAGINATE_BY': 10,\n 'PAGINATE_BY_PARAM': 'page_size',\n 'MAX_PAGINATE_BY': 100,\n # DRF v3.1+\n 'DEFAULT_PAGINATION_CLASS':\n 'rest_framework_ember.pagination.PageNumberPagination',\n # older than DRF v3.1\n 'DEFAULT_PAGINATION_SERIALIZER_CLASS':\n 'rest_framework_ember.pagination.PaginationSerializer',\n 'DEFAULT_PARSER_CLASSES': (\n 'rest_framework_ember.parsers.JSONParser',\n 'rest_framework.parsers.FormParser',\n 'rest_framework.parsers.MultiPartParser'\n ),\n 'DEFAULT_RENDERER_CLASSES': (\n 'rest_framework_ember.renderers.JSONRenderer',\n 'rest_framework.renderers.BrowsableAPIRenderer',\n ),\n }\n\nIf ``PAGINATE_BY`` is set the renderer will return a ``meta`` object with\nrecord count and the next and previous links. Django Rest Framework looks\nfor the ``page`` GET parameter by default allowing you to make requests for\nsubsets of the data with ``this.store.find('identity', {page: 2});``.\n\nresource_name property\n^^^^^^^^^^^^^^^^^^^^^^\n\nOn resources that do not subclass ``rest_framework.viewsets.ModelViewSet``,\nthe ``resource_name`` property is required on the class::\n\n class Me(generics.GenericAPIView):\n \"\"\"\n Current user's identity endpoint.\n\n GET /me\n \"\"\"\n resource_name = 'data'\n serializer_class = identity_serializers.IdentitySerializer\n allowed_methods = ['GET']\n permission_classes = (permissions.IsAuthenticated, )\n\n\nEmber Data <-> Rest Framework Format Conversion\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n*(camelization/underscore/pluralize)*\n\nThis package includes the optional ability to automatically convert json requests\nand responses from the Ember Data camelCase to python/rest_framework's preferred\nunderscore. Additionally resource names can be pluralized when an array of objects\nare returned. To hook this up include the following in your project settings::\n\n REST_EMBER_FORMAT_KEYS = True\n REST_EMBER_PLURALIZE_KEYS = True\n\nNote: due to the way the inflector works address_1 will convert to address1\non output but cannot convert address1 back to address_1 on POST or PUT. Keep\nthis in mind when naming fields with numbers in them.\n\n\nExample - Without format conversion::\n\n {\n \"identity\": [\n {\n \"id\": 1,\n \"username\": \"john\",\n \"first_name\": \"John\",\n \"last_name\": \"Coltrane\"\n },\n {\n \"id\": 2,\n \"username\": \"frodo\",\n \"first_name\": \"Bilbo\",\n \"last_name\": \"Baggins\"\n },\n ],\n ...\n }\n\nExample - With format conversion::\n\n {\n \"identities\": [\n {\n \"id\": 1,\n \"username\": \"john\",\n \"firstName\": \"John\",\n \"lastName\": \"Coltrane\"\n },\n {\n \"id\": 2,\n \"username\": \"frodo\",\n \"firstName\": \"Bilbo\",\n \"lastName\": \"Baggins\"\n },\n ],\n ...\n }\n\n\nManaging the trailing slash\n^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nBy default Django expects a trailing slash on urls and will 301 redirect any\nrequests lacking a trailing slash. You can change the server side by\ninstantiating the Django REST Framework's router like so::\n\n router = routers.SimpleRouter(trailing_slash=False)\n\nIf you aren't using SimpleRouter you can instead set APPEND_SLASH = False\nin Django's settings.py file and modify url pattern regex to match routes\nwithout a trailing slash.\n\nIf you prefer to make the change on the client side then add an\napplication adapter to your Ember app and override the buildURL method::\n\n App.ApplicationAdapter = DS.RESTAdapter.extend({\n buildURL: function() {\n var url = this._super.apply(this, arguments);\n if (url.charAt(url.length -1) !== '/') {\n url += '/';\n }\n return url;\n }\n });\n\nDisplaying Server Side Validation Messages\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nEmber Data does not ship with a default implementation of a validation error\nhandler except in the Rails ActiveModelAdapter so to display validation errors\nyou will need to add a small client adapter::\n\n App.ApplicationAdapter = DS.RESTAdapter.extend({\n ajaxError: function(jqXHR) {\n var error = this._super(jqXHR);\n if (jqXHR && jqXHR.status === 400) {\n var response = Ember.$.parseJSON(jqXHR.responseText),\n errors = {},\n keys = Ember.keys(response);\n if (keys.length === 1) {\n var jsonErrors = response[keys[0]];\n Ember.EnumerableUtils.forEach(Ember.keys(jsonErrors), function(key) {\n errors[key] = jsonErrors[key];\n });\n }\n return new DS.InvalidError(errors);\n } else {\n return error;\n }\n }\n });\n\nThe adapter above will handle the following response format when the response has\na 400 status code. The root key (\"post\" in this example) is discarded::\n\n {\n \"post\": {\n \"slug\": [\"Post with this Slug already exists.\"]\n }\n }\n\nTo display all errors add the following to the template::\n\n {{#each message in errors.messages}}\n {{message}}\n {{/each}}\n\nTo display a specific error inline use the following::\n\n {{#each errors.title}}\n