Fix deserialize logic for jQuery time-picker widget

This commit is contained in:
Lance Edgar 2017-12-08 14:39:23 -06:00
parent 1e8a4534d5
commit abd47ae7ae

View file

@ -26,8 +26,10 @@ Form Widgets
from __future__ import unicode_literals, absolute_import from __future__ import unicode_literals, absolute_import
import six
import json import json
import datetime
import six
import colander import colander
from deform import widget as dfwidget from deform import widget as dfwidget
@ -85,6 +87,18 @@ class JQueryTimeWidget(dfwidget.TimeInputWidget):
('showPeriod', True), ('showPeriod', True),
) )
def deserialize(self, field, pstruct):
if pstruct in ('', colander.null):
return colander.null
try:
validated = self._pstruct_schema.deserialize(pstruct)
except colander.Invalid as exc:
raise colander.Invalid(field.schema, "Invalid pstruct: %s" % exc)
value = validated['time_submit'] or validated['time']
if value:
value = datetime.datetime.strptime(value, '%I:%M %p').strftime('%H:%M')
return value
class JQueryAutocompleteWidget(dfwidget.AutocompleteInputWidget): class JQueryAutocompleteWidget(dfwidget.AutocompleteInputWidget):
""" """