edc-form-validators


Nameedc-form-validators JSON
Version 0.3.41 PyPI version JSON
download
home_pagehttps://github.com/clinicedc/edc-form-validators
SummaryForm validator classes for common patterns in django ModelForms.
upload_time2024-11-20 22:48:20
maintainerNone
docs_urlNone
authorErik van Widenfelt
requires_python>=3.12
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": null,
    "docs_url": null,
    "requires_python": ">=3.12",
    "maintainer_email": null,
    "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/50/05/f7823697788c7b6949c8f660a3cb58ad0b9905c0d13aa1b5719e0388836a/edc_form_validators-0.3.41.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.41",
    "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": "81b847ff68a214de2abfba08b3b8edcae14ba7a9d81652d68fda3096ed2c38b6",
                "md5": "f3c33bdf148d81ee4c56d2a8140958e5",
                "sha256": "d3ce5b21b35cc277419aede7663ef905e384f6411338195b735e4a5dbc032262"
            },
            "downloads": -1,
            "filename": "edc_form_validators-0.3.41-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f3c33bdf148d81ee4c56d2a8140958e5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.12",
            "size": 48268,
            "upload_time": "2024-11-20T22:48:18",
            "upload_time_iso_8601": "2024-11-20T22:48:18.641427Z",
            "url": "https://files.pythonhosted.org/packages/81/b8/47ff68a214de2abfba08b3b8edcae14ba7a9d81652d68fda3096ed2c38b6/edc_form_validators-0.3.41-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5005f7823697788c7b6949c8f660a3cb58ad0b9905c0d13aa1b5719e0388836a",
                "md5": "2405e58ee678c990a4fb34733bc25e1b",
                "sha256": "8a2d191804abc9bc329c70badb8d82c67092b19ee1906fb3d62a4d03031d081a"
            },
            "downloads": -1,
            "filename": "edc_form_validators-0.3.41.tar.gz",
            "has_sig": false,
            "md5_digest": "2405e58ee678c990a4fb34733bc25e1b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.12",
            "size": 41831,
            "upload_time": "2024-11-20T22:48:20",
            "upload_time_iso_8601": "2024-11-20T22:48:20.435158Z",
            "url": "https://files.pythonhosted.org/packages/50/05/f7823697788c7b6949c8f660a3cb58ad0b9905c0d13aa1b5719e0388836a/edc_form_validators-0.3.41.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-20 22:48:20",
    "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: 0.44892s