{ "info": { "author": "WiserTogether Tech Team", "author_email": "tech@wisertogether.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 1 - Planning", "Environment :: Web Environment", "Framework :: Django", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Topic :: Utilities" ], "description": "# django-remote-forms\n\nA package that allows you to serialize django forms, including fields and widgets into Python\ndictionary for easy conversion into JSON and expose over API\n\nPlease go through my [djangocon US 2012 talk](http://www.slideshare.net/tarequeh/django-forms-in-a-web-api-world)\nto understand the problem sphere, motivations, challenges and implementation of Remote Forms\n\n## Sample Implementation\n\nIf you don't mind digging around a little bit to learn about different the components that might be\nnecessary for an implementation of django-remote-forms, check out\ndjango Remote Admin [django-remote-admin](https://github.com/tarequeh/django-remote-admin)\n\n## Usage\n\n### Minimal Example\n\n```python\nfrom django_remote_forms.forms import RemoteForm\n\nform = LoginForm()\nremote_form = RemoteForm(form)\nremote_form_dict = remote_form.as_dict()\n```\n\nUpon converting the dictionary into JSON, it looks like this:\n\n```json\n{\n \"is_bound\": false,\n \"non_field_errors\": [],\n \"errors\": {},\n \"title\": \"LoginForm\",\n \"fields\": {\n \"username\": {\n \"title\": \"CharField\",\n \"required\": true,\n \"label\": \"Username\",\n \"initial\": null,\n \"help_text\": \"This is your django username\",\n \"error_messages\": {\n \"required\": \"This field is required.\",\n \"invalid\": \"Enter a valid value.\"\n },\n \"widget\": {\n \"title\": \"TextInput\",\n \"is_hidden\": false,\n \"needs_multipart_form\": false,\n \"is_localized\": false,\n \"is_required\": true,\n \"attrs\": {\n \"maxlength\": \"30\"\n },\n \"input_type\": \"text\"\n },\n \"min_length\": 6,\n \"max_length\": 30\n },\n \"password\": {\n \"title\": \"CharField\",\n \"required\": true,\n \"label\": \"Password\",\n \"initial\": null,\n \"help_text\": \"\",\n \"error_messages\": {\n \"required\": \"This field is required.\",\n \"invalid\": \"Enter a valid value.\"\n },\n \"widget\": {\n \"title\": \"PasswordInput\",\n \"is_hidden\": false,\n \"needs_multipart_form\": false,\n \"is_localized\": false,\n \"is_required\": true,\n \"attrs\": {\n \"maxlength\": \"128\"\n },\n \"input_type\": \"password\"\n },\n \"min_length\": 6,\n \"max_length\": 128\n }\n },\n \"label_suffix\": \":\",\n \"prefix\": null,\n \"csrfmiddlewaretoken\": \"2M3MDgfzBmkmBrJ9U0MuYUdy8vgeCCgw\",\n \"data\": {\n \"username\": null,\n \"password\": null\n }\n}\n```\n\n### An API endpoint serving remote forms\n\n```python\nfrom django.core.serializers.json import simplejson as json, DjangoJSONEncoder\nfrom django.http import HttpResponse\nfrom django.middleware.csrf import CsrfViewMiddleware\nfrom django.views.decorators.csrf import csrf_exempt\n\nfrom django_remote_forms.forms import RemoteForm\n\nfrom my_awesome_project.forms import MyAwesomeForm\n\n\n@csrf_exempt\ndef my_ajax_view(request):\n csrf_middleware = CsrfViewMiddleware()\n\n response_data = {}\n if request.method == 'GET':\n # Get form definition\n form = MyAwesomeForm()\n elif request.raw_post_data:\n request.POST = json.loads(request.raw_post_data)\n # Process request for CSRF\n csrf_middleware.process_view(request, None, None, None)\n form_data = request.POST.get('data', {})\n form = MyAwesomeForm(form_data)\n if form.is_valid():\n form.save()\n\n remote_form = RemoteForm(form)\n # Errors in response_data['non_field_errors'] and response_data['errors']\n response_data.update(remote_form.as_dict())\n\n response = HttpResponse(\n json.dumps(response_data, cls=DjangoJSONEncoder),\n mimetype=\"application/json\"\n )\n\n # Process response for CSRF\n csrf_middleware.process_response(request, response)\n return response\n```\n\n## djangocon Proposal\n\nThis is a bit lengthy. But if you want to know more about my motivations behind developing django-remote-forms\nthen read on.\n\n\n>In our quest to modularize the architecture of web applications, we create self-containing backend\n>systems that provide web APIs for programmatic interactions. This gives us the flexibility to\n>separate different system components. A system with multiple backend components e.g. user profile\n>engine, content engine, community engine, analytics engine may have a single frontend application\n>that fetches data from all of these components using respective web APIs.\n\n>With the increased availability of powerful JavaScript frameworks, such frontend applications are\n>often purely JS based to decrease application footprint, increase deployment flexibility and\n>separate presentation from data. The separation is very rewarding from a software engineering\n>standpoint but imposes several limitations on system design. Using django to construct the API for\n>arbitrary consumers comes with the limitation of not being able to utilize the powerful django form\n>subsystem to drive forms on these consumers. But is there a way to overcome this restriction?\n\n>This is not a trivial problem to solve and there are only a few assumptions we can make about the\n>web API consumer. It can be a native mobile or desktop - application or browser. We advocate that\n>web APIs should provide sufficient information about 'forms' so that they can be faithfully\n>reproduced at the consumer end.\n\n>Even in a API backend built using django, forms are essential for accepting, filtering, processing\n>and saving data. The django form subsystem provides many useful features to accomplish these tasks.\n>At the same time it facilitates the process of rendering the form elements in a browser\n>environment. The concepts of form fields combined with widgets can go a long way in streamlining\n>the interface to interact with data.\n\n>We propose an architecture to serialize information about django forms (to JSON) in a framework\n>independent fashion so that it can be consumed by any frontend application that renders HTML. Such\n>information includes but is not limited to basic form configurations, security tokens (if\n>necessary), rendering metadata and error handling instructions. We lovingly name this architecture\n>django-remote-forms.\n\n>At WiserTogether, we are in the process of building a component based architecture that strictly\n>provides data endpoints for frontend applications to consume. We are working towards developing\n>our frontend application for web browsers using backbone.js as MVC and handlebars as the templating\n>engine. django-remote-forms helps us streamline our data input interface with the django forms\n>living at the API backend.\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/wisertoghether/django-remote-forms/", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "django-remote-forms", "package_url": "https://pypi.org/project/django-remote-forms/", "platform": "", "project_url": "https://pypi.org/project/django-remote-forms/", "project_urls": { "Homepage": "http://github.com/wisertoghether/django-remote-forms/" }, "release_url": "https://pypi.org/project/django-remote-forms/0.0.1/", "requires_dist": null, "requires_python": "", "summary": "A platform independent form serializer for Django.", "version": "0.0.1" }, "last_serial": 3857797, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "3a4deda678ecb883c86f4324c0cc10a0", "sha256": "920638eb5019ac91dcfa65f3302ca44676dae60c60b32644848116d6ce098550" }, "downloads": -1, "filename": "django-remote-forms-0.0.1.tar.gz", "has_sig": false, "md5_digest": "3a4deda678ecb883c86f4324c0cc10a0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8583, "upload_time": "2018-05-13T02:50:13", "url": "https://files.pythonhosted.org/packages/e8/d4/b24e30a5ccf6a2febe549d125c8602c6e9683de71d1549774394de30a91f/django-remote-forms-0.0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "3a4deda678ecb883c86f4324c0cc10a0", "sha256": "920638eb5019ac91dcfa65f3302ca44676dae60c60b32644848116d6ce098550" }, "downloads": -1, "filename": "django-remote-forms-0.0.1.tar.gz", "has_sig": false, "md5_digest": "3a4deda678ecb883c86f4324c0cc10a0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8583, "upload_time": "2018-05-13T02:50:13", "url": "https://files.pythonhosted.org/packages/e8/d4/b24e30a5ccf6a2febe549d125c8602c6e9683de71d1549774394de30a91f/django-remote-forms-0.0.1.tar.gz" } ] }