Skip to content

Commit a296d4e

Browse files
author
Sylvain Delabye
committed
Allow future date validations with boolean values
1 parent 7d4dd09 commit a296d4e

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ master (unreleased)
99
- Add/Confirm support of Django REST Framework 3.11 (#417).
1010
- Added a thorough documentation for maintainers
1111
- Pin psycopg2-binary to 2.8 in testing env to fix CI.
12+
- Allow to create validations `IS_DATE_IN_THE_FUTURE` by passing a boolean value instead of a string.
1213

1314
Release 7.0.0 (2021-03-11)
1415
==========================

formidable/serializers/validation.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,14 @@ class FutureDateSerializer(ValidationSerializer):
128128

129129
type_id = 'IS_DATE_IN_THE_FUTURE'
130130

131+
def to_internal_value(self, data):
132+
if isinstance(data['value'], bool):
133+
data['value'] = str(data['value'])
134+
data = super().to_internal_value(data)
135+
return data
136+
131137
def validate_value(self, value):
132-
if value in ['t', "true"]:
133-
return "true"
138+
if value in ['t', 'true', 'True']:
139+
return 'true'
134140
else:
135-
return "false"
141+
return 'false'

0 commit comments

Comments
 (0)