Commit 8a11ed75 authored by Romain Courteaud's avatar Romain Courteaud

Rewrite createRelatedValueAccessors, in order to make it easier to read.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@13409 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 15551301
...@@ -331,8 +331,6 @@ class DocumentConstructor(Method): ...@@ -331,8 +331,6 @@ class DocumentConstructor(Method):
def __call__(self, folder, id, REQUEST=None, def __call__(self, folder, id, REQUEST=None,
activate_kw=None, is_indexable=None, **kw): activate_kw=None, is_indexable=None, **kw):
# o = self.klass(id, title=None)
# XXX Is it safe to set the title to None ?
o = self.klass(id) o = self.klass(id)
if activate_kw is not None: if activate_kw is not None:
o._v_activate_kw = activate_kw o._v_activate_kw = activate_kw
...@@ -1734,8 +1732,9 @@ def createDefaultAccessors(property_holder, id, prop = None, ...@@ -1734,8 +1732,9 @@ def createDefaultAccessors(property_holder, id, prop = None,
else: else:
# Create getters for a simple property # Create getters for a simple property
accessor_name = 'get' + UpperCase(id) accessor_name = 'get' + UpperCase(id)
accessor = Base.Getter(accessor_name, id, prop['type'], default = prop.get('default'), accessor = Base.Getter(accessor_name, id,
storage_id = prop.get('storage_id')) prop['type'], default=prop.get('default'),
storage_id = prop.get('storage_id'))
if not hasattr(property_holder, accessor_name) or prop.get('override',0): if not hasattr(property_holder, accessor_name) or prop.get('override',0):
setattr(property_holder, accessor_name, accessor) setattr(property_holder, accessor_name, accessor)
property_holder.security.declareProtected( read_permission, accessor_name ) property_holder.security.declareProtected( read_permission, accessor_name )
...@@ -2504,203 +2503,139 @@ def createRelatedValueAccessors(property_holder, id, ...@@ -2504,203 +2503,139 @@ def createRelatedValueAccessors(property_holder, id,
read_permission=Permissions.AccessContentsInformation, read_permission=Permissions.AccessContentsInformation,
write_permission=Permissions.ModifyPortalContent): write_permission=Permissions.ModifyPortalContent):
upper_case_id = UpperCase(id)
# Related Values (ie. reverse relation getters) # Related Values (ie. reverse relation getters)
# We are not generating here all the related stuff we need # We are not generating here all the related stuff we need
property_holder = BaseClass property_holder = BaseClass
accessor_name = UpperCase(id) + 'RelatedValues' # AccessorClass: (accessor_name, )
accessor_name = string.lower(accessor_name[0]) + accessor_name[1:] accessor_dict = {
accessor = RelatedValue.ListGetter(accessor_name, id) # List getter
if not hasattr(property_holder, accessor_name): RelatedValue.ListGetter: (
setattr(property_holder, accessor_name, accessor) '%s%sRelatedValues' % (upper_case_id[0].lower(),
property_holder.security.declareProtected(read_permission, accessor_name) upper_case_id[1:]),
accessor_name = 'get' + UpperCase(id) + 'RelatedValueList' 'get%sRelatedValueList' % upper_case_id,
if not hasattr(property_holder, accessor_name): '_categoryGet%sRelatedValueList' % upper_case_id,
setattr(property_holder, accessor_name, accessor.dummy_copy(accessor_name)) ),
property_holder.security.declareProtected(read_permission, accessor_name)
accessor_name = '_categoryGet' + UpperCase(id) + 'RelatedValueList' # Set getter
if not hasattr(property_holder, accessor_name): RelatedValue.SetGetter: (
setattr(property_holder, accessor_name, accessor.dummy_copy(accessor_name)) 'get%sRelatedValueSet' % upper_case_id,
'_categoryGet%sRelatedValueSet' % upper_case_id,
accessor_name = 'get' + UpperCase(id) + 'RelatedValueSet' ),
accessor = RelatedValue.SetGetter(accessor_name, id)
if not hasattr(property_holder, accessor_name): # Default value getter
setattr(property_holder, accessor_name, accessor) RelatedValue.DefaultGetter: (
property_holder.security.declareProtected(read_permission, accessor_name) 'getDefault%sRelatedValue' % upper_case_id,
accessor_name = '_categoryGet' + UpperCase(id) + 'RelatedValueSet' 'get%sRelatedValue' % upper_case_id,
if not hasattr(property_holder, accessor_name): '_categoryGetDefault%sRelatedValue' % upper_case_id,
setattr(property_holder, accessor_name, accessor.dummy_copy(accessor_name)) '_categoryGet%sRelatedValue' % upper_case_id,
),
accessor_name = 'getDefault' + UpperCase(id) + 'RelatedValue'
accessor = RelatedValue.DefaultGetter(accessor_name, id) # Related Relative Url
if not hasattr(property_holder, accessor_name): Related.ListGetter: (
setattr(property_holder, accessor_name, accessor) 'get%sRelatedList' % upper_case_id,
property_holder.security.declareProtected(read_permission, accessor_name) '_categoryGet%sRelatedList' % upper_case_id,
accessor_name = 'get' + UpperCase(id) + 'RelatedValue' ),
if not hasattr(property_holder, accessor_name):
setattr(property_holder, accessor_name, accessor.dummy_copy(accessor_name)) # Related as Set
property_holder.security.declareProtected(read_permission, accessor_name) Related.SetGetter: (
accessor_name = '_categoryGetDefault' + UpperCase(id) + 'RelatedValue' 'get%sRelatedSet' % upper_case_id,
if not hasattr(property_holder, accessor_name): '_categoryGet%sRelatedSet' % upper_case_id,
setattr(property_holder, accessor_name, accessor.dummy_copy(accessor_name)) ),
accessor_name = '_categoryGet' + UpperCase(id) + 'RelatedValue'
if not hasattr(property_holder, accessor_name): # Default getter
setattr(property_holder, accessor_name, accessor.dummy_copy(accessor_name)) Related.DefaultGetter: (
'getDefault%sRelated' % upper_case_id,
# Related Relative Url (ie. reverse relation getters) 'get%sRelated' % upper_case_id,
property_holder = BaseClass '_categoryGetDefault%sRelated' % upper_case_id,
'_categoryGet%sRelated' % upper_case_id,
accessor_name = 'get' + UpperCase(id) + 'RelatedList' ),
accessor = Related.ListGetter(accessor_name, id)
if not hasattr(property_holder, accessor_name): # Related Ids (ie. reverse relation getters)
setattr(property_holder, accessor_name, accessor) RelatedValue.IdListGetter: (
property_holder.security.declareProtected(read_permission, accessor_name) '%s%sRelatedIds' % (upper_case_id[0].lower(),
accessor_name = '_categoryGet' + UpperCase(id) + 'RelatedList' upper_case_id[1:]),
if not hasattr(property_holder, accessor_name): 'get%sRelatedIdList' % upper_case_id,
setattr(property_holder, accessor_name, accessor.dummy_copy(accessor_name)) '_categoryGet%sRelatedIdList' % upper_case_id,
),
accessor_name = 'get' + UpperCase(id) + 'RelatedSet'
accessor = Related.SetGetter(accessor_name, id) # Related Ids as Set
if not hasattr(property_holder, accessor_name): RelatedValue.IdSetGetter: (
setattr(property_holder, accessor_name, accessor) 'get%sRelatedIdSet' % upper_case_id,
property_holder.security.declareProtected(read_permission, accessor_name) '_categoryGet%sRelatedIdSet' % upper_case_id,
accessor_name = '_categoryGet' + UpperCase(id) + 'RelatedSet' ),
if not hasattr(property_holder, accessor_name):
setattr(property_holder, accessor_name, accessor.dummy_copy(accessor_name)) # Default Id getter
RelatedValue.DefaultIdGetter: (
accessor_name = 'getDefault' + UpperCase(id) + 'Related' 'getDefault%sRelatedId' % upper_case_id,
accessor = Related.DefaultGetter(accessor_name, id) 'get%sRelatedId' % upper_case_id,
if not hasattr(property_holder, accessor_name): '_categoryGetDefault%sRelatedId' % upper_case_id,
setattr(property_holder, accessor_name, accessor) '_categoryGet%sRelatedId' % upper_case_id,
property_holder.security.declareProtected(read_permission, accessor_name) ),
accessor_name = 'get' + UpperCase(id) + 'Related'
if not hasattr(property_holder, accessor_name): # Related Title list
setattr(property_holder, accessor_name, accessor.dummy_copy(accessor_name)) RelatedValue.TitleListGetter: (
property_holder.security.declareProtected(read_permission, accessor_name) 'get%sRelatedTitleList' % upper_case_id,
accessor_name = '_categoryGetDefault' + UpperCase(id) + 'Related' '_categoryGet%sRelatedTitleList' % upper_case_id,
if not hasattr(property_holder, accessor_name): ),
setattr(property_holder, accessor_name, accessor.dummy_copy(accessor_name))
accessor_name = '_categoryGet' + UpperCase(id) + 'Related' # Related Title Set
if not hasattr(property_holder, accessor_name): RelatedValue.TitleSetGetter: (
setattr(property_holder, accessor_name, accessor.dummy_copy(accessor_name)) 'get%sRelatedTitleSet' % upper_case_id,
'_categoryGet%sRelatedTitleSet' % upper_case_id,
# Related Ids (ie. reverse relation getters) ),
property_holder = BaseClass
# Related default title
accessor_name = UpperCase(id) + 'RelatedIds' RelatedValue.DefaultTitleGetter: (
accessor_name = string.lower(accessor_name[0]) + accessor_name[1:] 'getDefault%sRelatedTitle' % upper_case_id,
accessor = RelatedValue.IdListGetter(accessor_name, id) 'get%sRelatedTitle' % upper_case_id,
if not hasattr(property_holder, accessor_name): '_categoryGetDefault%sRelatedTitle' % upper_case_id,
setattr(property_holder, accessor_name, accessor) '_categoryGet%sRelatedTitle' % upper_case_id,
property_holder.security.declareProtected(read_permission, accessor_name) ),
accessor_name = 'get' + UpperCase(id) + 'RelatedIdList'
if not hasattr(property_holder, accessor_name): # Related Property list
setattr(property_holder, accessor_name, accessor.dummy_copy(accessor_name)) RelatedValue.PropertyListGetter: (
property_holder.security.declareProtected(read_permission, accessor_name) 'get%sRelatedPropertyList' % upper_case_id,
accessor_name = '_categoryGet' + UpperCase(id) + 'RelatedIdList' '_categoryGet%sRelatedPropertyList' % upper_case_id,
if not hasattr(property_holder, accessor_name): ),
setattr(property_holder, accessor_name, accessor.dummy_copy(accessor_name))
# Related Property Set
accessor_name = 'get' + UpperCase(id) + 'RelatedIdSet' RelatedValue.PropertySetGetter: (
accessor = RelatedValue.IdSetGetter(accessor_name, id) 'get%sRelatedPropertySet' % upper_case_id,
if not hasattr(property_holder, accessor_name): '_categoryGet%sRelatedPropertySet' % upper_case_id,
setattr(property_holder, accessor_name, accessor) ),
property_holder.security.declareProtected(read_permission, accessor_name)
accessor_name = '_categoryGet' + UpperCase(id) + 'RelatedIdSet' # Related default title
if not hasattr(property_holder, accessor_name): RelatedValue.DefaultPropertyGetter: (
setattr(property_holder, accessor_name, accessor.dummy_copy(accessor_name)) 'getDefault%sRelatedProperty' % upper_case_id,
'get%sRelatedProperty' % upper_case_id,
accessor_name = 'getDefault' + UpperCase(id) + 'RelatedId' '_categoryGetDefault%sRelatedProperty' % upper_case_id,
accessor = RelatedValue.DefaultIdGetter(accessor_name, id) '_categoryGet%sRelatedProperty' % upper_case_id,
if not hasattr(property_holder, accessor_name): ),
setattr(property_holder, accessor_name, accessor) }
property_holder.security.declareProtected(read_permission, accessor_name)
accessor_name = 'get' + UpperCase(id) + 'RelatedId' permission = read_permission
if not hasattr(property_holder, accessor_name): for accessor_class, accessor_name_list in accessor_dict.items():
setattr(property_holder, accessor_name, accessor.dummy_copy(accessor_name))
property_holder.security.declareProtected(read_permission, accessor_name) # First element is the original accessor
accessor_name = '_categoryGetDefault' + UpperCase(id) + 'RelatedId' accessor_name = accessor_name_list[0]
if not hasattr(property_holder, accessor_name): accessor = accessor_class(accessor_name, id)
setattr(property_holder, accessor_name, accessor.dummy_copy(accessor_name)) if not hasattr(property_holder, accessor_name):
accessor_name = '_categoryGet' + UpperCase(id) + 'RelatedId' setattr(property_holder, accessor_name, accessor)
if not hasattr(property_holder, accessor_name): # Declare the security of method which doesn't start with _
setattr(property_holder, accessor_name, accessor.dummy_copy(accessor_name)) if accessor_name[0] != '_':
property_holder.security.declareProtected(permission, accessor_name)
# Related Ids (ie. reverse relation getters)
property_holder = BaseClass # Others are dummy copies
for accessor_name in accessor_name_list[1:]:
accessor_name = 'get' + UpperCase(id) + 'RelatedTitleList' if not hasattr(property_holder, accessor_name):
accessor = RelatedValue.TitleListGetter(accessor_name, id) setattr(property_holder, accessor_name,
if not hasattr(property_holder, accessor_name): accessor.dummy_copy(accessor_name))
setattr(property_holder, accessor_name, accessor) # Declare the security of method which doesn't start with _
property_holder.security.declareProtected(read_permission, accessor_name) if accessor_name[0] != '_':
accessor_name = '_categoryGet' + UpperCase(id) + 'RelatedTitleList' property_holder.security.declareProtected(permission, accessor_name)
if not hasattr(property_holder, accessor_name):
setattr(property_holder, accessor_name, accessor.dummy_copy(accessor_name))
accessor_name = 'get' + UpperCase(id) + 'RelatedTitleSet'
accessor = RelatedValue.TitleSetGetter(accessor_name, id)
if not hasattr(property_holder, accessor_name):
setattr(property_holder, accessor_name, accessor)
property_holder.security.declareProtected(read_permission, accessor_name)
accessor_name = '_categoryGet' + UpperCase(id) + 'RelatedTitleSet'
if not hasattr(property_holder, accessor_name):
setattr(property_holder, accessor_name, accessor.dummy_copy(accessor_name))
accessor_name = 'getDefault' + UpperCase(id) + 'RelatedTitle'
accessor = RelatedValue.DefaultTitleGetter(accessor_name, id)
if not hasattr(property_holder, accessor_name):
setattr(property_holder, accessor_name, accessor)
property_holder.security.declareProtected(read_permission, accessor_name)
accessor_name = 'get' + UpperCase(id) + 'RelatedTitle'
if not hasattr(property_holder, accessor_name):
setattr(property_holder, accessor_name, accessor.dummy_copy(accessor_name))
property_holder.security.declareProtected(read_permission, accessor_name)
accessor_name = '_categoryGetDefault' + UpperCase(id) + 'RelatedTitle'
if not hasattr(property_holder, accessor_name):
setattr(property_holder, accessor_name, accessor.dummy_copy(accessor_name))
accessor_name = '_categoryGet' + UpperCase(id) + 'RelatedTitle'
if not hasattr(property_holder, accessor_name):
setattr(property_holder, accessor_name, accessor.dummy_copy(accessor_name))
# Related Ids (ie. reverse relation getters)
property_holder = BaseClass
accessor_name = 'get' + UpperCase(id) + 'RelatedPropertyList'
accessor = RelatedValue.PropertyListGetter(accessor_name, id)
if not hasattr(property_holder, accessor_name):
setattr(property_holder, accessor_name, accessor)
property_holder.security.declareProtected(read_permission, accessor_name)
accessor_name = '_categoryGet' + UpperCase(id) + 'RelatedPropertyList'
if not hasattr(property_holder, accessor_name):
setattr(property_holder, accessor_name, accessor.dummy_copy(accessor_name))
accessor_name = 'get' + UpperCase(id) + 'RelatedPropertySet'
accessor = RelatedValue.PropertySetGetter(accessor_name, id)
if not hasattr(property_holder, accessor_name):
setattr(property_holder, accessor_name, accessor)
property_holder.security.declareProtected(read_permission, accessor_name)
accessor_name = '_categoryGet' + UpperCase(id) + 'RelatedPropertySet'
if not hasattr(property_holder, accessor_name):
setattr(property_holder, accessor_name, accessor.dummy_copy(accessor_name))
accessor_name = 'getDefault' + UpperCase(id) + 'RelatedProperty'
accessor = RelatedValue.DefaultPropertyGetter(accessor_name, id)
if not hasattr(property_holder, accessor_name):
setattr(property_holder, accessor_name, accessor)
property_holder.security.declareProtected(read_permission, accessor_name)
accessor_name = 'get' + UpperCase(id) + 'RelatedProperty'
if not hasattr(property_holder, accessor_name):
setattr(property_holder, accessor_name, accessor.dummy_copy(accessor_name))
property_holder.security.declareProtected(read_permission, accessor_name)
accessor_name = '_categoryGetDefault' + UpperCase(id) + 'RelatedProperty'
if not hasattr(property_holder, accessor_name):
setattr(property_holder, accessor_name, accessor.dummy_copy(accessor_name))
accessor_name = '_categoryGet' + UpperCase(id) + 'RelatedProperty'
if not hasattr(property_holder, accessor_name):
setattr(property_holder, accessor_name, accessor.dummy_copy(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