Re: [Zope3-dev] How to provide some default utilities for sub-site

2005-11-04 Thread Dominik Huber

Hi Adam
You need location information (- __parent__) for this setup. Regularly 
the object knows that information not until its addition to a container. 
Subscribe to ObjectAdded event and do the same setup within the handler 
and it will work.


Regards,
Dominik

Adam Groszer wrote:


I'd like to provide some default utilities for my sub-site.
As I checked there is the nice ensureUtility method but as it turns
out it failes with

...
 Module szscreen.app, line 339, in __init__
   'WorkflowUtility', WorkflowUtility, 'wfu')
 Module zope.app.appsetup.bootstrap, line 66, in ensureUtility
   name, **kw
 Module zope.app.appsetup.bootstrap, line 74, in addConfigureUtility
   utility_name = addUtility(root_folder, utility_type, utility_factory, **kw)
 Module zope.app.appsetup.bootstrap, line 83, in addUtility
   package = getSiteManagerDefault(root_folder)
 Module zope.app.appsetup.bootstrap, line 105, in getSiteManagerDefault
   package = traverse(root_folder, package_name)
 Module zope.app.traversing.api, line 96, in traverse
   return traverser.traverse(path, request=request)
 Module zope.app.traversing.adapters, line 120, in traverse
   curr = IPhysicallyLocatable(self.context).getRoot()
 Module zope.app.location.traversing, line 90, in getRoot
   raise TypeError(Not enough context to determine location root)
TypeError: Not enough context to determine location root

when it checks the existence of the utility it uses
 sm = root_folder.getSiteManager()
but when it wants to add the non existing utility
 package = getSiteManagerDefault(root_folder)
which in turn wants to traverse like this
 package_name = '/++etc++site/default'
 package = traverse(root_folder, package_name)

Is there any way to easily solve the task?

Excerpt from szscreen.app:

class IApplication(IReadContainer, IPossibleSite, IAttributeAnnotatable):
 

class Application(Persistent, SampleContainer, SiteManagerContainer):

   implements(IApplication)
   
   def __init__(self):

   SampleContainer.__init__(self)
   
   sm = LocalSiteManager(self)

   self.setSiteManager(sm)

   ...
   
   ensureUtility(self, IWorkflowUtility,

   'WorkflowUtility', WorkflowUtility, 'wfu')

 




--
Dominik Huber

Perse Engineering GmbH
Jurastrasse 9a
CH-5406 Baden
 
E-Mail: [EMAIL PROTECTED]

Telefon: ++41 56 534 7730

begin:vcard
fn:Dominik Huber
n:Huber;Dominik
email;internet:[EMAIL PROTECTED]
tel;work:++41 56 534 77 30
x-mozilla-html:FALSE
version:2.1
end:vcard

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



Re[2]: [Zope3-dev] How to provide some default utilities for sub-site

2005-11-04 Thread Adam Groszer
Hello Dominik,

I tried it using a subscriber.

  subscriber
  handler=.app.App_boot
  for=zope.app.container.interfaces.IObjectAddedEvent
  /

def App_boot(event):
# precondition
obj = event.object
if not IApplication.providedBy(obj):
return

ensureUtility(obj, IWorkflowProcessRepository, 
'WorkflowProcessRepository', WorkflowProcessRepository, 
'')
ensureUtility(obj, IWorkflowUtility, 
'WorkflowUtility', WorkflowUtility, 'wfu')  

It works, but it adds the utilities to the global site manager :-(
If the behavior is OK this way, then why do I have to pass the
root_folder? I don't really get it.

If I start to go my own way and copy+modify the
zope.app.appsetup.bootstrap.py:

def getSiteManagerDefault(root_folder):
sm = root_folder.getSiteManager()
#default = zapi.traverse(folder.getSiteManager(), 'default')
#package_name = '/++etc++site/default'
#package = traverse(root_folder, package_name)
package_name = 'default'
package = traverse(sm, package_name)
return package

then it is working. The 2 utilities land in the local site manager.

Friday, November 4, 2005, 12:48:57 PM, you wrote:

 Hi Adam
 You need location information (- __parent__) for this setup. Regularly
 the object knows that information not until its addition to a container.
 Subscribe to ObjectAdded event and do the same setup within the handler
 and it will work.

 Regards,
 Dominik

 Adam Groszer wrote:

I'd like to provide some default utilities for my sub-site.
As I checked there is the nice ensureUtility method but as it turns
out it failes with

...
  Module szscreen.app, line 339, in __init__
'WorkflowUtility', WorkflowUtility, 'wfu')
  Module zope.app.appsetup.bootstrap, line 66, in ensureUtility
name, **kw
  Module zope.app.appsetup.bootstrap, line 74, in addConfigureUtility
utility_name = addUtility(root_folder, utility_type, utility_factory, 
 **kw)
  Module zope.app.appsetup.bootstrap, line 83, in addUtility
package = getSiteManagerDefault(root_folder)
  Module zope.app.appsetup.bootstrap, line 105, in getSiteManagerDefault
package = traverse(root_folder, package_name)
  Module zope.app.traversing.api, line 96, in traverse
return traverser.traverse(path, request=request)
  Module zope.app.traversing.adapters, line 120, in traverse
curr = IPhysicallyLocatable(self.context).getRoot()
  Module zope.app.location.traversing, line 90, in getRoot
raise TypeError(Not enough context to determine location root)
TypeError: Not enough context to determine location root

when it checks the existence of the utility it uses
  sm = root_folder.getSiteManager()
but when it wants to add the non existing utility
  package = getSiteManagerDefault(root_folder)
which in turn wants to traverse like this
  package_name = '/++etc++site/default'
  package = traverse(root_folder, package_name)

Is there any way to easily solve the task?

Excerpt from szscreen.app:

class IApplication(IReadContainer, IPossibleSite, IAttributeAnnotatable):
  

class Application(Persistent, SampleContainer, SiteManagerContainer):

implements(IApplication)

def __init__(self):
SampleContainer.__init__(self)

sm = LocalSiteManager(self)
self.setSiteManager(sm)

...

ensureUtility(self, IWorkflowUtility,
'WorkflowUtility', WorkflowUtility, 'wfu')

  






-- 
Best regards,
 Adammailto:[EMAIL PROTECTED]
--
Quote of the day:
Destiny is not a matter of chance; it is a matter of choice.  It is not 
something to be waited for; but, rather something to be achieved. (William 
Jennings Bryan)

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



Re: [Zope3-dev] How to provide some default utilities for sub-site

2005-11-04 Thread Dominik Huber

Hi Adam

First you have to assert that you object (obj) provides ISite. Then I 
would use the following attachted helper function `addLocalUtility` to 
add the your utiltiy. Least,  you could use multi-subscriber for events 
providing IObjectEvent, then you don't have to check for IApplication. 
Putting all together you get the following (unproved) registration and code:


 subscriber
 handler=.app.App_boot
 for=.IApplication zope.app.container.interfaces.IObjectAddedEvent
 /

def App_boot(obj, event):
   if not ISite.providedBy(obj): 
  helper.addSiteManager(obj)


   helper.addLocalUtility(obj, 'wfu', 'WorkflowUtility', WorkflowUtility())

Regards,
Dominik

Adam Groszer wrote:


Hello Dominik,

I tried it using a subscriber.

 subscriber
 handler=.app.App_boot
 for=zope.app.container.interfaces.IObjectAddedEvent
 /

def App_boot(event):
   # precondition
   obj = event.object
   if not IApplication.providedBy(obj):
   return
   
   ensureUtility(obj, IWorkflowProcessRepository, 
   'WorkflowProcessRepository', WorkflowProcessRepository, '')
   ensureUtility(obj, IWorkflowUtility, 
   'WorkflowUtility', WorkflowUtility, 'wfu')  


It works, but it adds the utilities to the global site manager :-(
If the behavior is OK this way, then why do I have to pass the
root_folder? I don't really get it.

If I start to go my own way and copy+modify the
zope.app.appsetup.bootstrap.py:

def getSiteManagerDefault(root_folder):
   sm = root_folder.getSiteManager()
   #default = zapi.traverse(folder.getSiteManager(), 'default')
   #package_name = '/++etc++site/default'
   #package = traverse(root_folder, package_name)
   package_name = 'default'
   package = traverse(sm, package_name)
   return package

then it is working. The 2 utilities land in the local site manager.

Friday, November 4, 2005, 12:48:57 PM, you wrote:

 


Hi Adam
You need location information (- __parent__) for this setup. Regularly
the object knows that information not until its addition to a container.
Subscribe to ObjectAdded event and do the same setup within the handler
and it will work.
   



 


Regards,
Dominik
   



 


Adam Groszer wrote:
   



 


I'd like to provide some default utilities for my sub-site.
As I checked there is the nice ensureUtility method but as it turns
out it failes with

...
Module szscreen.app, line 339, in __init__
  'WorkflowUtility', WorkflowUtility, 'wfu')
Module zope.app.appsetup.bootstrap, line 66, in ensureUtility
  name, **kw
Module zope.app.appsetup.bootstrap, line 74, in addConfigureUtility
  utility_name = addUtility(root_folder, utility_type, utility_factory, **kw)
Module zope.app.appsetup.bootstrap, line 83, in addUtility
  package = getSiteManagerDefault(root_folder)
Module zope.app.appsetup.bootstrap, line 105, in getSiteManagerDefault
  package = traverse(root_folder, package_name)
Module zope.app.traversing.api, line 96, in traverse
  return traverser.traverse(path, request=request)
Module zope.app.traversing.adapters, line 120, in traverse
  curr = IPhysicallyLocatable(self.context).getRoot()
Module zope.app.location.traversing, line 90, in getRoot
  raise TypeError(Not enough context to determine location root)
TypeError: Not enough context to determine location root

when it checks the existence of the utility it uses
sm = root_folder.getSiteManager()
but when it wants to add the non existing utility
package = getSiteManagerDefault(root_folder)
which in turn wants to traverse like this
package_name = '/++etc++site/default'
package = traverse(root_folder, package_name)

Is there any way to easily solve the task?

Excerpt from szscreen.app:

class IApplication(IReadContainer, IPossibleSite, IAttributeAnnotatable):


class Application(Persistent, SampleContainer, SiteManagerContainer):

  implements(IApplication)
  
  def __init__(self):

  SampleContainer.__init__(self)
  
  sm = LocalSiteManager(self)

  self.setSiteManager(sm)

  ...
  
  ensureUtility(self, IWorkflowUtility,

  'WorkflowUtility', WorkflowUtility, 'wfu')



 







 




--
Dominik Huber

Perse Engineering GmbH
Jurastrasse 9a
CH-5406 Baden
 
E-Mail: [EMAIL PROTECTED]

Telefon: ++41 56 534 7730

##
#
# Copyright (c) 2003, 2004, 2005 Projekt01 GmbH and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED AS IS AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#

Re[2]: [Zope3-dev] How to provide some default utilities for sub-site

2005-11-04 Thread Adam Groszer
Hello Dominik,

Great, it's working. Thanks.


Friday, November 4, 2005, 4:28:13 PM, you wrote:

DH Hi Adam

DH First you have to assert that you object (obj) provides ISite. Then I
DH would use the following attachted helper function `addLocalUtility` to
DH add the your utiltiy. Least,  you could use multi-subscriber for events
DH providing IObjectEvent, then you don't have to check for IApplication.
DH Putting all together you get the following (unproved) registration and code:

DH   subscriber
DH   handler=.app.App_boot
DH   for=.IApplication
DH zope.app.container.interfaces.IObjectAddedEvent
DH   /

DH def App_boot(obj, event):
DH if not ISite.providedBy(obj): 
DHhelper.addSiteManager(obj)

DH helper.addLocalUtility(obj, 'wfu', 'WorkflowUtility', WorkflowUtility())

DH Regards,
DH Dominik

DH Adam Groszer wrote:

Hello Dominik,

I tried it using a subscriber.

  subscriber
  handler=.app.App_boot
  for=zope.app.container.interfaces.IObjectAddedEvent
  /

def App_boot(event):
# precondition
obj = event.object
if not IApplication.providedBy(obj):
return

ensureUtility(obj, IWorkflowProcessRepository, 
'WorkflowProcessRepository', 
 WorkflowProcessRepository, '')
ensureUtility(obj, IWorkflowUtility, 
'WorkflowUtility', WorkflowUtility, 'wfu')

It works, but it adds the utilities to the global site manager :-(
If the behavior is OK this way, then why do I have to pass the
root_folder? I don't really get it.

If I start to go my own way and copy+modify the
zope.app.appsetup.bootstrap.py:

def getSiteManagerDefault(root_folder):
sm = root_folder.getSiteManager()
#default = zapi.traverse(folder.getSiteManager(), 'default')
#package_name = '/++etc++site/default'
#package = traverse(root_folder, package_name)
package_name = 'default'
package = traverse(sm, package_name)
return package

then it is working. The 2 utilities land in the local site manager.

Friday, November 4, 2005, 12:48:57 PM, you wrote:

  

Hi Adam
You need location information (- __parent__) for this setup. Regularly
the object knows that information not until its addition to a container.
Subscribe to ObjectAdded event and do the same setup within the handler
and it will work.



  

Regards,
Dominik



  

Adam Groszer wrote:



  

I'd like to provide some default utilities for my sub-site.
As I checked there is the nice ensureUtility method but as it turns
out it failes with

...
 Module szscreen.app, line 339, in __init__
   'WorkflowUtility', WorkflowUtility, 'wfu')
 Module zope.app.appsetup.bootstrap, line 66, in ensureUtility
   name, **kw
 Module zope.app.appsetup.bootstrap, line 74, in addConfigureUtility
   utility_name = addUtility(root_folder, utility_type, utility_factory, 
 **kw)
 Module zope.app.appsetup.bootstrap, line 83, in addUtility
   package = getSiteManagerDefault(root_folder)
 Module zope.app.appsetup.bootstrap, line 105, in getSiteManagerDefault
   package = traverse(root_folder, package_name)
 Module zope.app.traversing.api, line 96, in traverse
   return traverser.traverse(path, request=request)
 Module zope.app.traversing.adapters, line 120, in traverse
   curr = IPhysicallyLocatable(self.context).getRoot()
 Module zope.app.location.traversing, line 90, in getRoot
   raise TypeError(Not enough context to determine location root)
TypeError: Not enough context to determine location root

when it checks the existence of the utility it uses
 sm = root_folder.getSiteManager()
but when it wants to add the non existing utility
 package = getSiteManagerDefault(root_folder)
which in turn wants to traverse like this
 package_name = '/++etc++site/default'
 package = traverse(root_folder, package_name)

Is there any way to easily solve the task?

Excerpt from szscreen.app:

class IApplication(IReadContainer, IPossibleSite, IAttributeAnnotatable):
 

class Application(Persistent, SampleContainer, SiteManagerContainer):

   implements(IApplication)
   
   def __init__(self):
   SampleContainer.__init__(self)
   
   sm = LocalSiteManager(self)
   self.setSiteManager(sm)

   ...
   
   ensureUtility(self, IWorkflowUtility,
   'WorkflowUtility', WorkflowUtility, 'wfu')

 

  






  





-- 
Best regards,
 Groszer Adammailto:[EMAIL PROTECTED]
--
Quote of the day:
Here is a test to see if your mission on earth is finished. If you are alive, 
it isn't. 
- Francis Bacon 

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