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): ...@@ -589,23 +589,31 @@ def registerBaseCategories(property_sheet):
base_category_dict[bc] = 1 base_category_dict[bc] = 1
def importLocalInterface(module_id, path = None, is_erp5_type=False): 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: if path is None:
instance_home = getConfiguration().instancehome instance_home = getConfiguration().instancehome
path = os.path.join(instance_home, "interfaces") path = os.path.join(instance_home, "interfaces")
path = os.path.join(path, "%s.py" % module_id) path = os.path.join(path, "%s.py" % module_id)
f = open(path) f = open(path)
try: try:
class_id = "I" + convertToUpperCase(module_id)
if not is_erp5_type:
module = imp.load_source(class_id, path, f) module = imp.load_source(class_id, path, f)
import Products.ERP5Type.interfaces
setattr(Products.ERP5Type.interfaces, class_id, getattr(module, class_id))
finally: finally:
f.close() f.close()
# Create interface getter from zope.interface import Interface
accessor_name = 'provides' + class_id from Products.ERP5Type import interfaces
setattr(BaseClass, accessor_name, lambda self: self.provides(class_id)) InterfaceClass = type(Interface)
BaseClass.security.declarePublic(accessor_name) 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): def importLocalConstraint(class_id, path = None):
import Products.ERP5Type.Constraint import Products.ERP5Type.Constraint
...@@ -935,8 +943,16 @@ def importLocalDocument(class_id, path=None, class_path=None): ...@@ -935,8 +943,16 @@ def importLocalDocument(class_id, path=None, class_path=None):
module_path = "erp5.document" module_path = "erp5.document"
class_path = "%s.%s" % (module_path, class_id) class_path = "%s.%s" % (module_path, class_id)
module = imp.load_source(class_path, path) 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 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 document_class_registry[class_id] = class_path
### Migration ### 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