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.23.tar.gz
(38.8 kB
view hashes)
Built Distribution
Close
Hashes for edc-form-validators-0.3.23.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | c493bee33629a13f9c15b7921e235f6acd2a9bea1c61833425085f5a306fa0f5 |
|
MD5 | 6253825e08feb4f4467d045b203114eb |
|
BLAKE2b-256 | b1c1513b7beaa3e55485a83654e01bdc01df813ad7b2369548f218ac297020bd |
Close
Hashes for edc_form_validators-0.3.23-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c9f0f676bf558a4c72a2aedebbe345a3675ea01a15c14d095af39adcaa9a7e4 |
|
MD5 | b9389422d815e2bb2fc3427e7f3c4318 |
|
BLAKE2b-256 | a938e65f396a623be5e89175c86c3bc0383bff09fff46720bb5933483faaaea8 |