{ "info": { "author": "SF Software limited t/a Pebble", "author_email": "sysadmin@talktopebble.co.uk", "bugtrack_url": null, "classifiers": [], "description": "Django Mapped Fields\n====================\n\nA set of form fields to make it easier to accept semi-structured data with variable (but expected) keys. This data can now be mapped directly to your own Django Models and Forms with normalised field names.\n\nA common use case would be to take CSV or JSON files from external systems and\nnormalise them into your own data structures.\n\n\nUsage\n-----\n\nTo use a map field, simply import it and set its `field_names` when creating the\nfield.\n\n```python\nfrom django import forms\n\nfrom mapped_fields import fields\n\n\nclass ContactCsv(forms.Form):\n \"\"\"Import a Contact from a CSV File.\n \"\"\"\n first_name = fields.Charfield(\n max_length=50, field_names=('FirstName', 'Forename'))\n last_name = fields.Charfield(\n max_length=50, field_names=('LastName', 'Surname'))\n phone_number = fields.CharField(\n max_length=30, field_names=('Telephone', 'Mobile'))\n\n\ndef map_from_csv():\n csv_files = [\n {\n 'FirstName': 'Anne',\n 'LastName': 'Other',\n 'Mobile': '555-1234',\n },\n 'Forename': 'David',\n 'Legal Surname': 'Anderson',\n 'Telephone': '555-2345',\n },\n ]\n\n valid_form = ContactCsv(data=csv_files[0])\n valid_form.is_valid() == True\n valid_form.cleaned_data['first_name'] == 'Anne'\n valid_form.cleaned_data['last_name'] == 'Other'\n valid_form.cleaned_data['phone_number'] == '555-1234'\n\n invalid_form = ContactCsv(data=csv_files[1])\n invalid_form.is_valid() == False # Legal Surname is not in the mapped fields\n```\n\nHandling Multiple field_names in a single file\n----------------------------------------------\n\nIf you have multiple different fields in the same file mapping to a single\noutput, the first match on field_names will be used:\n\n```python\nfrom mapped_fields import fields\n\n\nclass ContactForm(forms.Form):\n \"\"\"Demonstrate multiple field_names.\n \"\"\"\n name = fields.CharField(\n max_length=100, field_names=('Name', 'ContactName'))\n\n\ndef map_from_dict():\n data = {\n 'ContactName': 'James',\n 'Name': 'Anderson',\n }\n\n form = ContactForm(data=data)\n form.is_valid() == True\n form.cleaned_data['name'] == 'Name' # Name was listed first in field_names\n```\n\nThis is potentially useful if you are importing file formats that are\ninconsistent, and where you want a fallback if the \"best\" header isn't\nthere.\n\n\nFields\n------\n\nThe Mapped Fields plugin works by extending existing django fields. The\ncurrently supported fields are:\n\n- `mapped_fields.fields.BooleanField`\n- `mapped_fields.fields.NullBooleanField`\n- `mapped_fields.fields.CharField`\n- `mapped_fields.fields.DateField`\n- `mapped_fields.fields.DateTimeField`\n- `mapped_fields.fields.DecimalField`\n- `mapped_fields.fields.FloatField`\n- `mapped_fields.fields.IntegerField`\n- `mapped_fields.fields.EmailField`\n- `mapped_fields.fields.SlugField`\n- `mapped_fields.fields.URLField`\n\n\nAll fields work as in Django, but take a mandatory extra argument `field_names` -- a list or tuple\nof field names to map from the source data into the field.\n\n\nTesting\n-------\n\nTo test, install the requirements inside your virtualenv then run test\ninside test_project:\n\n```\nvirtualenv venv\n. venv/bin/activate\npip install -r requirements.txt\npython setup.py install\n\ncd test_project\n./manage.py test\n```\n", "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/mypebble/mapped-fields", "keywords": null, "license": "UNKNOWN", "maintainer": null, "maintainer_email": null, "name": "django-mapped-fields", "package_url": "https://pypi.org/project/django-mapped-fields/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/django-mapped-fields/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/mypebble/mapped-fields" }, "release_url": "https://pypi.org/project/django-mapped-fields/0.0.4/", "requires_dist": null, "requires_python": null, "summary": "Form fields to make it easier to map CSV or JSON files to your own models", "version": "0.0.4" }, "last_serial": 1236281, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "d9f2ddc3b65cb8224c7825ace501d324", "sha256": "ff90e49d573a3cd7c268faad027df06e545459324d2b95d956de32cdf539c24c" }, "downloads": -1, "filename": "django-mapped-fields-0.0.1.tar.gz", "has_sig": false, "md5_digest": "d9f2ddc3b65cb8224c7825ace501d324", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3927, "upload_time": "2014-03-24T09:41:59", "url": "https://files.pythonhosted.org/packages/d2/d2/84afbaec7fba18c6abb5202d15a650d3bab8a50f9210675a1b48d884e66e/django-mapped-fields-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "d37e0d793bc95813c0976ea9a5ca1406", "sha256": "59fa64a21bf3877650580fd28d58c330c217e444da80d49f5228785ee9b3d6d8" }, "downloads": -1, "filename": "django-mapped-fields-0.0.2.tar.gz", "has_sig": false, "md5_digest": "d37e0d793bc95813c0976ea9a5ca1406", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3992, "upload_time": "2014-03-24T13:45:31", "url": "https://files.pythonhosted.org/packages/9c/7e/d55c70e961fd1b2934f0a4afce3b438547d566b1d4016f5cce859e7d9ae8/django-mapped-fields-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "5fd504205a1ba7880b95bebad5c14e12", "sha256": "ce1670742bed95a0824184fe2a08d6ca45b05de9eb01744fa7c2fe171705cdb2" }, "downloads": -1, "filename": "django-mapped-fields-0.0.3.tar.gz", "has_sig": false, "md5_digest": "5fd504205a1ba7880b95bebad5c14e12", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4004, "upload_time": "2014-03-27T14:33:23", "url": "https://files.pythonhosted.org/packages/b1/fc/650992ea5ddedbab9a2e11e5a2fe496c0d1ba66d7a256310a299347c7c5b/django-mapped-fields-0.0.3.tar.gz" } ], "0.0.4": [ { "comment_text": "", "digests": { "md5": "98d6d62f2ba2b57d4357abc4d3ced488", "sha256": "c9d1ab222f84a2c52982d984ca0bdb218e21c2f44c40416f4fd38c83c14084b5" }, "downloads": -1, "filename": "django-mapped-fields-0.0.4.tar.gz", "has_sig": false, "md5_digest": "98d6d62f2ba2b57d4357abc4d3ced488", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4039, "upload_time": "2014-09-24T12:23:01", "url": "https://files.pythonhosted.org/packages/f9/69/c8e739cd251e459a5db12fbca406407e9758e49d5ad55e84fdfe42b40ba3/django-mapped-fields-0.0.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "98d6d62f2ba2b57d4357abc4d3ced488", "sha256": "c9d1ab222f84a2c52982d984ca0bdb218e21c2f44c40416f4fd38c83c14084b5" }, "downloads": -1, "filename": "django-mapped-fields-0.0.4.tar.gz", "has_sig": false, "md5_digest": "98d6d62f2ba2b57d4357abc4d3ced488", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4039, "upload_time": "2014-09-24T12:23:01", "url": "https://files.pythonhosted.org/packages/f9/69/c8e739cd251e459a5db12fbca406407e9758e49d5ad55e84fdfe42b40ba3/django-mapped-fields-0.0.4.tar.gz" } ] }