Form validator classes for common patterns in django ModelForms.
Project description
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 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)
Project details
Release history Release notifications | RSS feed
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-0.3.21.tar.gz
(38.8 kB
view hashes)
Built Distribution
Close
Hashes for edc-form-validators-0.3.21.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32e8b048c11c07f03c0dd87a25aa976aa201af45e10235a4289bb895d0032687 |
|
MD5 | 0df96aabefa527a93d11334777e8cb3b |
|
BLAKE2b-256 | 441cfa2f0781c0a86710b29d5345f32101def000025f1aeee6b75a711e412d9a |
Close
Hashes for edc_form_validators-0.3.21-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 270b2e077826f8a7ab6bf84a162f5413a0da1a6abce17f644bfe9814734fe88f |
|
MD5 | 990efc597c08d1750e9f056e6ed81477 |
|
BLAKE2b-256 | b7a2861cf322d8b8f7bab5792d6ba80d570c19dc2a89e2cdb2ed96ab6c4698fd |