edc-form-validators


Nameedc-form-validators JSON
Version 0.3.40 PyPI version JSON
download
home_pagehttps://github.com/clinicedc/edc-form-validators
SummaryForm validator classes for common patterns in django ModelForms.
upload_time2024-01-24 05:53:59
maintainer
docs_urlNone
authorErik van Widenfelt
requires_python>=3.11
licenseGPL license, see LICENSE
keywords django modelform form validation edc clinicedc clinical trials
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            |pypi| |actions| |codecov| |downloads|

edc-form-validators
-------------------

Form validator classes for ModelForms


ModelForm ``FormValidator``
---------------------------

``FormValidator`` simplifies common patterns used in ``ModelForm.clean``. For example, if there is a response to field A then there should not a be response to field B and visa-versa.

Declare a form with it's ``form_validator`` class and use ``FormValidatorMixin``:

.. code-block:: python

    class MyFormValidator(FormValidator):

        def clean(self):
            self.required_if(
                YES,
                field='f1',
                field_required='f2')
            ...

    class MyModelForm(FormValidatorMixin, forms.ModelForm):

        form_validator_cls = MyFormValidator

        class Meta:
            model = TestModel
            fields = '__all__'


Testing
-------

Test the ``form_validator`` without having to instantiate the ``ModelForm``:

.. code-block:: python

    def test_my_form_validator(self):
        options = {
            'f1': YES,
            'f2': None}
        form_validator = MyFormValidator(cleaned_data=options)
        self.assertRaises(ValidationError, form_validator.validate)
        self.assertIn('f2', form_validator._errors)


.. |pypi| image:: https://img.shields.io/pypi/v/edc-form-validators.svg
    :target: https://pypi.python.org/pypi/edc-form-validators

.. |actions| image:: https://github.com/clinicedc/edc-form-validators/actions/workflows/build.yml/badge.svg
  :target: https://github.com/clinicedc/edc-form-validators/actions/workflows/build.yml

.. |codecov| image:: https://codecov.io/gh/clinicedc/edc-form-validators/branch/develop/graph/badge.svg
  :target: https://codecov.io/gh/clinicedc/edc-form-validators

.. |downloads| image:: https://pepy.tech/badge/edc-form-validators
   :target: https://pepy.tech/project/edc-form-validators

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/clinicedc/edc-form-validators",
    "name": "edc-form-validators",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": "",
    "keywords": "django modelform form validation edc,clinicedc,clinical trials",
    "author": "Erik van Widenfelt",
    "author_email": "ew2789@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/ed/1d/373e2f6d740323f136ad08cfd64d5d74ea669b8d53700cb86f424ce6e79e/edc-form-validators-0.3.40.tar.gz",
    "platform": null,
    "description": "|pypi| |actions| |codecov| |downloads|\n\nedc-form-validators\n-------------------\n\nForm validator classes for ModelForms\n\n\nModelForm ``FormValidator``\n---------------------------\n\n``FormValidator`` simplifies common patterns used in ``ModelForm.clean``. For example, if there is a response to field A then there should not a be response to field B and visa-versa.\n\nDeclare a form with it's ``form_validator`` class and use ``FormValidatorMixin``:\n\n.. code-block:: python\n\n    class MyFormValidator(FormValidator):\n\n        def clean(self):\n            self.required_if(\n                YES,\n                field='f1',\n                field_required='f2')\n            ...\n\n    class MyModelForm(FormValidatorMixin, forms.ModelForm):\n\n        form_validator_cls = MyFormValidator\n\n        class Meta:\n            model = TestModel\n            fields = '__all__'\n\n\nTesting\n-------\n\nTest the ``form_validator`` without having to instantiate the ``ModelForm``:\n\n.. code-block:: python\n\n    def test_my_form_validator(self):\n        options = {\n            'f1': YES,\n            'f2': None}\n        form_validator = MyFormValidator(cleaned_data=options)\n        self.assertRaises(ValidationError, form_validator.validate)\n        self.assertIn('f2', form_validator._errors)\n\n\n.. |pypi| image:: https://img.shields.io/pypi/v/edc-form-validators.svg\n    :target: https://pypi.python.org/pypi/edc-form-validators\n\n.. |actions| image:: https://github.com/clinicedc/edc-form-validators/actions/workflows/build.yml/badge.svg\n  :target: https://github.com/clinicedc/edc-form-validators/actions/workflows/build.yml\n\n.. |codecov| image:: https://codecov.io/gh/clinicedc/edc-form-validators/branch/develop/graph/badge.svg\n  :target: https://codecov.io/gh/clinicedc/edc-form-validators\n\n.. |downloads| image:: https://pepy.tech/badge/edc-form-validators\n   :target: https://pepy.tech/project/edc-form-validators\n",
    "bugtrack_url": null,
    "license": "GPL license, see LICENSE",
    "summary": "Form validator classes for common patterns in django ModelForms.",
    "version": "0.3.40",
    "project_urls": {
        "Homepage": "https://github.com/clinicedc/edc-form-validators"
    },
    "split_keywords": [
        "django modelform form validation edc",
        "clinicedc",
        "clinical trials"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f627823864ed8e5384758a9747d4eb8ee189fd6505ef20b19eb545105e6fbd61",
                "md5": "6cfa715b25b62b3546db8527b02626f9",
                "sha256": "b577b7b8327ac8e0382e190aa68dcd4d4f6cf1787293a75d573ce097ec700526"
            },
            "downloads": -1,
            "filename": "edc_form_validators-0.3.40-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6cfa715b25b62b3546db8527b02626f9",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 48268,
            "upload_time": "2024-01-24T05:53:57",
            "upload_time_iso_8601": "2024-01-24T05:53:57.436812Z",
            "url": "https://files.pythonhosted.org/packages/f6/27/823864ed8e5384758a9747d4eb8ee189fd6505ef20b19eb545105e6fbd61/edc_form_validators-0.3.40-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ed1d373e2f6d740323f136ad08cfd64d5d74ea669b8d53700cb86f424ce6e79e",
                "md5": "9b9cfb329b6f1c04428c74b44ffa4d70",
                "sha256": "c226e3e75cfc4b4803ce937fe5fdc95358ac18a3d7bec618d1e236d8230c6fd7"
            },
            "downloads": -1,
            "filename": "edc-form-validators-0.3.40.tar.gz",
            "has_sig": false,
            "md5_digest": "9b9cfb329b6f1c04428c74b44ffa4d70",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 41700,
            "upload_time": "2024-01-24T05:53:59",
            "upload_time_iso_8601": "2024-01-24T05:53:59.275503Z",
            "url": "https://files.pythonhosted.org/packages/ed/1d/373e2f6d740323f136ad08cfd64d5d74ea669b8d53700cb86f424ce6e79e/edc-form-validators-0.3.40.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-24 05:53:59",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "clinicedc",
    "github_project": "edc-form-validators",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "lcname": "edc-form-validators"
}
        
Elapsed time: 1.17249s