1# from bolt.exceptions import ValidationError
2
3# class APIFormMixin:
4# def clean(self):
5# cleaned_data = super().clean()
6
7# # Make sure all the field names are present in the input data
8# for name, field in self.fields.items():
9# if name not in self.data:
10# raise ValidationError(f"Missing field {name}")
11
12# return cleaned_data
13
14
15class APIPartialFormMixin:
16 def __init__(self, *args, **kwargs):
17 super().__init__(*args, **kwargs)
18
19 # If any field is not present in the JSON input,
20 # then act as if it's "disabled" so Bolt
21 # will keep the initial value instead of setting it to the default.
22 # This is required because stuff like checkbox doesn't submit in HTML form data when false.
23 for name, field in self.fields.items():
24 if name not in self.data:
25 field.disabled = True