[z3-five] local utility with zope 2.9.5

Dennis Schulz d.schulz81 at gmx.net
Tue Jan 16 10:40:29 CET 2007


Hi,

I would like (no I not really like, I have to) to register a local 
utility with zope 2.9.5 and Five 1.4.2.
(I know that it is more trouble than with the new zope version but I 
really have to finish something on the current Plone 2.5.)

I found the following example:

https://svn.openplans.org/svn/topp.rose/trunk/utility.py


I tried it out (see below code) and I get always the message 
"IPossibleSite" not provided.
Do I have to register the utility on my Application or on the Plone 
Site? Both of them do not provide IPossibleSite.
When I explicitly provide IPossibleSite 
(directlyProvides(app,IPossibleSite)) the call  sm = 
app.getSiteManager() raises an attribute error afterwards.....

Below there code of the registration is attached.
I call it in the Extensions/install.py of my archetype based product. 
Anything wrong with this?

Could anyone tell me if this is the right approach or point me to some 
other example?

Dennis





from ore.annotation import 
UtilityAnnotation,annotationAdapter,AnnotationUtility
from ore.annotation.interfaces import IAnnotationUtility,IUtilityAnnotatable
try:
    from OFS.Application import Application
    from OFS.SimpleItem import SimpleItem

    class OFSAnnotationUtility(SimpleItem, AnnotationUtility):
        """
        Zope2 friendly Util
        """
except ImportError:
    pass

def install(self):
   
    out = StringIO()
    installTypes(self, out, listTypes(PROJECTNAME), PROJECTNAME)
    install_subskin(self, out, GLOBALS)
    """
    add local utility in zope2
    """
    app = self
 
    print "before"
    print app
       
    from zope.app.component.interfaces import IPossibleSite
    from zope.interface import directlyProvides
    from Products.Five.site.localsite import enableLocalSiteHook
    findroot = True

    # from alecm's 'listen'
    if findroot:
        # find the zope application root
        app = aq_inner(app)
        while app is not None and not isinstance(app, Application):
          
            app = aq_parent(app)

    print "after"
    print app

    # If we have the zope Application and the utility is not yet
    # registered, then register it.
    if (app is not None and
        zapi.queryUtility(IAnnotationUtility, default=None) is None):
        enableLocalSiteHook(app)
        setSite(app)
        sm = app.getSiteManager()
        sm.registerUtility(IAnnotationUtility, AnnotationUtility(NAME))

    out.write("Successfully Yeah Yeah installed %s." % PROJECTNAME)
    return out.getvalue()










More information about the z3-five mailing list