[Grok-dev] Re: Using martian to load schemata
Martijn Faassen
faassen at startifact.com
Wed Jun 25 12:49:37 EDT 2008
Martin Aspeli wrote:
> Martijn Faassen <faassen <at> startifact.com> writes:
>
>> Yes, this is a good point. grok.Fields() (or formlib FormFields) work
>> during import time, so you can't get the schema yet.
>>
>> You can work around this, but you'd need to make it a property:
>>
>> class MyForm(grok.EditForm):
>> @property
>> def form_fields(self):
>> return grok.Fields(IMySchema)
>>
>> This way grok.Fields will only be executed during runtime, as the form
>> is being rendered.
>>
>> We run into similar problems when generating a schema from RDB schema.
>> It's unfortunate the form code assumes the schemas need to exist already
>> during import time. I wonder whether z3c.form has a better way?
>
> Sounds like a bit of a general problem. If you want to be able to use Zope
> 3 components in grokkers/martian directives, you're going to get into funny
> dependency loops, I think.
This has absolutely nothing to do with Martian, just with the way
configuration works in Zope 3. If you are going to define your schema at
configuration time (or run time) and want to *use* them during import
time (as grok.Fields or formlib in general actually does), i.e. *before*
configuration, you'll have this problem.
In the rdb case we're not even using Martian to define the schema, we
just call a function to get it, defining the schema during run time.
You can use Zope 3 components in zope.configuration actions, you just
need to get the order right.
Regards,
Martijn
More information about the Grok-dev
mailing list