Commit 7bbfbff2 authored by Julien Muchembled's avatar Julien Muchembled

Forgot changes to products/ERP5Type/Utils.py in r39918

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@39922 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent dc8b16da
......@@ -589,23 +589,31 @@ def registerBaseCategories(property_sheet):
base_category_dict[bc] = 1
def importLocalInterface(module_id, path = None, is_erp5_type=False):
def provides(class_id):
# Create interface getter
accessor_name = 'provides' + class_id
setattr(BaseClass, accessor_name, lambda self: self.provides(class_id))
BaseClass.security.declarePublic(accessor_name)
class_id = "I" + convertToUpperCase(module_id)
if is_erp5_type:
provides(class_id)
else:
if path is None:
instance_home = getConfiguration().instancehome
path = os.path.join(instance_home, "interfaces")
path = os.path.join(path, "%s.py" % module_id)
f = open(path)
try:
class_id = "I" + convertToUpperCase(module_id)
if not is_erp5_type:
module = imp.load_source(class_id, path, f)
import Products.ERP5Type.interfaces
setattr(Products.ERP5Type.interfaces, class_id, getattr(module, class_id))
finally:
f.close()
# Create interface getter
accessor_name = 'provides' + class_id
setattr(BaseClass, accessor_name, lambda self: self.provides(class_id))
BaseClass.security.declarePublic(accessor_name)
from zope.interface import Interface
from Products.ERP5Type import interfaces
InterfaceClass = type(Interface)
for k, v in module.__dict__.iteritems():
if type(v) is InterfaceClass and v is not Interface:
setattr(interfaces, k, v)
provides(class_id)
def importLocalConstraint(class_id, path = None):
import Products.ERP5Type.Constraint
......@@ -935,8 +943,16 @@ def importLocalDocument(class_id, path=None, class_path=None):
module_path = "erp5.document"
class_path = "%s.%s" % (module_path, class_id)
module = imp.load_source(class_path, path)
klass = getattr(module, class_id, None)
# Tolerate that Document doesn't define any class, which can be useful
# if we only want to monkey patch.
# XXX A new 'Patch' folder should be introduced instead. Each module would
# define 2 methods: 'patch' and 'unpatch' (for proper upgrading).
if klass is None:
assert hasattr(module, 'patch')
return
import erp5.document
setattr(erp5.document, class_id, getattr(module, class_id))
setattr(erp5.document, class_id, klass)
document_class_registry[class_id] = class_path
### Migration
......
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