[Grok-dev] Re: Using martian to load schemata

Martijn Faassen faassen at startifact.com
Wed Jun 25 12:20:37 EDT 2008

Martin Aspeli wrote:
> I was wondering if this could be done with Martian. I assume Grok will have the
> same problem in places.

Martian by itself doesn't involve itself with the component architecture 
but Grok indeed does. Grok generates actions during grok time, and then 
at the end of Zope 3's configuration process, all the actions are 
executed. You can use martian.priority to influence the order in which 
things are grokked, but only on a per-module level.

Now ZCML actions also have an ordering process. This order is, I 
believe, global. You can pass an 'order' argument to the config.action() 
method. If you want something to be done early on, you give it a low 
(negative) order. If you want something to be done at the end, I'm not 
sure what you can do, but you could at least give it an order lower than 
that of the utility registrations.

> I would also consider switching the syntax a bit, to be:
>  from zope.interface import Interface
>  from plone.supermodel import xml_schema
>  class IPage(Interface):
>      xml_schema("page.xml")
> This wouldn't create a dynamic base class, but instead it would scribble the
> fields onto the IPage class. Again, it would need to do so after the CA was
> loaded, though.
> Can anyone tell me whether Martian would be worth exploring here? 

You could use Martian to detect Interface subclasses and then look for 
the xml_schema directive on them, and register an action.

This action would then load up the XML and scribble into the interface. 
If the action is given a high enough order, it'll be executed after the 
other actions that register your utilities or adapters or whatnot. What 
this order is, I'm not sure.

> Or do I need
> something else that's more aware of the Zope 3 CA? I don't fully understand how
> to react once the CA is loaded, though I'm guessing I should be using
> zope.configuration actions in some way and ensure that my actions execute late
> in the process?

Yes, that's the way, as described above.

> Any hints would be greatly appreciated. I also hope that you guys may be
> interested in plone.supermodel. It should work for any application that bases
> its models on zope.schema interfaces and wants to load those from XML. Use 
> cases in Plone land include a way to do this with a TTW-only schema, in order 
> to support TTW type creation, and support for using GUI tools to build the 
> model file.

If you store your schema information in the ZODB I wonder how you're 
going to do this. The XML cannot be loaded during configuration time 
then, as at least to my knowledge, the ZODB isn't loaded yet during 
configuration time. In addition, only global component registrations 
will have been made - you cannot get to local utilities at this point. 
Loading it from a file shouldn't be a problem though, as you can do this 
during configuration time.



More information about the Grok-dev mailing list