diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-06-23 03:32:59 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-06-23 03:32:59 +0000 |
| commit | dfea6bdfa5f629679960115f26498fb4a378d75b (patch) | |
| tree | 0ac5c98694400acf65338b90fc9270e42ff617e9 /django/newforms | |
| parent | 08aa5c585b511cfaf97ced38f2b5f7fb96492203 (diff) | |
Fixed #4630 -- Fixed some validation problems with SplitDateTimeField. Thanks
glin@seznam.cz and SmileyChris.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5515 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/newforms')
| -rw-r--r-- | django/newforms/fields.py | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/django/newforms/fields.py b/django/newforms/fields.py index 471318e95f..167281a061 100644 --- a/django/newforms/fields.py +++ b/django/newforms/fields.py @@ -516,11 +516,13 @@ class MultiValueField(Field): """ clean_data = [] errors = ErrorList() - if self.required and not value: - raise ValidationError(gettext(u'This field is required.')) - elif not self.required and not value: - return self.compress([]) - if not isinstance(value, (list, tuple)): + if not value or isinstance(value, (list, tuple)): + if not value or not [v for v in value if v not in EMPTY_VALUES]: + if self.required: + raise ValidationError(gettext(u'This field is required.')) + else: + return self.compress([]) + else: raise ValidationError(gettext(u'Enter a list of values.')) for i, field in enumerate(self.fields): try: @@ -558,5 +560,11 @@ class SplitDateTimeField(MultiValueField): def compress(self, data_list): if data_list: + # Raise a validation error if time or date is empty + # (possible if SplitDateTimeField has required=False). + if data_list[0] in EMPTY_VALUES: + raise ValidationError(gettext(u'Enter a valid date.')) + if data_list[1] in EMPTY_VALUES: + raise ValidationError(gettext(u'Enter a valid time.')) return datetime.datetime.combine(*data_list) return None |
