Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

edc-form-validators

Package Overview
Dependencies
Maintainers
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

edc-form-validators

Form validator classes for common patterns in django ModelForms.

  • 0.3.41
  • PyPI
  • Socket score

Maintainers
2

|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

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc