On Fri, 2010-05-28 at 08:28 -0400, Chris McDonough wrote:
> I agree with how Tim just characterized this.  I'm still trying to
> figure out what the best way to spell it.
> 
> My current idea is to:
> 
> - Define a special "null" sentinel value.
> 
> - Change the type definitions and widget definitions to do something 
>   sensible when they see a "null" during serialization and
>   deserialization. (e.g. "n = SchemaNode(default=null)").
> 
> - Add a required= flag to SchemaNode, e.g. field = SchenaNode(Integer(),
>   required=True).
> 
> - Decouple the meaning of default and required.


This isn't quite how it worked out.

Instead, the SchemaNode constructor grew a "missing" argument, which
represents the value to be used if a form deserialization returns a
"colander.default" sentinel.  If this "missing" argument is provided,
the node is not required.  If the missing argument is not provided, the
node is required.  The "missing" argument may be "colander.null",
representing the null value.  For example:

import colander

class StandardFields(colander.MappingSchema):
    manufacturer = SchemaNode(String(), missing='') # not required
    obsolete_date = SchemaNode(Date(),missing=colander.null)
    length = SchemaNode(Float(), missing=colander.null)
    units_per_pack = SchemaNode(Integer(), missing=colander.null)

None of the above fields are required.  A field without a "missing"
value, however, is required.

Tge "default" argument to SchemaNode now means the initial serialization
value for values absent from the appstruct but present in the schema.

It would be useful if the folks for whom it mattered could give this new
regime a roll before I merge it to the respective colander and deform
trunks and make new releases of both.

http://svn.repoze.org/deform/branches/default_overhaul/
http://svn.repoze.org/colander/branches/default_overhaul/

These packages must be used together; an older colander cannot be used
with the branch deform; use setup.py develop of both using a virtualenv.
The docs for both branches are more or less up to date and can be built
via "make clean html" from within the "docs" directory of each.  The
result can be viewed by opening ".build/html/index.html" within the docs
directory.  The CHANGES.txt of each also has relatively useful notes
about changes from the last set of releases.

- C


_______________________________________________
Repoze-dev mailing list
Repoze-dev@lists.repoze.org
http://lists.repoze.org/listinfo/repoze-dev

Reply via email to