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.


Rocky Burt
ServerZen Software -- http://www.serverzen.com
News About The Server (blog) -- http://www.serverzen.net

Attachment: signature.asc
Description: This is a digitally signed message part

Zope3-dev mailing list
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com

Reply via email to