diff --git a/tailbone/forms2/widgets.py b/tailbone/forms2/widgets.py index d314a0f0..90fd0930 100644 --- a/tailbone/forms2/widgets.py +++ b/tailbone/forms2/widgets.py @@ -26,8 +26,10 @@ Form Widgets from __future__ import unicode_literals, absolute_import -import six import json +import datetime + +import six import colander from deform import widget as dfwidget @@ -85,6 +87,18 @@ class JQueryTimeWidget(dfwidget.TimeInputWidget): ('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): """