Commit a581a35f authored by Rocky Burt's avatar Rocky Burt

No longer opens a zodb connection every time a ProductDispatcher is looked up,...

No longer opens a zodb connection every time a ProductDispatcher is looked up, forward ported from zope 2.10 branch r72990 and five 1.5 branch r72986.
parent ef0e48c2
......@@ -82,6 +82,9 @@ Zope Changes
Bugs Fixed
- No longer opens a zodb connection every time a ProductDispatcher
is looked up.
- PageTemplate/ZRPythonExpr.py: expressions represented as unicode string
caused UnicodeDecodeErrors.
......
......@@ -26,31 +26,14 @@ def _product_packages():
zope2 packages and those without the Products namespace package.
"""
old_product_packages = {}
packages = {}
for x in dir(Products):
m = getattr(Products, x)
if isinstance(m, types.ModuleType):
old_product_packages[x] = m
packages = {}
app = Zope2.app()
try:
products = app.Control_Panel.Products
for product_id in products.objectIds():
product = products[product_id]
if hasattr(product, 'package_name'):
pos = product.package_name.rfind('.')
if pos > -1:
packages[product_id] = __import__(product.package_name,
globals(), {},
product.package_name[pos+1:])
else:
packages[product_id] = __import__(product.package_name)
elif old_product_packages.has_key(product_id):
packages[product_id] = old_product_packages[product_id]
finally:
app._p_jar.close()
packages[x] = m
for m in getattr(Products, '_registered_packages', []):
packages[m.__name__] = m
return packages
......
......@@ -218,6 +218,11 @@ def _registerPackage(module_, init_func=None):
if init_func is not None:
newContext = ProductContext(product, app, module_)
init_func(newContext)
registered_packages = getattr(Products, '_registered_packages', None)
if registered_packages is None:
registered_packages = Products._registered_packages = []
registered_packages.append(module_)
finally:
try:
import transaction
......
......@@ -65,6 +65,10 @@ def test_registerPackage():
>>> 'pythonproduct2' in product_listing
True
Make sure it also shows up in ``Products._registered_packages``.
>>> [x.__name__ for x in getattr(Products, '_registered_packages', [])]
['pythonproduct2']
Clean up:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment