[Zope3-dev] Re: Applying schema data on an object
Rocky Burt
rocky at serverzen.com
Wed Dec 13 11:37:17 EST 2006
On Wed, 2006-13-12 at 17:19 +0100, Christian Theune wrote:
> I'd like to remove the explicit assignments from the constructor and use
> a function to do this in a generic way. I didn't find anything that does
> this yet, except from a formlib function that requires FormFields
> instead of a schema, so I wrote my own:
>
> -----
> def set_schema_data(context, schema, data):
> """Update the context's attributes with the given data that belongs
> to the specified schema.
> """
> for name in schema:
> field = schema[name]
> if not zope.schema.interfaces.IField.providedBy(field):
> continue
> if name in data:
> field.set(context, data[name])
> -----
>
> There is a function around already which comes from zope.formlib and
> requires the schema to be specified as a FormFields setup. I'd like to
> not have the formlib dependency in this code.
>
> I propose to include the given function in zope.schema or
> zope.interface. Eventually this could also be spelled as a method on a
> schema (symmetrical to field.set): schema.set(object, data)
This all looks good to me... but might I make the suggestion that you
refactor the zope.formlib code that works with FormFields to use your
function as well? I agree it's not good to make the other code
dependent on formlib, but of course formlib already depends on
zope.interface and zope.schema.
Regards,
Rocky
--
Rocky Burt
ServerZen Software -- http://www.serverzen.com
News About The Server (blog) -- http://www.serverzen.net
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://mail.zope.org/pipermail/zope3-dev/attachments/20061213/fc3d7110/attachment.bin
More information about the Zope3-dev
mailing list