[Grok-dev] Re: Using martian to load schemata
Martijn Faassen
faassen at startifact.com
Wed Jun 25 12:24:32 EDT 2008
Martin Aspeli wrote:
> Martin Aspeli <optilude <at> gmx.net> writes:
>
>> Can anyone tell me whether Martian would be worth exploring here? 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?
>
> I've been digging around martian and grokcore.component. I see how
> grokcore.component uses configuration actions via a 'config' variable. I
> *think* I could do something similar, e.g.
>
> class IPage(Schema):
> model("page.xml")
>
> where Schema would be a grokkable base class and model would be a martian
> directive.
Yes, you'd have a component called Schema that you'd grok for with a
ClassGrokker, and you'd define a directive called model. Something like:
class SchemaGrokker(martian.ClassGrokker):
martian.component(Schema)
martian.directive(model)
def execute(self, class_, config, model, **kw):
... register your action here...
You'd need to use at least grokcore.component to get the 'grok'
directive available. Martian itself doesn't interface with
zope.configuration.
> What I haven't quite understood, is where the 'config' parameter in e.g. the
> AdapterGrokker's execute() method comes from. I guess it has something to do
> with directive.bind(), but I got a bit lost in the code at that point.
No, that's unrelated. The 'config' parameter comes from the
zope.configuration machinery. It's passed in to the 'grok' ZCML
directive implementation as implemented in grokcore.component.zcml.
> I'm also not quite sure how to use config.action() to ensure that my
> particular callable gets executed after all standard components have been set
> up, though I guess that's a zope.configuration question?
Give it an 'order' argument.
Regards,
Martijn
More information about the Grok-dev
mailing list