{
"info": {
"author": "Lamar Meigs",
"author_email": "lamarmeigs@gmail.com",
"bugtrack_url": null,
"classifiers": [
"Development Status :: 4 - Beta",
"Environment :: Web Environment",
"Framework :: Django",
"Framework :: Django :: 1.10",
"Framework :: Django :: 1.7",
"Framework :: Django :: 1.8",
"Framework :: Django :: 1.9",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.5",
"Topic :: Internet :: WWW/HTTP",
"Topic :: Internet :: WWW/HTTP :: Dynamic Content",
"Topic :: Software Development :: Libraries :: Python Modules"
],
"description": "django-clean-fields\n===================\n\nThis Django utility allows the definition of methods or functions to\nclean model object field values on save.\n\nInstallation\n------------\n\nSince django-clean-fields is not a Django app, simply include it on your\n``PYTHONPATH``. The easiest way to do this is installing via ``pip``:\n\n.. code:: bash\n\n pip install django-clean-fields\n\nNo changes to the project's settings are necessary.\n\nUsage\n-----\n\nTwo alternate implementation options are available: an extended model\nclass that closely resembles conventions used by the `Django forms\nAPI `__,\nand a decorator that registers a callable with the `pre\\_save\nsignal `__.\nWhich approach to use is a decision left to the developer. The former\noption may provide the most familiarity with existing conventions; the\nlatter offers more flexibility.\n\nCleanFieldsModel\n~~~~~~~~~~~~~~~~\n\nAny model inheriting from the abstract\n``clean_fields.models.CleanFieldsModel`` will check for and run cleaner\nmethods as its first action when saving. Such methods should match the\nconventions used by `form field\nvalidators `__,\nnamely:\n\n- methods must be named ``clean_``\n- methods must accept no parameters\n- methods must return the \"cleaned\" value, ready to be written to the\n database\n- method may raise an exception to interrupt saving\n\nExample:\n\n.. code:: python\n\n from django.core.exceptions import ValidationError\n from django.db import models\n from clean_fields.models import CleanFieldsModel\n\n class Article(CleanFieldsModel):\n title = models.CharField(max_length=30)\n\n def clean_title(self):\n if \"you'll never believe\" in self.title.lower():\n raise ValidationError('Sensationalist Clickbait Not Allowed')\n return self.title.title()\n\nDecorators\n~~~~~~~~~~\n\nThe ``clean_fields.decorators.cleans_field`` decorator can be applied to\nany callable, which will then be invoked when the `pre\\_save\nsignal `__\nis sent by the corresponding model. The decorator requires a single\nargument: a reference string identifying the field to clean, which must\nfollow the pattern \"app\\_name.ModelName.field\\_name\". Note that the full\nreference must be provided even if the callable is within the model\nclass itself.\n\nAny decorated callable must accept the current field value and return\nthe \"cleaned\" value. The code below has the identical effect as the\nabove example.\n\nExample:\n\n.. code:: python\n\n from django.core.exceptions import ValidationError\n from django.db import models\n from clean_fields.decorators import cleans_field\n\n class Article(models.Model):\n title = models.CharField(max_length=30)\n\n @cleans_field('your_app.Article.title')\n def ensure_title_case(self, unsaved_title):\n return unsaved_title.title()\n\n\n # Multiple cleaners can be defined for a single field.\n # Also, they needn't be instance methods on the model object.\n @cleans_field('your_app.Article.title')\n def validate_dignified_title(unsaved_title):\n if \"you'll never believe\" in unsaved_title.lower():\n raise ValidationError('Sensationalist Clickbait Not Allowed')\n return unsaved_title\n\nIf references to other fields on the model instance are necessary, the\n``clean_fields.decorators.cleans_field_with_context`` decorator should\nbe used instead. This decorator works the same as ``cleans_field``, but\npasses an additional parameter to the cleaner: a dictionary containing\nthe current field names and values.\n\nExample:\n\n.. code:: python\n\n from django.db import models\n from clean_fields.decorators import cleans_field_with_context\n\n class Article(models.Model):\n title = models.CharField(max_length=30)\n is_published = models.BooleanField()\n\n @cleans_field_with_context('your_app.Article.title')\n def ensure_title_case_when_unpublished(self, unsaved_title, data):\n if data['is_published']:\n return unsaved_title\n else:\n return unsaved_title.title()\n\nDiscussion\n----------\n\nThere is solid reasoning behind the omission of similar behavior in\nDjango's core. For one, it might create a feeling of false security.\nValidation runs on save, but that does not prevent \"uncleaned\" data from\nbeing committed to the database (for instance, via the ORM's\n```bulk_create`` `__\nor\n```update`` `__\nmethods, which circumvent ``save()``). Furthermore, a lack of\nmodel-level validation encourages a separation between a user's\ninteraction with model objects and a developer's interaction with model\nobjects. This rigorous definition of user roles is usually a Good Thing,\nbut it can impose an unnecessary burden on projects that don't require\nuser-driven interfaces. Be sure that this workflow benefits your project\nbefore installing it.\n\nIf in doubt, it's worth noting some built-in alternative means to\naccomplish similar cleaning behavior. For instance:\n\n1. The forms API\n\n `Django form-field\n validation `__\n allows cleaning both specific values or the entirety of a submitted\n form. Used with a\n `ModelForm `__,\n this is the best way to scrub data delivered via the user interface.\n\n However, forms and their validation are intended to be used within\n the context of a web page. They lose much of their simplicity when\n handled entirely on the backend.\n\n2. Model field constraints and validators\n\n Model fields provide two ways to avoid committing erroneous values to\n the database. The first are `field\n options `__;\n passed as keyword arguments to your fields declarations, these will\n enforce value contraints on the database level (eg. CharField's\n max\\_length). The second is the ability to define\n `validators `__.\n These functions, more flexible in Python than at the database level,\n will raise errors if the values to be saved to not adhere to some\n defined pattern or convention.\n\n While both these options keep the validation at the model level,\n their benefit is merely error prevention. Neither allow the ability\n to \"massage\" data into an acceptable format.\n\n3. Model Validation\n\n Django does provide some support custom `model object\n validation `__\n via the ```Model.clean()``\n method `__.\n This allows modifying attributes, allows access to multiple fields,\n and will be called via the ```Model.full_clean()``\n method `__.\n\n This sort of custom validation sounds ideal, except that it is not\n called when a model object is saved. ``full_clean()`` or ``clean()``\n must be invoked manually by any object other than a ``ModelForm``.\n Moreover, from a design perspective, it's preferable to have methods\n with as narrow a focus as possible: a single method to clean a single\n aspect of a single field is better than ``clean()``, which must\n handle all validation on all fields.\n\n4. Signal handling\n\n The ``cleans_field`` decorator already leverages `built-in Django\n signals `__\n (specifically, the `pre\\_save\n signal `__).\n It is possible to handle field scrubbing directly by defining your\n own signal handlers and connecting them to the appropriate signal.\n\n The greatest shortcoming of this approach is that it encourages bad\n OO design: signal handlers of this nature would easily be defined\n apart from the models which they are meant to modify. Even\n implemented as staticmethods on the appropriate models, their method\n signature is obtuse, and therefore difficult to use outside of the\n context of signals.\n\nThis project intends to pick up the slack where the above built-in\nmethods fall short, providing a simple interface to support streamlined\nmodel design. It's not uncircumventable, so *caveat emptor*, but aims to\nmake your life easier.",
"description_content_type": null,
"docs_url": null,
"download_url": "",
"downloads": {
"last_day": -1,
"last_month": -1,
"last_week": -1
},
"home_page": "https://github.com/lamarmeigs/django-clean-fields",
"keywords": "django,model,field,validation",
"license": "MIT",
"maintainer": "",
"maintainer_email": "",
"name": "django-clean-fields",
"package_url": "https://pypi.org/project/django-clean-fields/",
"platform": "",
"project_url": "https://pypi.org/project/django-clean-fields/",
"project_urls": {
"Homepage": "https://github.com/lamarmeigs/django-clean-fields"
},
"release_url": "https://pypi.org/project/django-clean-fields/0.3.0/",
"requires_dist": null,
"requires_python": "",
"summary": "A Django utility to clean model field values on save.",
"version": "0.3.0"
},
"last_serial": 2291019,
"releases": {
"0.1.0": [
{
"comment_text": "",
"digests": {
"md5": "786a3727793690cbd54e708c0724a4e0",
"sha256": "5102f6302bba7891c1c080fd55bd781f1fb6d999e81b616bfbccb4a797f899c6"
},
"downloads": -1,
"filename": "django-clean-fields-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "786a3727793690cbd54e708c0724a4e0",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 7897,
"upload_time": "2016-07-31T22:20:59",
"url": "https://files.pythonhosted.org/packages/66/49/b0419d7c5ad8a1fda7e841b05038e39a7348aba7532dcf53f654accd5795/django-clean-fields-0.1.0.tar.gz"
}
],
"0.2.0": [
{
"comment_text": "",
"digests": {
"md5": "2fa502e26611e62970d0abd8bf32785a",
"sha256": "bf9b2c127dd5c8df0c4056a6f55fd1616948483d65a454fadcc0259cc5e4288a"
},
"downloads": -1,
"filename": "django-clean-fields-0.2.0.tar.gz",
"has_sig": false,
"md5_digest": "2fa502e26611e62970d0abd8bf32785a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 8096,
"upload_time": "2016-08-06T18:10:56",
"url": "https://files.pythonhosted.org/packages/da/4f/b556692899584302b862f2d3098d6ef8ff211381dc5073cbc0bcfde8e01d/django-clean-fields-0.2.0.tar.gz"
}
],
"0.3.0": [
{
"comment_text": "",
"digests": {
"md5": "8049faae72a36e6d910b31d2230b2f4f",
"sha256": "64a1e0a2392b44c5764ea87346cb837098ab06c427739f57ae493890db508931"
},
"downloads": -1,
"filename": "django-clean-fields-0.3.0.tar.gz",
"has_sig": false,
"md5_digest": "8049faae72a36e6d910b31d2230b2f4f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 9056,
"upload_time": "2016-08-19T15:14:42",
"url": "https://files.pythonhosted.org/packages/ea/e9/c89b41b9342e47b480ba454b31f5b5a79f5c5e2ef5d99982d8f884d0ff5c/django-clean-fields-0.3.0.tar.gz"
}
]
},
"urls": [
{
"comment_text": "",
"digests": {
"md5": "8049faae72a36e6d910b31d2230b2f4f",
"sha256": "64a1e0a2392b44c5764ea87346cb837098ab06c427739f57ae493890db508931"
},
"downloads": -1,
"filename": "django-clean-fields-0.3.0.tar.gz",
"has_sig": false,
"md5_digest": "8049faae72a36e6d910b31d2230b2f4f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 9056,
"upload_time": "2016-08-19T15:14:42",
"url": "https://files.pythonhosted.org/packages/ea/e9/c89b41b9342e47b480ba454b31f5b5a79f5c5e2ef5d99982d8f884d0ff5c/django-clean-fields-0.3.0.tar.gz"
}
]
}