[Zope] local and global site manager, adapter and utility questions

Thierry Florac thierry.florac at onf.fr
Tue Jun 11 07:24:15 UTC 2013


Hi Tamer,

Le Sun, 09 Jun 2013 17:30:26 +0200,
  Tamer Higazi <th982a at googlemail.com> a écrit:

> Hi Thierry!
> Thanks for your lat response, meanwhile things are getting more and
> more clear to me.
> 
> I got it meanwhile to register utilities through the
> globalSiteManager, and I am now very familiar now with zca basics
> (though that I have much more to learn of it's API)
> 
> There is something totally unclear to me!
> 
> 
> I got 2 applications registered in the
> "/storage/PyProjects/ztfyAPP/etc/configure.zcml"
> 
> tamer at office /storage/PyProjects/ztfyAPP/src $ ls -lA
> insgesamt 16
> drwxr-xr-x 2 tamer tamer 4096  9. Jun 07:40 appsx
> drwxr-xr-x 2 tamer tamer 4096 20. Mai 16:13 appsx.egg-info
> drwxr-xr-x 4 tamer tamer 4096  9. Jun 07:43 webapp
> drwxr-xr-x 2 tamer tamer 4096 20. Mai 02:35 webapp.egg-info
> 
> 
> that is "webapp" and "appsx"
> 
> so far so good.
> 
> At /storage/PyProjects/ztfyAPP/src/appsx/__init__.py:
> 
> I globally registered a class, which definied previously as a utility.
> 
> 
> from Services import *
> from zope.component import getGlobalSiteManager
> from zope.component import getUtilitiesFor,queryUtility
> 
> gsmx = getGlobalSiteManager()
> 
> VAT = VATServices()
> gsmx.registerUtility(VAT,IVATServices,'VAT')
> 
> 
> 
> now I want to have access this utility in the global sitemanager from
> one other app.
> 
> /storage/PyProjects/ztfyAPP/src/webapp/__init__.py:
> 
> from myhello import HelloView
> from zope.component import getGlobalSiteManager
> 
> #print list(getUtilitiesFor('IVatServices'))
> 
> gsmx2 = getGlobalSiteManager()
> gsmx2.queryUtility(IVATServices,'VAT').Hallo()
> 
> 
> I thought it is in the memory. Okay, that the interface is not
> available in the other application is clear.
> 
> 
> But, how do I access components or utilities registered in a different
> application globally, at one other application at all ?!


There are two points about your configuration:

1. It's a personal choice but I never add code inside a ZTFY.webapp
   environment. My application code is always written in external
   packages, and only referenced in my execution environments (by
   updating setup.py, buildout.cfg and configure.zcml).

2. Anyway, if both of your applications are correctly referenced in
   configure.zcml and included in the global registry, you should be
   able to use any of it's components from anywhere in your code. So my
   question is simple: are you sure that the second application (appsx)
   is correctly included in your execution environment and registered?
   You can check that by using the apidoc tool (in debug mode, using
   http://localhost:8080/++apidoc++ by default) and searching for one
   of your interfaces or utilities registered in this package...

Regards,
Thierry



More information about the Zope mailing list