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,7 +1732,8 @@ def createDefaultAccessors(property_holder, id, prop = None, ...@@ -1734,7 +1732,8 @@ 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,
prop['type'], default=prop.get('default'),
storage_id = prop.get('storage_id')) 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)
...@@ -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):
setattr(property_holder, accessor_name, accessor)
property_holder.security.declareProtected(read_permission, accessor_name)
accessor_name = '_categoryGet' + UpperCase(id) + 'RelatedList'
if not hasattr(property_holder, accessor_name):
setattr(property_holder, accessor_name, accessor.dummy_copy(accessor_name))
accessor_name = 'get' + UpperCase(id) + 'RelatedSet'
accessor = Related.SetGetter(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) + 'RelatedSet'
if not hasattr(property_holder, accessor_name):
setattr(property_holder, accessor_name, accessor.dummy_copy(accessor_name))
accessor_name = 'getDefault' + UpperCase(id) + 'Related'
accessor = Related.DefaultGetter(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) + 'Related'
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) + 'Related'
if not hasattr(property_holder, accessor_name):
setattr(property_holder, accessor_name, accessor.dummy_copy(accessor_name))
accessor_name = '_categoryGet' + UpperCase(id) + 'Related'
if not hasattr(property_holder, accessor_name):
setattr(property_holder, accessor_name, accessor.dummy_copy(accessor_name))
# Related Ids (ie. reverse relation getters) # Related Ids (ie. reverse relation getters)
property_holder = BaseClass RelatedValue.IdListGetter: (
'%s%sRelatedIds' % (upper_case_id[0].lower(),
accessor_name = UpperCase(id) + 'RelatedIds' upper_case_id[1:]),
accessor_name = string.lower(accessor_name[0]) + accessor_name[1:] 'get%sRelatedIdList' % upper_case_id,
accessor = RelatedValue.IdListGetter(accessor_name, id) '_categoryGet%sRelatedIdList' % upper_case_id,
if not hasattr(property_holder, accessor_name): ),
setattr(property_holder, accessor_name, accessor)
property_holder.security.declareProtected(read_permission, accessor_name) # Related Ids as Set
accessor_name = 'get' + UpperCase(id) + 'RelatedIdList' RelatedValue.IdSetGetter: (
if not hasattr(property_holder, accessor_name): 'get%sRelatedIdSet' % upper_case_id,
setattr(property_holder, accessor_name, accessor.dummy_copy(accessor_name)) '_categoryGet%sRelatedIdSet' % upper_case_id,
property_holder.security.declareProtected(read_permission, accessor_name) ),
accessor_name = '_categoryGet' + UpperCase(id) + 'RelatedIdList'
if not hasattr(property_holder, accessor_name): # Default Id getter
setattr(property_holder, accessor_name, accessor.dummy_copy(accessor_name)) RelatedValue.DefaultIdGetter: (
'getDefault%sRelatedId' % upper_case_id,
accessor_name = 'get' + UpperCase(id) + 'RelatedIdSet' 'get%sRelatedId' % upper_case_id,
accessor = RelatedValue.IdSetGetter(accessor_name, id) '_categoryGetDefault%sRelatedId' % upper_case_id,
if not hasattr(property_holder, accessor_name): '_categoryGet%sRelatedId' % upper_case_id,
setattr(property_holder, accessor_name, accessor) ),
property_holder.security.declareProtected(read_permission, accessor_name)
accessor_name = '_categoryGet' + UpperCase(id) + 'RelatedIdSet' # Related Title list
if not hasattr(property_holder, accessor_name): RelatedValue.TitleListGetter: (
setattr(property_holder, accessor_name, accessor.dummy_copy(accessor_name)) 'get%sRelatedTitleList' % upper_case_id,
'_categoryGet%sRelatedTitleList' % upper_case_id,
accessor_name = 'getDefault' + UpperCase(id) + 'RelatedId' ),
accessor = RelatedValue.DefaultIdGetter(accessor_name, id)
if not hasattr(property_holder, accessor_name): # Related Title Set
setattr(property_holder, accessor_name, accessor) RelatedValue.TitleSetGetter: (
property_holder.security.declareProtected(read_permission, accessor_name) 'get%sRelatedTitleSet' % upper_case_id,
accessor_name = 'get' + UpperCase(id) + 'RelatedId' '_categoryGet%sRelatedTitleSet' % upper_case_id,
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) # Related default title
accessor_name = '_categoryGetDefault' + UpperCase(id) + 'RelatedId' RelatedValue.DefaultTitleGetter: (
if not hasattr(property_holder, accessor_name): 'getDefault%sRelatedTitle' % upper_case_id,
setattr(property_holder, accessor_name, accessor.dummy_copy(accessor_name)) 'get%sRelatedTitle' % upper_case_id,
accessor_name = '_categoryGet' + UpperCase(id) + 'RelatedId' '_categoryGetDefault%sRelatedTitle' % upper_case_id,
if not hasattr(property_holder, accessor_name): '_categoryGet%sRelatedTitle' % upper_case_id,
setattr(property_holder, accessor_name, accessor.dummy_copy(accessor_name)) ),
# Related Ids (ie. reverse relation getters) # Related Property list
property_holder = BaseClass RelatedValue.PropertyListGetter: (
'get%sRelatedPropertyList' % upper_case_id,
accessor_name = 'get' + UpperCase(id) + 'RelatedTitleList' '_categoryGet%sRelatedPropertyList' % upper_case_id,
accessor = RelatedValue.TitleListGetter(accessor_name, id) ),
if not hasattr(property_holder, accessor_name):
setattr(property_holder, accessor_name, accessor) # Related Property Set
property_holder.security.declareProtected(read_permission, accessor_name) RelatedValue.PropertySetGetter: (
accessor_name = '_categoryGet' + UpperCase(id) + 'RelatedTitleList' 'get%sRelatedPropertySet' % upper_case_id,
if not hasattr(property_holder, accessor_name): '_categoryGet%sRelatedPropertySet' % upper_case_id,
setattr(property_holder, accessor_name, accessor.dummy_copy(accessor_name)) ),
accessor_name = 'get' + UpperCase(id) + 'RelatedTitleSet' # Related default title
accessor = RelatedValue.TitleSetGetter(accessor_name, id) RelatedValue.DefaultPropertyGetter: (
if not hasattr(property_holder, accessor_name): 'getDefault%sRelatedProperty' % upper_case_id,
setattr(property_holder, accessor_name, accessor) 'get%sRelatedProperty' % upper_case_id,
property_holder.security.declareProtected(read_permission, accessor_name) '_categoryGetDefault%sRelatedProperty' % upper_case_id,
accessor_name = '_categoryGet' + UpperCase(id) + 'RelatedTitleSet' '_categoryGet%sRelatedProperty' % upper_case_id,
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' permission = read_permission
accessor = RelatedValue.PropertySetGetter(accessor_name, id) for accessor_class, accessor_name_list in accessor_dict.items():
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' # First element is the original accessor
accessor = RelatedValue.DefaultPropertyGetter(accessor_name, id) accessor_name = accessor_name_list[0]
accessor = accessor_class(accessor_name, id)
if not hasattr(property_holder, accessor_name): if not hasattr(property_holder, accessor_name):
setattr(property_holder, accessor_name, accessor) setattr(property_holder, accessor_name, accessor)
property_holder.security.declareProtected(read_permission, accessor_name) # Declare the security of method which doesn't start with _
accessor_name = 'get' + UpperCase(id) + 'RelatedProperty' if accessor_name[0] != '_':
if not hasattr(property_holder, accessor_name): property_holder.security.declareProtected(permission, accessor_name)
setattr(property_holder, accessor_name, accessor.dummy_copy(accessor_name))
property_holder.security.declareProtected(read_permission, accessor_name) # Others are dummy copies
accessor_name = '_categoryGetDefault' + UpperCase(id) + 'RelatedProperty' for accessor_name in accessor_name_list[1:]:
if not hasattr(property_holder, accessor_name): if not hasattr(property_holder, accessor_name):
setattr(property_holder, accessor_name, accessor.dummy_copy(accessor_name)) setattr(property_holder, accessor_name,
accessor_name = '_categoryGet' + UpperCase(id) + 'RelatedProperty' accessor.dummy_copy(accessor_name))
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)
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