diff --git a/tailbone/forms/renderers/core.py b/tailbone/forms/renderers/core.py index e68d4777..0f3c925c 100644 --- a/tailbone/forms/renderers/core.py +++ b/tailbone/forms/renderers/core.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2015 Lance Edgar +# Copyright © 2010-2016 Lance Edgar # # This file is part of Rattail. # @@ -24,16 +24,16 @@ Core Field Renderers """ -from __future__ import unicode_literals +from __future__ import unicode_literals, absolute_import import datetime -import formalchemy +import formalchemy as fa from formalchemy.fields import AbstractField from pyramid.renderers import render -class CustomFieldRenderer(formalchemy.FieldRenderer): +class CustomFieldRenderer(fa.FieldRenderer): """ Base class for renderers which accept customization args, and "fake out" FormAlchemy by pretending to still be a renderer factory when in fact it's @@ -59,7 +59,7 @@ class CustomFieldRenderer(formalchemy.FieldRenderer): return self.request.rattail_config -class DateFieldRenderer(CustomFieldRenderer, formalchemy.DateFieldRenderer): +class DateFieldRenderer(CustomFieldRenderer, fa.DateFieldRenderer): """ Date field renderer which uses jQuery UI datepicker widget when rendering in edit mode. @@ -79,7 +79,12 @@ class DateFieldRenderer(CustomFieldRenderer, formalchemy.DateFieldRenderer): value = self._serialized_value() if not value: return None - return datetime.datetime.strptime(value, '%Y-%m-%d') + try: + return datetime.datetime.strptime(value, '%Y-%m-%d') + except ValueError: + raise fa.ValidationError("Date value must be in YYYY-MM-DD format") + except Exception as error: + raise fa.ValidationError(unicode(error)) def _serialized_value(self): return self.params.getone(self.name)