В Пнд, 04.07.2005, в 11:27, Dominik Huber пишет:
>                                                                           
> Garanin Michael wrote:
> 
> >                                                                          
> >Hello!
> >My app setup code do follow step:
> >1) create simple AppSite (as ISite) in top
> >2) create local-utility object, 
> >for example PAU = PluggableAuthentication()
> >3) AppSite['PAU'] = PAU 
> >4) registration the PAU in AppSite/++etc++site/default.
> >
> >In other words: local-utility object location in top/mysite, but
> >registration in top/mysite/++etc++site/default.
> >Q: It's work, but is it legal?
> >Thanks!
> >  
> >
> IMO it makes sense that the default site folder is invoked if a local 
> utility is added to a site.
> 
> We use the following helper function for the local utility additon and 
> registration:
> 
> from zope.app import zapi
> from zope.app.container.interfaces import INameChooser
> from zope.app.component.interfaces.registration import ActiveStatus
> from zope.app.component.interfaces import ISite
> from zope.app.utility import UtilityRegistration
> 
> def addLocalUtility(site, name, iface, utility, package='default'):
>     """Add a utility to a site
> 
>     The utility is added to the package and activated.
>     This assumes the site has already a Utility Service.
>     """
>     # preconditions
>     if not ISite.providedBy(site):
>         raise TypeError('ISite required.')
> 
>     # get site manager and site management folder
>     sitemanager = site.getSiteManager()
>     default = sitemanager[package]
> 
>     # add utility to site management folder
>     chooser = INameChooser(default)
>     folder_name = chooser.chooseName(utility.__name__, utility)
>     default[folder_name] = utility
> 
>     # create service registration
>     path = zapi.getPath(utility)
>     registration = UtilityRegistration(name, iface, utility)
>     key = default.registrationManager.addRegistration(registration)
>     zapi.traverse(default.registrationManager, key).status = ActiveStatus 
> 
>     return zapi.traverse(sitemanager, path)
> 
> Regards,
> Dominik
> 
> 

Ok, but my setup code very like your code with little difference:
- your code: default[folder_name] = utility
- my code: site[folder_name] = utility  (my question: is it legal?)
As result i have url "MySite/PAU/USERS" instead
"MySite/++etc++site/default/PAU/USERS". And it is works.




 

_______________________________________________
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com

Reply via email to