More tweaks in support of Deform.

This commit is contained in:
Chris McDonough
2010-05-08 06:38:52 +00:00
parent 4eefbb5f9b
commit cc9f8c406c
3 changed files with 29 additions and 15 deletions

View File

@@ -10,7 +10,12 @@ Next release
of Unicode values is done by the String type. This differs from the
previous behavior, where ``None`` implied that the encoding was
``utf-8``. Pass the encoding as ``utf-8`` specifically to get the
older behavior back.
older behavior back. This is in support of Deform.
- The default ``err_template`` value attached to the ``colander.Date``
and ``colander.Datetime` types was changed. It is now simply
``Invalid date`` instead of ``_('${val} cannot be parsed as an
iso8601 date: ${err}')``. This is in support of Deform.
0.6.1 (2010-05-04)
------------------

View File

@@ -798,7 +798,7 @@ class Boolean(object):
if not value:
if node.required:
raise Invalid(node, _('Required'))
value = node.default
return node.default
value = value.lower()
if value in ('false', '0'):
return False
@@ -944,11 +944,13 @@ class DateTime(object):
You can adjust the error message reported by this class by
changing its ``err_template`` attribute in a subclass on an
instance of this class. By default, the ``err_template``
attribute is the string ``${value} cannot be parsed as an iso8601
date: ${exc}``. This string is used as the interpolation subject
of a dictionary composed of ``val`` and ``err``. ``val`` and
``err`` are the unvalidatable value and the exception caused
trying to convert the value, respectively.
attribute is the string ``Invalid date``. This string is used as
the interpolation subject of a dictionary composed of ``val`` and
``err``. ``val`` and ``err`` are the unvalidatable value and the
exception caused trying to convert the value, respectively. These
may be used in an overridden err_template as ``${val}`` and
``${err}`` respectively as necessary, e.g. ``_('${val} cannot be
parsed as an iso8601 date: ${err}')``.
For convenience, this type is also willing to coerce
``datetime.date`` objects to a DateTime ISO string representation
@@ -964,7 +966,8 @@ class DateTime(object):
The subnodes of the :class:`colander.SchemaNode` that wraps
this type are ignored.
"""
err_template = _('${val} cannot be parsed as an iso8601 date: ${err}')
err_template = _('Invalid date')
def __init__(self, default_tzinfo=None):
if default_tzinfo is None:
default_tzinfo = iso8601.iso8601.Utc()
@@ -1007,11 +1010,13 @@ class Date(object):
You can adjust the error message reported by this class by
changing its ``err_template`` attribute in a subclass on an
instance of this class. By default, the ``err_template``
attribute is the string ``${val} cannot be parsed as an iso8601
date: ${err}``. This string is used as the interpolation subject
of a dictionary composed of ``val`` and ``err``. ``val`` and
``exc`` are the unvalidatable value and the exception caused
trying to convert the value, respectively.
attribute is the string ``Invalid date``. This string is used as
the interpolation subject of a dictionary composed of ``val`` and
``err``. ``val`` and ``err`` are the unvalidatable value and the
exception caused trying to convert the value, respectively. These
may be used in an overridden err_template as ``${val}`` and
``${err}`` respectively as necessary, e.g. ``_('${val} cannot be
parsed as an iso8601 date: ${err}')``.
For convenience, this type is also willing to coerce
``datetime.datetime`` objects to a date-only ISO string
@@ -1028,7 +1033,7 @@ class Date(object):
The subnodes of the :class:`colander.SchemaNode` that wraps
this type are ignored.
"""
err_template = _('${val} cannot be parsed as an iso8601 date: ${err}')
err_template = _('Invalid date')
def serialize(self, node, value):
if isinstance(value, datetime.datetime):
value = value.date()

View File

@@ -46,7 +46,11 @@ Exceptions
An attribute not used internally by Colander, but which can be
used by higher-level systems to attach arbitrary values to
Colander exception nodes.
Colander exception nodes. For example, In the system named
Deform, which uses Colander schemas to define HTML form
renderings, the ``value`` is used when raising an exception
from a widget as the value which should be redisplayed when an
error is shown.
Validators
~~~~~~~~~~