Skip to content

Commit

Permalink
Hand Application object to Products through ProductContext
Browse files Browse the repository at this point in the history
Products receive the ProductContext as the first parameter
to their initialize() method when they are loaded. This context used to
contain a reference to the app until it was removed during Zope 4
preparations. The Application was, however, never exposed through an
API.

Access to the API is necessary for certain products that automatically
add objects to the Application when they are loaded, such as the
Products.Sessions and Products.TemporaryFolder. This used to happen in
OFS.Application in Zope 2, but was moved out when the products became
indepentent.
  • Loading branch information
rbu committed May 17, 2018
1 parent 016a3f1 commit bba6eee
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/App/ProductContext.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class ProductContext(object):

def __init__(self, product, app, package):
self.__prod = product
self.__app = app
self.__pack = package

def registerClass(self, instance_class=None, meta_type='',
Expand Down Expand Up @@ -213,6 +214,9 @@ class DummyHelp(object):
lastRegistered = None
return DummyHelp()

def getApplication(self):
return self.__app


class AttrDict(object):

Expand Down
6 changes: 3 additions & 3 deletions src/OFS/Application.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def install_root_view(self):
self.commit(u'Added default view for root object')

def install_products(self):
return install_products()
return install_products(self.getApp())

def install_standards(self):
app = self.getApp()
Expand Down Expand Up @@ -424,7 +424,7 @@ def install_product(app, product_dir, product_name, meta_types,
setattr(Application.misc_, product_name, misc_)

productObject = FactoryDispatcher.Product(product_name)
context = ProductContext(productObject, None, product)
context = ProductContext(productObject, app, product)

# Look for an 'initialize' method in the product.
initmethod = pgetattr(product, 'initialize', None)
Expand All @@ -439,7 +439,7 @@ def install_package(app, module, init_func, raise_exc=None):
product.package_name = name

if init_func is not None:
newContext = ProductContext(product, None, module)
newContext = ProductContext(product, app, module)
init_func(newContext)

package_initialized(module, init_func)
Expand Down

0 comments on commit bba6eee

Please sign in to comment.