[Grok-dev] Re: viewlets and application_root
Luciano Ramalho
luciano at ramalho.org
Thu Apr 24 18:26:35 EDT 2008
On Thu, Apr 24, 2008 at 7:02 PM, Luciano Ramalho <luciano at ramalho.org> wrote:
> On Thu, Apr 24, 2008 at 6:20 PM, Martijn Faassen <faassen at startifact.com> wrote:
> > I think there's a good use case for adding such functionality to both grok
> > itself (just like grok.url()) and to the view (and viewlet, I guess). We
> > already have application_url() which does much the same, but then gets the
> > URL right away. We should factor the walk-up-the-tree functionality out.
> >
> > Contributions would be welcome!
> >
> > (As an alternative I often use grok.getSite(), but that will only work for
> > applications that have no sub-sites in it, so the tree walking would be
> > better here)
>
> That's easy enough that even I can implement it, so I'll do it.
>
> I know where the relevant code is because I actually duplicated part
> of it in kirbi.
>
> What should we call the function?
>
> grok.getApplication() follows the pattern of grok.getSite(). Is that ok?
>
> BTW I see a naming inconsistency between grok.application_url() and
> grok.getSite(). Should we do something about it?
While we are at it, I found something curious about our API usage:
look at the grep output below and note that we have getSite, but it's
practically never used; getSiteManager is much more popular! Should we
add some tests to show the use of getSite?
./__init__.py:from zope.app.component.hooks import getSite
./admin/.svn/text-base/view.py.svn-base: sm =
self.context.getSiteManager()
./admin/view.py: sm = self.context.getSiteManager()
./ftests/catalog/indexes.py: >>> sm = herd.getSiteManager()
./ftests/catalog/indexes_app_interface.py: >>> sm = herd.getSiteManager()
./ftests/catalog/indexes_app_interface.py: >>> sm = herd2.getSiteManager()
./ftests/catalog/indexes_attribute.py: >>> sm = herd.getSiteManager()
./ftests/catalog/indexes_class.py: >>> sm = herd.getSiteManager()
./ftests/catalog/indexes_multiple.py: >>> sm = herd.getSiteManager()
./ftests/catalog/indexes_multiple_conflict.py: >>> sm = herd.getSiteManager()
./ftests/catalog/indexes_name.py: >>> sm = herd.getSiteManager()
./ftests/catalog/indexes_nonexistent.py: >>> sm = herd.getSiteManager()
./ftests/catalog/indexes_set.py: >>> sm = herd.getSiteManager()
./ftests/catalog/indexes_site.py: >>> sm = herd.getSiteManager()
./ftests/utility/local.py: >>> from zope.app.component.hooks import
getSite, setSite
./ftests/utility/local_override.py: >>> from zope.app.component.hooks
import getSite, setSite
./ftests/utility/local_override.py: >>> list(cave.getSiteManager().keys())
./ftests/utility/public.py: >>> from zope.app.component.hooks import
getSite, setSite
./ftests/utility/public.py: >>> (cave2.getSiteManager()['fireplace'] is
./ftests/utility/subclass.py: >>> from zope.app.component.hooks
import getSite, setSite
./interfaces.py: def getSite():
./meta.py: site_manager = site.getSiteManager()
Cheers,
Luciano
More information about the Grok-dev
mailing list