[Grok-dev] Re: letting Grok take over the site
Philipp von Weitershausen
philipp at weitershausen.de
Mon Sep 17 09:10:30 EDT 2007
Brandon Craig Rhodes wrote:
> PvW suggested this belongs in a separate thread, and I agree, since
> there's an issue of terminology to settle as well.
> There should be a simple way to create a Grok app that "owns the whole
> Zope instance" that it runs inside. People to whom I've shown Grok
> are confused that, having written my app, I don't just get to access
> it at the root "/" URL of my web site. They don't understand why I
> should have to then enter a GUI and instantiate my app.
Yup. I would actually like it if Zope would take a particular
grok.Application class and use it to make the root object of my ZODB. So
that when I first start my Zope application, I get an instance of my
application instead of the root folder.
This will have some problems, though:
* You're bound to make persistent changes to your application class
which means you'll have to be able to evolve or delete it somehow. This
is possible to accomplish, but it'll require some surgery.
* We'll need a way to tell Zope which application to use if you have
several installed. It also bears the question whether we should allow
several applications to be instantiated in one ZODB, just like we do now.
> So it would be neat to have a Grok component named something like
> "Site" that you could inherit from to build an app that owns the root:
> class MyApp(grok.Site, grok.Container):
> But here we hit a terminology conflict - there already seems to be a
> notion of a "Site" in Grok, and it does *not* mean the whole web site!
Amen brother. I have preached and preached against Zope3's weird use of
the name "site". What it really means is "place where components are
registered". We should perhaps at least call it "component site" which
is sort of a compromise. Last time I suggested that, it got shot down,
> There is a function called "grok.getSite()" that, contrary to its
> name, returns the application instance you are running inside of! One
> would have thought it would have been called "getApplication()" so
> that it would be symmetric with the class name "grok.Application".
grok.Application is a subclass of grok.Site. So the terminology is correct.
> It would therefore seem most consistent if:
> - grok.Application declared an application.
It does that now. Or perhaps I'm not getting the actual meaning of that
> - grok.getApplication() returned the application you're inside of.
I still don't see a use for this. Perhaps only from a terminology point
> - By default you were inside of a site that holds Grok app instances.
> - grok.getSite() returns the root of the whole site.
I don't understand how this would be different from grok.getApplication().
> - By inheriting an object from grok.Site, your code could take it over.
I think grok.Application should be thing that lets you take over the
root. grok.Site is something any object can implement anywhere in the
hierarchy to make local component registrations. (You can nest sites).
http://worldcookery.com -- Professional Zope documentation and training
More information about the Grok-dev