{ "info": { "author": "MEG Support Tools", "author_email": "info@medicaleguides.com", "bugtrack_url": null, "classifiers": [ "Environment :: Web Environment", "Framework :: Django", "Intended Audience :: Developers", "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.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://git.megsupporttools.com/misc/django-remote-forms", "keywords": null, "license": "UNKNOWN", "maintainer": null, "maintainer_email": null, "name": "meg-django-remote-forms", "package_url": "https://pypi.org/project/meg-django-remote-forms/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/meg-django-remote-forms/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://git.megsupporttools.com/misc/django-remote-forms" }, "release_url": "https://pypi.org/project/meg-django-remote-forms/1.2.1/", "requires_dist": null, "requires_python": null, "summary": "A platform independent form serializer for Django.", "version": "1.2.1" }, "last_serial": 2937671, "releases": { "1.2": [], "1.2.1": [ { "comment_text": "", "digests": { "md5": "71ded31018ff0e95be3d5f6ac52cecf9", "sha256": "b3e6da5468bfedeaa49497029bfdf523c7c25c5be08a563c6bc6ff9b445ece08" }, "downloads": -1, "filename": "meg_django_remote_forms-1.2.1-py2-none-any.whl", "has_sig": false, "md5_digest": "71ded31018ff0e95be3d5f6ac52cecf9", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 13420, "upload_time": "2017-06-09T09:04:04", "url": "https://files.pythonhosted.org/packages/e2/3c/fe6afce18bcc7726446ceaa7470a9c65953ae077e3dc4a692d2c16e622bb/meg_django_remote_forms-1.2.1-py2-none-any.whl" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "71ded31018ff0e95be3d5f6ac52cecf9", "sha256": "b3e6da5468bfedeaa49497029bfdf523c7c25c5be08a563c6bc6ff9b445ece08" }, "downloads": -1, "filename": "meg_django_remote_forms-1.2.1-py2-none-any.whl", "has_sig": false, "md5_digest": "71ded31018ff0e95be3d5f6ac52cecf9", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 13420, "upload_time": "2017-06-09T09:04:04", "url": "https://files.pythonhosted.org/packages/e2/3c/fe6afce18bcc7726446ceaa7470a9c65953ae077e3dc4a692d2c16e622bb/meg_django_remote_forms-1.2.1-py2-none-any.whl" } ] }