Commit d20df843 authored by Yoshinori Okuji's avatar Yoshinori Okuji

Make it sure to generate dynamic methods in an ERP5 Site.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@20889 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent ba5488f9
...@@ -526,10 +526,10 @@ def initializeClassDynamicProperties(self, klass): ...@@ -526,10 +526,10 @@ def initializeClassDynamicProperties(self, klass):
# Mark as generated # Mark as generated
Base.aq_method_generated[klass] = 1 Base.aq_method_generated[klass] = 1
def initializePortalTypeDynamicProperties(self, klass, ptype, aq_key): def initializePortalTypeDynamicProperties(self, klass, ptype, aq_key, portal):
## Init CachingMethod which implements caching for ERP5 ## Init CachingMethod which implements caching for ERP5
from Products.ERP5Type.Cache import initializePortalCachingProperties from Products.ERP5Type.Cache import initializePortalCachingProperties
initializePortalCachingProperties(self) initializePortalCachingProperties(portal)
id = '' id = ''
#LOG('before aq_portal_type %s' % id, 0, str(ptype)) #LOG('before aq_portal_type %s' % id, 0, str(ptype))
...@@ -544,9 +544,10 @@ def initializePortalTypeDynamicProperties(self, klass, ptype, aq_key): ...@@ -544,9 +544,10 @@ def initializePortalTypeDynamicProperties(self, klass, ptype, aq_key):
(ptype != parent_type or klass != parent_klass) and \ (ptype != parent_type or klass != parent_klass) and \
not Base.aq_portal_type.has_key(parent_type): not Base.aq_portal_type.has_key(parent_type):
initializePortalTypeDynamicProperties(parent_object, parent_klass, initializePortalTypeDynamicProperties(parent_object, parent_klass,
parent_type, parent_object._aq_key()) parent_type,
parent_object._aq_key(), portal)
# Initiatise portal_type properties (XXX) # Initiatise portal_type properties (XXX)
ptype_object = getattr(aq_base(self.portal_types), ptype, None) ptype_object = getattr(aq_base(portal.portal_types), ptype, None)
prop_list = list(getattr(klass, '_properties', [])) prop_list = list(getattr(klass, '_properties', []))
cat_list = list(getattr(klass, '_categories', [])) cat_list = list(getattr(klass, '_categories', []))
constraint_list = list(getattr(klass, '_constraints', [])) constraint_list = list(getattr(klass, '_constraints', []))
...@@ -588,10 +589,10 @@ def initializePortalTypeDynamicProperties(self, klass, ptype, aq_key): ...@@ -588,10 +589,10 @@ def initializePortalTypeDynamicProperties(self, klass, ptype, aq_key):
prop_holder._constraints = constraint_list prop_holder._constraints = constraint_list
from Utils import setDefaultClassProperties, setDefaultProperties from Utils import setDefaultClassProperties, setDefaultProperties
setDefaultClassProperties(prop_holder) setDefaultClassProperties(prop_holder)
setDefaultProperties(prop_holder, object=self) setDefaultProperties(prop_holder, object=self, portal=portal)
#LOG('initializeDefaultProperties: %s' % ptype, 0, str(prop_holder.__dict__)) #LOG('initializeDefaultProperties: %s' % ptype, 0, str(prop_holder.__dict__))
# initializePortalTypeDynamicWorkflowMethods(self, initializePortalTypeDynamicWorkflowMethods(self, klass, ptype, prop_holder,
initializePortalTypeDynamicWorkflowMethods(self, klass, ptype, prop_holder) portal)
# We can now associate it after initialising security # We can now associate it after initialising security
InitializeClass(prop_holder) InitializeClass(prop_holder)
prop_holder.__propholder__ = prop_holder prop_holder.__propholder__ = prop_holder
...@@ -600,7 +601,8 @@ def initializePortalTypeDynamicProperties(self, klass, ptype, aq_key): ...@@ -600,7 +601,8 @@ def initializePortalTypeDynamicProperties(self, klass, ptype, aq_key):
#klass.__ac_permissions__ = prop_holder.__ac_permissions__ #klass.__ac_permissions__ = prop_holder.__ac_permissions__
Base.aq_portal_type[aq_key] = prop_holder Base.aq_portal_type[aq_key] = prop_holder
def initializePortalTypeDynamicWorkflowMethods(self, klass, ptype, prop_holder): def initializePortalTypeDynamicWorkflowMethods(self, klass, ptype, prop_holder,
portal):
"""We should now make sure workflow methods are defined """We should now make sure workflow methods are defined
and also make sure simulation state is defined.""" and also make sure simulation state is defined."""
# aq_inner is required to prevent extra name lookups from happening # aq_inner is required to prevent extra name lookups from happening
...@@ -608,7 +610,7 @@ def initializePortalTypeDynamicWorkflowMethods(self, klass, ptype, prop_holder): ...@@ -608,7 +610,7 @@ def initializePortalTypeDynamicWorkflowMethods(self, klass, ptype, prop_holder):
# wrapper contains an object with _aq_dynamic defined, the workflow id # wrapper contains an object with _aq_dynamic defined, the workflow id
# is looked up with _aq_dynamic, thus causes infinite recursions. # is looked up with _aq_dynamic, thus causes infinite recursions.
portal_workflow = aq_inner(getToolByName(self, 'portal_workflow')) portal_workflow = aq_inner(getToolByName(portal, 'portal_workflow'))
for wf in portal_workflow.getWorkflowsFor(self): for wf in portal_workflow.getWorkflowsFor(self):
if wf.__class__.__name__ in ('DCWorkflowDefinition', ): if wf.__class__.__name__ in ('DCWorkflowDefinition', ):
wf_id = wf.id wf_id = wf.id
...@@ -877,22 +879,27 @@ class Base( CopyContainer, ...@@ -877,22 +879,27 @@ class Base( CopyContainer,
initializeClassDynamicProperties(self, klass) initializeClassDynamicProperties(self, klass)
generated = 1 generated = 1
# Iterate until an ERP5 Site is obtained.
portal = self.getPortalObject()
while portal.portal_type != 'ERP5 Site':
portal = portal.aq_parent.aq_inner.getPortalObject()
# Generate portal_type methods # Generate portal_type methods
if not Base.aq_portal_type.has_key(aq_key): if not Base.aq_portal_type.has_key(aq_key):
if ptype == 'Preference': if ptype == 'Preference':
# XXX-JPS this should be moved to Preference class # XXX-JPS this should be moved to Preference class
from Products.ERP5Form.PreferenceTool import updatePreferenceClassPropertySheetList from Products.ERP5Form.PreferenceTool import updatePreferenceClassPropertySheetList
updatePreferenceClassPropertySheetList() updatePreferenceClassPropertySheetList()
initializePortalTypeDynamicProperties(self, klass, ptype, aq_key) initializePortalTypeDynamicProperties(self, klass, ptype, aq_key, portal)
generated = 1 generated = 1
# Generate Related Accessors # Generate Related Accessors
if not Base.aq_related_generated: if not Base.aq_related_generated:
from Utils import createRelatedValueAccessors from Utils import createRelatedValueAccessors
generated = 1 generated = 1
portal_types = getToolByName(self, 'portal_types', None) portal_types = getToolByName(portal, 'portal_types', None)
generated_bid = {} generated_bid = {}
econtext = createExpressionContext(self.getPortalObject()) econtext = createExpressionContext(object=self, portal=portal)
for pid, ps in PropertySheet.__dict__.items(): for pid, ps in PropertySheet.__dict__.items():
if pid[0] != '_': if pid[0] != '_':
base_category_list = [] base_category_list = []
...@@ -925,7 +932,7 @@ class Base( CopyContainer, ...@@ -925,7 +932,7 @@ class Base( CopyContainer,
from Products.ERP5Form.PreferenceTool import createPreferenceToolAccessorList from Products.ERP5Form.PreferenceTool import createPreferenceToolAccessorList
from Products.ERP5Form.PreferenceTool import updatePreferenceClassPropertySheetList from Products.ERP5Form.PreferenceTool import updatePreferenceClassPropertySheetList
updatePreferenceClassPropertySheetList() updatePreferenceClassPropertySheetList()
createPreferenceToolAccessorList(self.getPortalObject()) createPreferenceToolAccessorList(portal)
except ImportError, e : except ImportError, e :
LOG('Base._aq_dynamic', WARNING, LOG('Base._aq_dynamic', WARNING,
'unable to create methods for PreferenceTool', e) 'unable to create methods for PreferenceTool', e)
......
...@@ -999,16 +999,11 @@ def setDefaultConstructor(klass): ...@@ -999,16 +999,11 @@ def setDefaultConstructor(klass):
document_constructor.__name__ = document_constructor_name document_constructor.__name__ = document_constructor_name
def createExpressionContext(object): def createExpressionContext(object, portal):
""" """
Return a context used for evaluating a TALES expression. Return a context used for evaluating a TALES expression.
""" """
if object is not None: if object is None or getattr(object, 'aq_base', None) is None:
portal = object.getPortalObject()
else:
portal = None
if object is None or not hasattr(object, 'aq_base'):
folder = portal folder = portal
else: else:
folder = object folder = object
...@@ -1059,7 +1054,7 @@ def createExpressionContext(object): ...@@ -1059,7 +1054,7 @@ def createExpressionContext(object):
} }
return getEngine().getContext(data) return getEngine().getContext(data)
def setDefaultProperties(property_holder, object=None): def setDefaultProperties(property_holder, object=None, portal=None):
""" """
This methods sets default accessors for this object as well This methods sets default accessors for this object as well
as consistency checkers, based on the definition as consistency checkers, based on the definition
...@@ -1083,7 +1078,7 @@ def setDefaultProperties(property_holder, object=None): ...@@ -1083,7 +1078,7 @@ def setDefaultProperties(property_holder, object=None):
Set default attributes in current object for all properties in '_properties' Set default attributes in current object for all properties in '_properties'
""" """
econtext = createExpressionContext(object) econtext = createExpressionContext(object, portal)
legalTypes = type_definition.keys() legalTypes = type_definition.keys()
# First build the property list from the property sheet # First build the property list from the property sheet
# and the class properties # and the class properties
...@@ -1236,8 +1231,8 @@ def setDefaultProperties(property_holder, object=None): ...@@ -1236,8 +1231,8 @@ def setDefaultProperties(property_holder, object=None):
write_permission=Permissions.ModifyPortalContent) write_permission=Permissions.ModifyPortalContent)
# Get read and write permission # Get read and write permission
if object is not None: if portal is not None:
cat_object = object.getPortalObject().portal_categories.get(cat, None) cat_object = portal.portal_categories.get(cat, None)
else: else:
cat_object = None cat_object = None
if cat_object is not None: if cat_object is not None:
...@@ -1273,8 +1268,8 @@ def setDefaultProperties(property_holder, object=None): ...@@ -1273,8 +1268,8 @@ def setDefaultProperties(property_holder, object=None):
base_category_list.append(cat) base_category_list.append(cat)
for cat in base_category_list: for cat in base_category_list:
# Get read and write permission # Get read and write permission
if object is not None: if portal is not None:
cat_object = object.getPortalObject().portal_categories.get(cat, None) cat_object = portal.portal_categories.get(cat, None)
else: else:
cat_object = None cat_object = None
if cat_object is not None: if cat_object is not None:
......
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