Skip to content

Commit

Permalink
Propagate kwargs from Form.is_valid() to Form.validate() and `F…
Browse files Browse the repository at this point in the history
…orm.validate_{key}()` methods. 👾
  • Loading branch information
Sibyx committed Nov 11, 2019
1 parent fd3ad55 commit 123c59c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.3.0 : 11.11.2019

- **Feature**: Propagate `kwargs` from `Form.is_valid()` to `Form.validate()` and `Form.validate_{key}()` methods.

## 0.2.1 : 4.11.2019

- **Fix**: Fixed `to_python()` in FormFieldList
Expand Down
2 changes: 1 addition & 1 deletion django_request_formatter/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.2.1'
__version__ = '0.3.0'
8 changes: 4 additions & 4 deletions django_request_formatter/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def fill(self, obj):
for key, item in self._data.items():
setattr(obj, key, item)

def is_valid(self, raise_exception: bool = True):
def is_valid(self, raise_exception: bool = True, **kwargs):
errors = {}

for key, field in self.fields.items():
Expand All @@ -125,15 +125,15 @@ def is_valid(self, raise_exception: bool = True):

if hasattr(self, f"validate_{key}"):
try:
getattr(self, f"validate_{key}")(self._data.get(key, None))
getattr(self, f"validate_{key}")(self._data.get(key, None), **kwargs)
except ValidationError as e:
field_errors.append(e)

if field_errors:
errors[key] = field_errors

try:
self.validate()
self.validate(**kwargs)
except ValidationError as e:
errors = {**errors, **e.error_dict}

Expand All @@ -145,7 +145,7 @@ def is_valid(self, raise_exception: bool = True):

return True

def validate(self):
def validate(self, **kwargs):
pass


Expand Down

0 comments on commit 123c59c

Please sign in to comment.