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.27.tar.gz
(39.4 kB
view hashes)
Built Distribution
Close
Hashes for edc-form-validators-0.3.27.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06cdd7180526f302b06b1e611442c0728b195f3cb89a3216048dac7e9430821b |
|
MD5 | d43c78bc02ddea804991f25ddad3357d |
|
BLAKE2b-256 | 9a16668be012dac7c7b349da004e1b584a7669dbe25beae24570901205c2ad65 |
Close
Hashes for edc_form_validators-0.3.27-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0c31a5377873ceb8368d61fe50627dec36bfb45837abb0dde7d15e1a9ddaca5 |
|
MD5 | 73feb09481c843d465ad3bf9a3b727ed |
|
BLAKE2b-256 | 2612c87b49dd1b7fed1196dc7c5697bd3ed73a8d4726fa430dfde6d31f0b2b6b |