Commit a5cb5954 authored by Romain Courteaud's avatar Romain Courteaud

Import locals constraints.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@5118 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 4413cb25
......@@ -157,17 +157,21 @@ def initializePortalTypeDynamicProperties(self, klass, ptype):
parent_object = self.aq_parent
parent_klass = parent_object.__class__
parent_type = parent_object.portal_type
if getattr(parent_klass, 'isRADContent', 0) and (ptype != parent_type or klass != parent_klass) \
and not Base.aq_portal_type.has_key(parent_type):
initializePortalTypeDynamicProperties(parent_object, parent_klass, parent_type)
if getattr(parent_klass, 'isRADContent', 0) and \
(ptype != parent_type or klass != parent_klass) and \
not Base.aq_portal_type.has_key(parent_type):
initializePortalTypeDynamicProperties(parent_object, parent_klass,
parent_type)
# Initiatise portal_type properties (XXX)
ptype_object = getattr(aq_base(self.portal_types), ptype, None)
cat_list = []
prop_list = []
constraint_list = []
if ptype_object is not None and ptype_object.meta_type == 'ERP5 Type Information':
if (ptype_object is not None) and \
(ptype_object.meta_type == 'ERP5 Type Information'):
# Make sure this is an ERP5Type object
ps_list = map(lambda p: getattr(PropertySheet, p, None), ptype_object.property_sheet_list)
ps_list = map(lambda p: getattr(PropertySheet, p, None),
ptype_object.property_sheet_list)
ps_list = filter(lambda p: p is not None, ps_list)
# Always append the klass.property_sheets to this list (for compatibility)
# Because of the order we generate accessors, it is still possible
......@@ -177,23 +181,23 @@ def initializePortalTypeDynamicProperties(self, klass, ptype):
else:
ps_list = getClassPropertyList(klass)
for base in ps_list:
if hasattr(base, '_properties'):
if type(base._properties) in (type(()), type([])):
prop_list += base._properties
property_sheet_definition_dict = {
'_properties': prop_list,
'_categories': cat_list,
'_constraints': constraint_list
}
for ps_property_name, current_list in \
property_sheet_definition_dict.items():
if hasattr(base, ps_property_name):
ps_property = getattr(base, ps_property_name)
if type(ps_property) in (type(()), type([])):
current_list += ps_property
else :
raise ValueError, "_properties is not a list for %s" % base
if hasattr(base, '_categories'):
if type(base._categories) in (type(()), type([])):
cat_list += base._categories
else:
cat_list += [base._categories]
if hasattr(base, '_constraints'):
if type(base._constraints) in (type(()), type([])):
constraint_list += base._constraints
else :
raise ValueError, "_constraints is not a list for %s" % base
raise ValueError, "%s is not a list for %s" % (ps_property_name,
base)
if ptype_object is not None and ptype_object.meta_type == 'ERP5 Type Information':
if (ptype_object is not None) and \
(ptype_object.meta_type == 'ERP5 Type Information'):
cat_list += ptype_object.base_category_list
prop_holder._properties = prop_list
prop_holder._categories = cat_list
......
......@@ -705,10 +705,14 @@ def importLocalDocument(class_id, document_path = None):
m[name].append(method)
m[name+'__roles__']=pr
def initializeLocalDocumentRegistry():
def initializeLocalRegistry(directory_name, import_local_method,
path_arg_name='path'):
"""
Initialize local directory.
"""
if not getConfiguration: return
instance_home = getConfiguration().instancehome
document_path = os.path.join(instance_home, "Document")
document_path = os.path.join(instance_home, directory_name)
python_file_expr = re.compile("py$")
# For unit testing.
if os.access(document_path, os.F_OK):
......@@ -720,34 +724,24 @@ def initializeLocalDocumentRegistry():
if python_file_expr.search(file_name,1):
module_name = file_name[0:-3]
try:
importLocalDocument(module_name, document_path = document_path)
LOG('Added local document to ERP5Type repository: %s (%s)'
% (module_name, document_path), 0, '')
# XXX Arg are not consistent
import_local_method(module_name, **{path_arg_name: document_path})
LOG('Added local %s to ERP5Type repository: %s (%s)'
% (directory_name, module_name, document_path), 0, '')
except Exception, e:
LOG('Failed to add local document to ERP5Type repository: %s (%s)'
% (module_name, document_path), PROBLEM, '', e)
LOG('Failed to add local %s to ERP5Type repository: %s (%s)'
% (directory_name, module_name, document_path), PROBLEM, '', e)
def initializeLocalDocumentRegistry():
# XXX Arg are not consistent
initializeLocalRegistry("Document", importLocalDocument,
path_arg_name='document_path')
def initializeLocalPropertySheetRegistry():
if not getConfiguration: return
instance_home = getConfiguration().instancehome
document_path = os.path.join(instance_home, "PropertySheet")
python_file_expr = re.compile("py$")
# For unit testing.
if os.access(document_path, os.F_OK):
file_list = os.listdir(document_path)
else:
file_list = ()
for file_name in file_list:
if file_name != '__init__.py':
if python_file_expr.search(file_name,1):
module_name = file_name[0:-3]
try:
importLocalPropertySheet(module_name, path = document_path)
LOG('Added local property sheet to ERP5Type repository: %s (%s)'
% (module_name, document_path), 0, '')
except Exception, e:
LOG('Failed to add local property sheet to ERP5Type repository: %s (%s)'
% (module_name, document_path), PROBLEM, '', e)
initializeLocalRegistry("PropertySheet", importLocalPropertySheet)
def initializeLocalConstraintRegistry():
initializeLocalRegistry("Constraint", importLocalConstraint)
#####################################################
# Product initialization
......@@ -879,7 +873,12 @@ def createConstraintList(property_holder, constraint_definition):
constraint_definition -- the constraint with all attributes
"""
consistency_class = getattr(Constraint, constraint_definition['type'])
try:
consistency_class = getattr(Constraint, constraint_definition['type'])
except AttributeError:
LOG("ERP5Type", 0, "Can not find Constraint: %s" % \
constraint_definition['type'])
raise
consistency_instance = consistency_class(**constraint_definition)
property_holder.constraints += [consistency_instance]
......@@ -1033,6 +1032,7 @@ def setDefaultProperties(property_holder, object=None):
else:
new_cat_list.append(cat)
cat_list = new_cat_list
for const in constraint_list:
for key,value in const.items():
if isinstance(value, Expression):
......@@ -1127,6 +1127,7 @@ def setDefaultProperties(property_holder, object=None):
# Create the constraint method list - always check type
property_holder.constraints = [ Constraint.PropertyTypeValidity(id='type_check',
description="Type Validity Check Error") ]
for const in constraint_list:
createConstraintList(property_holder, constraint_definition=const)
# ERP5 _properties and Zope _properties are somehow different
......
......@@ -73,6 +73,9 @@ def initialize( context ):
# We should register product classes at some point
from Products.ERP5Type.InitGenerator import initializeProductDocumentRegistry
initializeProductDocumentRegistry()
# We should register local constraints at some point
from Products.ERP5Type.Utils import initializeLocalConstraintRegistry
initializeLocalConstraintRegistry()
# We should register local property sheets at some point
from Products.ERP5Type.Utils import initializeLocalPropertySheetRegistry
initializeLocalPropertySheetRegistry()
......
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