Make jQuery time widget input even more flexible
e.g. allow any of: * 01:30 PM * 1:30pm * 11 AM * 11am
This commit is contained in:
parent
42b97d1e1a
commit
e58ca10e25
|
@ -37,11 +37,18 @@ class JQueryTime(colander.Time):
|
||||||
def deserialize(self, node, cstruct):
|
def deserialize(self, node, cstruct):
|
||||||
if not cstruct:
|
if not cstruct:
|
||||||
return colander.null
|
return colander.null
|
||||||
|
|
||||||
|
formats = [
|
||||||
|
'%I:%M %p',
|
||||||
|
'%I:%M%p',
|
||||||
|
'%I %p',
|
||||||
|
'%I%p',
|
||||||
|
]
|
||||||
|
for fmt in formats:
|
||||||
try:
|
try:
|
||||||
return colander.timeparse(cstruct, '%I:%M %p')
|
return colander.timeparse(cstruct, fmt)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
try:
|
pass
|
||||||
return colander.timeparse(cstruct, '%I:%M%p')
|
|
||||||
except:
|
# re-try first format, for "better" error message
|
||||||
# re-try first format, for "better" error
|
return colander.timeparse(cstruct, formats[0])
|
||||||
return colander.timeparse(cstruct, '%I:%M %p')
|
|
||||||
|
|
Loading…
Reference in a new issue