Allow null for FalafelDateTime form fields

This commit is contained in:
Lance Edgar 2023-10-09 15:50:41 -05:00
parent 9efe767654
commit 44112a3a4b

View file

@ -87,7 +87,7 @@ class FalafelDateTime(colander.DateTime):
def serialize(self, node, appstruct): def serialize(self, node, appstruct):
if not appstruct: if not appstruct:
return colander.null return {}
# cant use isinstance; dt subs date # cant use isinstance; dt subs date
if type(appstruct) is datetime.date: if type(appstruct) is datetime.date:
@ -111,6 +111,9 @@ class FalafelDateTime(colander.DateTime):
if not cstruct: if not cstruct:
return colander.null return colander.null
if not cstruct['date'] and not cstruct['time']:
return colander.null
try: try:
date = datetime.datetime.strptime(cstruct['date'], '%Y-%m-%d').date() date = datetime.datetime.strptime(cstruct['date'], '%Y-%m-%d').date()
except: except: