Commit d71c4187 authored by Xiaowu Zhang's avatar Xiaowu Zhang

Formulator DateTimeField: add ampm validate

parent 13ea2b27
...@@ -741,6 +741,11 @@ class DateTimeValidator(Validator): ...@@ -741,6 +741,11 @@ class DateTimeValidator(Validator):
id = field.generate_subfield_key(name, validation = 1, key = key) id = field.generate_subfield_key(name, validation = 1, key = key)
if name == "timezone": if name == "timezone":
return REQUEST.get(id) return REQUEST.get(id)
if name == "ampm":
ampm = REQUEST.get(id)
if ampm in ('am', 'pm'):
return ampm
raise ValidationError('not_datetime', field)
return IntegerValidatorInstance.validate(field, id, REQUEST) return IntegerValidatorInstance.validate(field, id, REQUEST)
def validate(self, field, key, REQUEST): def validate(self, field, key, REQUEST):
...@@ -787,6 +792,7 @@ class DateTimeValidator(Validator): ...@@ -787,6 +792,7 @@ class DateTimeValidator(Validator):
self.raise_error('not_datetime', field) self.raise_error('not_datetime', field)
if field.get_value('ampm_time_style'): if field.get_value('ampm_time_style'):
try:
ampm = self.validate_sub_field(field, key, 'ampm', REQUEST) ampm = self.validate_sub_field(field, key, 'ampm', REQUEST)
if field.get_value('allow_empty_time'): if field.get_value('allow_empty_time'):
if ampm == '': if ampm == '':
...@@ -800,7 +806,8 @@ class DateTimeValidator(Validator): ...@@ -800,7 +806,8 @@ class DateTimeValidator(Validator):
self.raise_error('not_datetime', field) self.raise_error('not_datetime', field)
elif ampm == 'pm' and hour < 12: elif ampm == 'pm' and hour < 12:
hour += 12 hour += 12
except ValidationError:
self.raise_error('not_datetime', field)
# handle possible timezone input # handle possible timezone input
timezone = '' timezone = ''
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment