Commit 375a1bc0 authored by Nicolas Delaby's avatar Nicolas Delaby

* Clean createRelatedValueAccessors:

   remove write_permission parameter which is not used
   factorise code
* Use property_holder to generate related Value Accessors if available


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@28112 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 3f88c393
...@@ -885,7 +885,7 @@ class Base( CopyContainer, ...@@ -885,7 +885,7 @@ class Base( CopyContainer,
accessor = property_holder.createAccessor(id) accessor = property_holder.createAccessor(id)
return accessor return accessor
except KeyError: except KeyError:
pass property_holder = None
if id in ('portal_types', 'portal_url', 'portal_workflow'): if id in ('portal_types', 'portal_url', 'portal_workflow'):
# This is required to precent infinite loop (we need to access portal_types tool) # This is required to precent infinite loop (we need to access portal_types tool)
...@@ -942,12 +942,12 @@ class Base( CopyContainer, ...@@ -942,12 +942,12 @@ class Base( CopyContainer,
for bid in base_category_list: for bid in base_category_list:
if bid not in generated_bid: if bid not in generated_bid:
#LOG( "Create createRelatedValueAccessors %s" % bid,0,'') #LOG( "Create createRelatedValueAccessors %s" % bid,0,'')
createRelatedValueAccessors(bid) createRelatedValueAccessors(property_holder, bid)
generated_bid[bid] = 1 generated_bid[bid] = 1
for ptype in portal_types.objectValues('ERP5 Type Information') : for ptype in portal_types.objectValues('ERP5 Type Information') :
for bid in ptype.base_category_list : for bid in ptype.base_category_list :
if bid not in generated_bid : if bid not in generated_bid :
createRelatedValueAccessors(bid) createRelatedValueAccessors(property_holder, bid)
generated_bid[bid] = 1 generated_bid[bid] = 1
Base.aq_related_generated = 1 Base.aq_related_generated = 1
......
...@@ -1400,8 +1400,7 @@ def setDefaultProperties(property_holder, object=None, portal=None): ...@@ -1400,8 +1400,7 @@ def setDefaultProperties(property_holder, object=None, portal=None):
read_permission = Permissions.AccessContentsInformation read_permission = Permissions.AccessContentsInformation
write_permission = Permissions.ModifyPortalContent write_permission = Permissions.ModifyPortalContent
# Actualy create accessors # Actualy create accessors
createRelatedValueAccessors(cat, read_permission=read_permission, createRelatedValueAccessors(property_holder, cat, read_permission=read_permission)
write_permission=write_permission)
# Unnecessary to create these accessors more than once. # Unnecessary to create these accessors more than once.
base_category_dict.clear() base_category_dict.clear()
# Create the constraint method list - always check type # Create the constraint method list - always check type
...@@ -1437,7 +1436,7 @@ def setDefaultProperties(property_holder, object=None, portal=None): ...@@ -1437,7 +1436,7 @@ def setDefaultProperties(property_holder, object=None, portal=None):
# allows to create the equivalent of NULL values # allows to create the equivalent of NULL values
# - new - XXX # - new - XXX
# We remove such properties here # We remove such properties here
from Base import Base as BaseClass #from Base import Base as BaseClass
for prop in converted_prop_list: for prop in converted_prop_list:
if prop['type'] in legalTypes: if prop['type'] in legalTypes:
#if not hasattr(property_holder, prop['id']): #if not hasattr(property_holder, prop['id']):
...@@ -2417,8 +2416,7 @@ def createValueAccessors(property_holder, id, ...@@ -2417,8 +2416,7 @@ def createValueAccessors(property_holder, id,
property_holder.registerAccessor(setter_name, id, Value.UidSetSetter, accessor_args) property_holder.registerAccessor(setter_name, id, Value.UidSetSetter, accessor_args)
def createRelatedValueAccessors(id, read_permission=Permissions.AccessContentsInformation, def createRelatedValueAccessors(property_holder, id, read_permission=Permissions.AccessContentsInformation):
write_permission=Permissions.ModifyPortalContent):
upper_case_id = UpperCase(id) upper_case_id = UpperCase(id)
# Related Values (ie. reverse relation getters) # Related Values (ie. reverse relation getters)
...@@ -2530,26 +2528,21 @@ def createRelatedValueAccessors(id, read_permission=Permissions.AccessContentsIn ...@@ -2530,26 +2528,21 @@ def createRelatedValueAccessors(id, read_permission=Permissions.AccessContentsIn
), ),
} }
permission = read_permission
for accessor_class, accessor_name_list in accessor_dict.items(): for accessor_class, accessor_name_list in accessor_dict.items():
for accessor_name in accessor_name_list:
# First element is the original accessor if property_holder is not None:
accessor_name = accessor_name_list[0] if not hasattr(property_holder, accessor_name):
accessor = accessor_class(accessor_name, id) property_holder.registerAccessor(accessor_name, id, accessor_class, ())
if not hasattr(BaseClass, accessor_name):
setattr(BaseClass, accessor_name, accessor)
# Declare the security of method which doesn't start with _
if accessor_name[0] != '_': if accessor_name[0] != '_':
BaseClass.security.declareProtected(permission, accessor_name) property_holder.declareProtected(read_permission, accessor_name)
else:
# Others are dummy copies accessor = accessor_class(accessor_name, id)
for accessor_name in accessor_name_list[1:]:
if not hasattr(BaseClass, accessor_name): if not hasattr(BaseClass, accessor_name):
setattr(BaseClass, accessor_name, setattr(BaseClass, accessor_name,
accessor.dummy_copy(accessor_name)) accessor.dummy_copy(accessor_name))
# Declare the security of method which doesn't start with _ # Declare the security of method which doesn't start with _
if accessor_name[0] != '_': if accessor_name[0] != '_':
BaseClass.security.declareProtected(permission, accessor_name) BaseClass.security.declareProtected(read_permission, accessor_name)
def createTranslationAccessors(property_holder, id, def createTranslationAccessors(property_holder, id,
read_permission=Permissions.AccessContentsInformation, read_permission=Permissions.AccessContentsInformation,
......
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