Skip to main content

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:

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:

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)

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

edc_form_validators-1.0.0.tar.gz (41.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

edc_form_validators-1.0.0-py3-none-any.whl (48.8 kB view details)

Uploaded Python 3

File details

Details for the file edc_form_validators-1.0.0.tar.gz.

File metadata

  • Download URL: edc_form_validators-1.0.0.tar.gz
  • Upload date:
  • Size: 41.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.4

File hashes

Hashes for edc_form_validators-1.0.0.tar.gz
Algorithm Hash digest
SHA256 41c469692a8521d8a8eb7aeb5c12ff64aab5a1d4cef228b83a84604aa35ee4e2
MD5 52e903af2e10ed17a6a5abfc4e654e69
BLAKE2b-256 9cdd01111135a512c0d256318ed347bafd081fd4f533c469cc5493508fe3fbfe

See more details on using hashes here.

File details

Details for the file edc_form_validators-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for edc_form_validators-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cd03d3b70bfef5fa024ef8bfff0d29832523f574049d8703ee7749d9117ae162
MD5 1792576dd65a9251a7c482b1884e245a
BLAKE2b-256 0f7c14d1265193e95269919ba6d9934eb0631a246b4f75b3abab40895a34b53c

See more details on using hashes here.

Release history Release notifications | RSS feed

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page