Re: [Zope] local and global site manager, adapter and utility questions
Hi Tamer, Le Sun, 09 Jun 2013 17:30:26 +0200, Tamer Higazi th9...@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@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 ___ Zope maillist - Zope@zope.org https://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - https://mail.zope.org/mailman/listinfo/zope-announce https://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] local and global site manager, adapter and utility questions
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@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 ?! Tamer Am 14.05.2013 09:22, schrieb Thierry Florac: Hi, Le Tue, 14 May 2013 06:55:38 +0200, Tamer Higazi th9...@googlemail.com a écrit: 1. What is the difference between a global and a localSiteManager from the zope.component package?! How do I have to understand that a globalSiteManager resists in memory, and a localSiteManager is persistent ?! Could somebody of you explain it to me?! Yes, there are two kinds of complementary registries (or site managers): - a global one, mainly build by ZCML (or static) declarations - a local one, which is made of persistent components registered into the ZODB. Local components are contextual, so are only available (by default) to objects attached to the site manager inside which these components are defined. This registry is mainly specific to Zope applications so if you build a ZCA-based application outside of Zope, you will probably don't have a local registry. Where you are looking for a component, search is made at first in the local registry, then in the global one. 2. What is the difference between an adapter and a utility ?! I register an adapter as well the same way as I do with a utility, and I query those 2 as well. But what's the point there?! A utility is a simple named component which provides an interface; it's generally a singleton. An adapter, on the opposite, takes one or more objects arguments (each providing a given interface) to return an object providing another interface. Regards, Thierry P.S.: please avoid cross-posts! ___ Zope maillist - Zope@zope.org https://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - https://mail.zope.org/mailman/listinfo/zope-announce https://mail.zope.org/mailman/listinfo/zope-dev )
[Zope] local and global site manager, adapter and utility questions
Hi people! I have worked out so far the ZCA tutorial, and there are certain things for me not clear. 1. What is the difference between a global and a localSiteManager from the zope.component package?! How do I have to understand that a globalSiteManager resists in memory, and a localSiteManager is persistent ?! Could somebody of you explain it to me?! 2. What is the difference between an adapter and a utility ?! I register an adapter as well the same way as I do with a utility, and I query those 2 as well. But what's the point there?! For answering my questions, I would kindly thank you. Tamer ___ Zope maillist - Zope@zope.org https://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - https://mail.zope.org/mailman/listinfo/zope-announce https://mail.zope.org/mailman/listinfo/zope-dev )