Commit 2b9dab9a authored by Arnaud Fontaine's avatar Arnaud Fontaine

Following r43892, accessors generation is not performed through Utils

anymore, so get rid of the code related to accessors generation in
Utils


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@43895 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 3e44e2b4
......@@ -1206,26 +1206,6 @@ def initializeProduct( context,
permission = permission,
icon = icon)
class ConstraintNotFound(Exception):
pass
def createConstraintList(property_holder, constraint_definition):
"""
This function creates constraint instances for a class
and a property
constraint_definition -- the constraint with all attributes
"""
from Products.ERP5Type import Constraint
try:
consistency_class = getattr(Constraint, constraint_definition['type'])
except AttributeError:
LOG("ERP5Type", PROBLEM, "Can not find Constraint: %s" \
% constraint_definition['type'], error=sys.exc_info())
raise ConstraintNotFound(repr(constraint_definition))
consistency_instance = consistency_class(**constraint_definition)
property_holder.constraints += [consistency_instance]
#####################################################
# Constructor initialization
#####################################################
......@@ -1300,1654 +1280,6 @@ def createExpressionContext(object, portal=None):
tv[cache_key] = ec
return ec
def getExistingBaseCategoryList(portal, base_cat_list):
cache = getReadOnlyTransactionCache()
if cache is None:
cache = getTransactionalVariable()
category_tool = getattr(portal, 'portal_categories', None)
if category_tool is None:
# most likely, accessor generation when bootstrapping a site
if not getattr(portal, '_v_bootstrapping', False):
warnings.warn("Category Tool is missing. Accessors can not be generated.")
return ()
new_base_cat_list = []
for base_cat in base_cat_list:
if base_cat is None:
# a Dynamic Category Property specifies a TALES Expression which
# may return a list containing None, so just skip it
continue
key = (base_cat,)
try:
value = cache[key]
except KeyError:
value = category_tool._getOb(base_cat, None)
if value is None:
warnings.warn("Base Category %r is missing."
" Accessors can not be generated." % base_cat, Warning)
cache[key] = value
if value is not None:
new_base_cat_list.append(base_cat)
return tuple(new_base_cat_list)
def createRelatedAccessors(portal_categories, property_holder, econtext,
base_category_list=None):
if base_category_list is None:
base_category_list = []
# first extend the Tales category definitions into base_category_list
for cat in base_category_dict:
if isinstance(cat, Expression):
result = cat(econtext)
if isinstance(result, (list, tuple)):
base_category_list.extend(result)
else:
base_category_list.append(result)
else:
base_category_list.append(cat)
for cat in base_category_list:
# Get read and write permission
cat_object = portal_categories.get(cat, None)
if cat_object is not None:
read_permission = Permissions.__dict__.get(
cat_object.getReadPermission(),
Permissions.AccessContentsInformation)
if isinstance(read_permission, Expression):
read_permission = read_permission(econtext)
else:
read_permission = Permissions.AccessContentsInformation
# Actually create accessors
createRelatedValueAccessors(property_holder, cat, read_permission=read_permission)
# Unnecessary to create these accessors more than once.
base_category_dict.clear()
def createAllCategoryAccessors(portal, property_holder, cat_list, econtext):
if portal is not None:
portal_categories = getattr(portal, 'portal_categories', None)
else:
portal_categories = None
for cat in cat_list:
# Create free text accessors.
prop = {
'id' : '%s_free_text' % cat,
'description': 'free text to specify %s' % cat,
'type' : 'text',
'default' : '',
'mode' : 'w'
}
# XXX These are only for backward compatibility.
if cat == 'group':
prop['storage_id'] = 'group'
elif cat == 'site':
prop['storage_id'] = 'location'
createDefaultAccessors(
property_holder,
prop['id'],
prop=prop,
read_permission=Permissions.AccessContentsInformation,
write_permission=Permissions.ModifyPortalContent,
portal=portal)
# Get read and write permission
if portal_categories is not None:
cat_object = portal_categories.get(cat, None)
else:
cat_object = None
if cat_object is not None:
read_permission = Permissions.__dict__.get(
cat_object.getReadPermission(),
Permissions.AccessContentsInformation)
if isinstance(read_permission, Expression):
read_permission = read_permission(econtext)
write_permission = Permissions.__dict__.get(
cat_object.getWritePermission(),
Permissions.ModifyPortalContent)
if isinstance(write_permission, Expression):
write_permission = write_permission(econtext)
else:
read_permission = Permissions.AccessContentsInformation
write_permission = Permissions.ModifyPortalContent
# Actualy create accessors
createCategoryAccessors(property_holder, cat,
read_permission=read_permission, write_permission=write_permission)
createValueAccessors(property_holder, cat,
read_permission=read_permission, write_permission=write_permission)
default_translation_property_dict = {
'id' : 'translation_domain',
'description' : '',
'default' : '',
'type' : 'string',
'mode' : 'w',
}
def setDefaultProperties(property_holder, object=None, portal=None):
"""
This methods sets default accessors for this object as well
as consistency checkers, based on the definition
stored in PropertySheet objects.
Accessors include
- attribute accessors (ie. a string, float value stored by the object)
- category accessors (ie. a membership of an object to a category)
- relation accessors (ie. a kind of membership where the category
instance is content)
- programmable acquisition acessors (ie. attribute accessors which
are based on relations)
Consistency checkers are intended to check the content consistency
(ex. ariry of a relation) as well as fix content consistency
through a default consistency fixing method.
Set default attributes in current object for all properties in '_properties'
"""
econtext = createExpressionContext(object, portal)
# First build the property list from the property sheet
# and the class properties
prop_list = []
# Do not consider superclass _properties definition
for prop in property_holder.__dict__.get('_properties', []):
# Copy the dict so that Expression objects are not overwritten.
prop_list.append(prop.copy())
# Do not consider superclass _categories definition
cat_list = property_holder.__dict__.get('_categories', [])
# a list of declarative consistency definitions (ie. constraints)
# Do not consider superclass _constraints definition
constraint_list = property_holder.__dict__.get('_constraints', [])
# Evaluate TALES expressions.
for prop in prop_list:
for key,value in prop.items():
if isinstance(value, Expression):
prop[key] = value(econtext)
new_cat_list = []
for cat in cat_list:
if isinstance(cat, Expression):
result = cat(econtext)
if isinstance(result, (tuple, list)):
new_cat_list.extend(result)
else:
new_cat_list.append(result)
else:
new_cat_list.append(cat)
cat_list = getExistingBaseCategoryList(portal, new_cat_list)
from Products.ERP5Type.mixin.constraint import ConstraintMixin
for const in constraint_list:
if isinstance(const, ConstraintMixin):
continue
for key, value in const.items():
if isinstance(value, Expression):
const[key] = value(econtext)
# Store ERP5 properties on specific attributes
property_holder._erp5_properties = tuple(prop_list)
# Create default accessors for property sheets
converted_prop_list = []
converted_prop_set = set()
for prop in prop_list:
if prop['type'] not in type_definition:
LOG("ERP5Type.Utils", INFO,
"Invalid type '%s' of property '%s' for Property Sheet '%s'" % \
(prop['type'], prop['id'], property_holder.__name__))
continue
read_permission = prop.get('read_permission',
Permissions.AccessContentsInformation)
if isinstance(read_permission, Expression):
read_permission = read_permission(econtext)
write_permission = prop.get('write_permission',
Permissions.ModifyPortalContent)
if isinstance(write_permission, Expression):
write_permission = write_permission(econtext)
if 'base_id' in prop:
continue
if prop['id'] not in converted_prop_set:
if prop['type'] != 'content':
converted_prop_list.append(prop)
converted_prop_set.add(prop['id'])
# Create range accessors, if this has a range.
if prop.get('range', 0):
for value in ('min', 'max'):
range_prop = prop.copy()
del range_prop['range']
range_prop.pop('storage_id', None)
if range_prop.get('acquisition_accessor_id', 0):
range_prop['acquisition_accessor_id'] = '%sRange%s' % (
range_prop['acquisition_accessor_id'], value.capitalize())
range_prop['alt_accessor_id'] = (
'get' + convertToUpperCase(prop['id']),)
createDefaultAccessors(
property_holder,
'%s_range_%s' % (prop['id'], value),
prop=range_prop,
read_permission=read_permission,
write_permission=write_permission,
portal=portal)
# Create translation accesor, if translatable is set
if prop.get('translatable', 0):
# make accessors like getTranslatedProperty
createTranslationAccessors(
property_holder,
'translated_%s' % (prop['id']),
prop,
read_permission=read_permission,
write_permission=write_permission)
createTranslationLanguageAccessors(
property_holder,
prop,
read_permission=read_permission,
write_permission=write_permission,
portal=portal)
# make accessor to translation_domain
# first create default one as a normal property
accessor_id = '%s_translation_domain' % prop['id']
createDefaultAccessors(
property_holder,
accessor_id,
prop=default_translation_property_dict,
read_permission=read_permission,
write_permission=write_permission,
portal=portal)
# then overload accesors getPropertyTranslationDomain
default = prop.get('translation_domain', '')
createTranslationAccessors(
property_holder,
accessor_id,
prop,
read_permission=read_permission,
write_permission=write_permission,
default=default)
createDefaultAccessors(
property_holder,
prop['id'],
prop=prop,
read_permission=read_permission,
write_permission=write_permission,
portal=portal)
# Create Category Accessors
createAllCategoryAccessors(portal, property_holder, cat_list, econtext)
property_holder.constraints = []
for constraint in constraint_list:
# ZODB Property Sheets constraints are no longer defined by a
# dictionary but by a ConstraintMixin, thus just append it to
# the list of constraints
if isinstance(constraint, ConstraintMixin):
property_holder.constraints.append(constraint)
else:
createConstraintList(property_holder, constraint_definition=constraint)
# ERP5 _properties and Zope _properties are somehow different
# The id is converted to the Zope standard - we keep the original id
# as base_id
new_converted_prop_list = []
for prop in converted_prop_list:
new_prop = prop.copy()
if prop['type'] in list_types or prop.get('multivalued', 0):
# Display as list
if not prop.get('base_id', None):
new_prop['base_id'] = prop['id']
new_prop['id'] = prop['id'] + '_list'
if prop.get('acquisition_base_category') is not None \
and not prop.get('acquisition_copy_value'):
# Set acquisition values as read only if no value is copied
new_prop['mode'] = 'r'
new_converted_prop_list.append(new_prop)
# Set the properties of the class
property_holder._properties = tuple(new_converted_prop_list)
property_holder._categories = tuple(cat_list)
property_holder._constraints = tuple(constraint_list)
# And the default values - default values are needed
# for historical reasons : many objects have a default
# value defines at the class level. The use of None
# allows to create the equivalent of NULL values
# - new - XXX
# We remove such properties here
#from Base import Base as BaseClass
for prop in converted_prop_list:
if prop['type'] not in type_definition:
raise TypeError, '"%s" is invalid type for propertysheet' % \
prop['type']
#if not hasattr(property_holder, prop['id']):
# setattr(property_holder, prop['id'], None) # This makes sure no acquisition will happen
# but is wrong when we use storage_id .....
#storage_id = prop.get('storage_id', prop['id'])
#if not hasattr(BaseClass, storage_id):
# setattr(property_holder, storage_id, None) # This breaks things with aq_dynamic
#setattr(BaseClass, storage_id, None) # This blocks acquisition
#else:
#LOG('existing property',0,str(storage_id))
#if prop.get('default') is not None:
# # setattr(property_holder, prop['id'], prop.get('default'))
# pass
#else:
# # setattr(property_holder, prop['id'], defaults[prop['type']])
# pass
#####################################################
# Accessor initialization
#####################################################
from Base import Base as BaseClass
from Accessor import Base, List, Acquired, Content,\
AcquiredProperty, ContentProperty, \
Alias
def createDefaultAccessors(property_holder, id, prop = None,
read_permission=Permissions.AccessContentsInformation,
write_permission=Permissions.ModifyPortalContent,
portal=None):
"""
This function creates accessor and setter for a class
and a property
property_holder -- the class to add an accessor to
id -- the id of the property
prop -- the property definition of the property
"""
override = prop.get('override',0)
######################################################
# Create Translation Acquired Accessors.
if prop.get('translation_acquired_property_id'):
createTranslationAcquiredPropertyAccessors(property_holder, prop,
portal=portal)
######################################################
# Create Portal Category Type Accessors.
if prop['type'] == 'group_type':
createGroupTypeAccessors(property_holder, prop,
read_permission=read_permission,
portal=portal)
######################################################
# Create Getters
elif prop.get('acquisition_base_category') is not None:
# Create getters for an acquired property
# XXXX Missing Boolean accessor
accessor_args = (
prop['type'],
prop.get('default'),
prop['acquisition_base_category'],
prop['acquisition_portal_type'],
prop['acquisition_accessor_id'],
prop.get('acquisition_copy_value',0),
prop.get('acquisition_mask_value',0),
prop.get('storage_id'),
prop.get('alt_accessor_id'),
prop.get('acquisition_object_id'),
(prop['type'] in list_types or prop.get('multivalued', 0)),
(prop['type'] == 'tales')
)
# Base Getter
accessor_name = 'get' + UpperCase(id)
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, id, Acquired.DefaultGetter, accessor_args)
property_holder.declareProtected( read_permission, accessor_name )
accessor_name = '_baseGet' + UpperCase(id)
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, id, Acquired.DefaultGetter, accessor_args)
# Default Getter
accessor_name = 'getDefault' + UpperCase(id)
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, id, Acquired.DefaultGetter, accessor_args)
property_holder.declareProtected( read_permission, accessor_name )
accessor_name = '_baseGetDefault' + UpperCase(id)
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, id, Acquired.DefaultGetter, accessor_args)
# List Getter
if prop['type'] in list_types or prop.get('multivalued', 0):
accessor_name = 'get' + UpperCase(id) + 'List'
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, id, Acquired.ListGetter, accessor_args)
property_holder.declareProtected( read_permission, accessor_name )
accessor_name = '_baseGet' + UpperCase(id) + 'List'
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, id, Acquired.ListGetter, accessor_args)
# Set Getter
accessor_name = 'get' + UpperCase(id) + 'Set'
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, id, Acquired.SetGetter, accessor_args)
property_holder.declareProtected( read_permission, accessor_name )
accessor_name = '_baseGet' + UpperCase(id) + 'Set'
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, id, Acquired.SetGetter, accessor_args)
if prop['type'] == 'content':
#LOG('Value Object Accessor', 0, prop['id'])
# Base Getter
accessor_name = 'get' + UpperCase(id) + 'Value'
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, id, Acquired.DefaultGetter, accessor_args)
property_holder.declareProtected( read_permission, accessor_name )
accessor_name = '_baseGet' + UpperCase(id) + 'Value'
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, id, Acquired.DefaultGetter, accessor_args)
# Default Getter
accessor_name = 'getDefault' + UpperCase(id) + 'Value'
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, id, Acquired.DefaultGetter, accessor_args)
property_holder.declareProtected( read_permission, accessor_name )
accessor_name = '_baseGetDefault' + UpperCase(id) + 'Value'
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, id, Acquired.DefaultGetter, accessor_args)
# List Getter
accessor_name = 'get' + UpperCase(id) + 'ValueList'
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, id, Acquired.ListGetter, accessor_args)
property_holder.declareProtected( read_permission, accessor_name )
accessor_name = '_baseGet' + UpperCase(id) + 'ValueList'
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, id, Acquired.ListGetter, accessor_args)
# AcquiredProperty Getters
if prop.get('acquired_property_id'):
for aq_id in prop['acquired_property_id']:
composed_id = "%s_%s" % (id, aq_id)
# Getter
# print "Set composed_id accessor %s" % composed_id
accessor_name = 'get' + UpperCase(composed_id)
# print "Set accessor_name accessor %s" % accessor_name
accessor_args = (
prop['type'],
prop['portal_type'],
aq_id,
prop['acquisition_base_category'],
prop['acquisition_portal_type'],
prop['acquisition_accessor_id'],
prop.get('acquisition_copy_value',0),
prop.get('acquisition_mask_value',0),
prop.get('storage_id'),
prop.get('alt_accessor_id'),
prop.get('acquisition_object_id'),
(prop['type'] in list_types or prop.get('multivalued', 0)),
(prop['type'] == 'tales')
)
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, composed_id, AcquiredProperty.Getter, accessor_args)
property_holder.declareProtected( read_permission, accessor_name )
accessor_name = '_baseGet' + UpperCase(composed_id)
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, composed_id, AcquiredProperty.Getter, accessor_args)
# Default Getter
accessor_name = 'getDefault' + UpperCase(composed_id)
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, composed_id, AcquiredProperty.DefaultGetter, accessor_args)
property_holder.declareProtected( read_permission, accessor_name )
accessor_name = '_baseGetDefault' + UpperCase(composed_id)
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, composed_id, AcquiredProperty.DefaultGetter, accessor_args)
# List Getter
################# NOT YET
# Setter
accessor_name = 'set' + UpperCase(composed_id)
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, '_' + accessor_name, Alias.Reindex, ())
property_holder.declareProtected( write_permission, accessor_name )
accessor_name = '_set' + UpperCase(composed_id)
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, composed_id, AcquiredProperty.Setter, accessor_args)
accessor_name = '_baseSet' + UpperCase(composed_id)
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, composed_id, AcquiredProperty.Setter, accessor_args)
# Default Setter
accessor_name = 'setDefault' + UpperCase(composed_id)
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, '_' + accessor_name, Alias.Reindex, ())
property_holder.declareProtected( write_permission, accessor_name )
accessor_name = '_setDefault' + UpperCase(composed_id)
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, composed_id, AcquiredProperty.DefaultSetter, accessor_args)
accessor_name = '_baseSetDefault' + UpperCase(composed_id)
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, composed_id, AcquiredProperty.DefaultSetter, accessor_args)
# List Getter
################# NOT YET
elif prop['type'] in list_types or prop.get('multivalued', 0):
# The base accessor returns the first item in a list
# and simulates a simple property
# The default value is the first element of prop.get('default') if it exists
default = prop.get('default')
accessor_args = (prop['type'], prop.get('default'), prop.get('storage_id'))
# Create getters for a list property
accessor_name = 'get' + UpperCase(id)
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, id, List.Getter, accessor_args)
property_holder.declareProtected( read_permission, accessor_name )
accessor_name = '_baseGet' + UpperCase(id)
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, id, List.Getter, accessor_args)
accessor_name = 'getDefault' + UpperCase(id)
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, id, List.DefaultGetter, accessor_args)
property_holder.declareProtected( read_permission, accessor_name )
accessor_name = '_baseGetDefault' + UpperCase(id)
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, id, List.DefaultGetter, accessor_args)
accessor_name = 'get' + UpperCase(id) + 'List'
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, id, List.ListGetter, accessor_args)
property_holder.declareProtected( read_permission, accessor_name )
accessor_name = '_baseGet' + UpperCase(id) + 'List'
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, id, List.ListGetter, accessor_args)
accessor_name = 'get' + UpperCase(id) + 'Set'
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, id, List.SetGetter, accessor_args)
property_holder.declareProtected( read_permission, accessor_name )
accessor_name = '_baseGet' + UpperCase(id) + 'Set'
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, id, List.SetGetter, accessor_args)
elif prop['type'] == 'content':
accessor_args = (prop['type'], prop.get('portal_type'), prop.get('storage_id'))
# Create getters for a list property
accessor_name = 'get' + UpperCase(id)
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, id, Content.Getter, accessor_args)
property_holder.declareProtected( read_permission, accessor_name )
accessor_name = '_baseGet' + UpperCase(id)
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, id, Content.Getter, accessor_args)
accessor_name = 'getDefault' + UpperCase(id)
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, id, Content.DefaultGetter, accessor_args)
property_holder.declareProtected( read_permission, accessor_name )
accessor_name = '_baseGetDefault' + UpperCase(id)
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, id, Content.DefaultGetter, accessor_args)
accessor_name = 'get' + UpperCase(id) + 'List'
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, id, Content.ListGetter, accessor_args)
property_holder.declareProtected( read_permission, accessor_name )
accessor_name = '_baseGet' + UpperCase(id) + 'List'
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, id, Content.ListGetter, accessor_args)
# Create value getters for a list property
accessor_name = 'get' + UpperCase(id) + 'Value'
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, id, Content.ValueGetter, accessor_args)
property_holder.declareProtected( read_permission, accessor_name )
accessor_name = '_baseGet' + UpperCase(id) + 'Value'
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, id, Content.ValueGetter, accessor_args)
accessor_name = 'getDefault' + UpperCase(id) + 'Value'
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, id, Content.DefaultValueGetter, accessor_args)
property_holder.declareProtected( read_permission, accessor_name )
accessor_name = '_baseGetDefault' + UpperCase(id) + 'Value'
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, id, Content.DefaultValueGetter, accessor_args)
accessor_name = 'get' + UpperCase(id) + 'ValueList'
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, id, Content.ValueListGetter, accessor_args)
property_holder.declareProtected( read_permission, accessor_name )
accessor_name = '_baseGet' + UpperCase(id) + 'ValueList'
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, id, Content.ValueListGetter, accessor_args)
if prop.get('acquired_property_id'):
for aq_id in prop['acquired_property_id']:
for composed_id in ("%s_%s" % (id, aq_id), "default_%s_%s" % (id, aq_id)) :
accessor_name = 'get' + UpperCase(composed_id)
accessor_args = (prop['type'], aq_id, prop.get('portal_type'), prop.get('storage_id'))
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, composed_id, ContentProperty.Getter, accessor_args)
property_holder.declareProtected( read_permission, accessor_name )
accessor_name = 'get' + UpperCase(composed_id) + 'List'
list_accessor_args = (prop['type'], aq_id + '_list', prop.get('portal_type'), prop.get('storage_id'))
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, composed_id + '_list',
ContentProperty.Getter, list_accessor_args)
property_holder.declareProtected( read_permission, accessor_name )
# No default getter YET XXXXXXXXXXXXXX
# No list getter YET XXXXXXXXXXXXXX
accessor_name = '_set' + UpperCase(composed_id)
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, composed_id, ContentProperty.Setter, accessor_args)
property_holder.declareProtected( write_permission, accessor_name )
accessor_name = '_set' + UpperCase(composed_id) + 'List'
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, composed_id + '_list',
ContentProperty.Setter, list_accessor_args)
property_holder.declareProtected( write_permission, accessor_name )
accessor_name = 'set' + UpperCase(composed_id)
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, '_' + accessor_name, Alias.Reindex, ())
property_holder.declareProtected( write_permission, accessor_name )
accessor_name = 'set' + UpperCase(composed_id) + 'List'
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, '_' + accessor_name, Alias.Reindex, ())
property_holder.declareProtected( write_permission, accessor_name )
# No default getter YET XXXXXXXXXXXXXX
# No list getter YET XXXXXXXXXXXXXX
else:
accessor_args = (prop['type'], prop.get('default'), prop.get('storage_id'))
# Create getters for a simple property
accessor_name = 'get' + UpperCase(id)
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, id, Base.Getter, accessor_args)
property_holder.declareProtected( read_permission, accessor_name )
accessor_name = '_baseGet' + UpperCase(id)
if not hasattr(property_holder, accessor_name) or override:
property_holder.registerAccessor(accessor_name, id, Base.Getter, accessor_args)
######################################################
# Create Setters
if prop['type'] == 'group_type':
# No setter
pass
elif prop['type'] in list_types or prop.get('multivalued', 0):
# Create setters for a list property by aliasing
setter_name = 'set' + UpperCase(id)
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, '_' + setter_name, Alias.Reindex, ())
property_holder.declareProtected(write_permission, setter_name)
setter_name = 'setDefault' + UpperCase(id)
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, '_' + setter_name, Alias.Reindex, ())
property_holder.declareProtected(write_permission, setter_name)
setter_name = 'set' + UpperCase(id) + 'List'
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, '_' + setter_name, Alias.Reindex, ())
property_holder.declareProtected(write_permission, setter_name)
setter_name = 'set' + UpperCase(id) + 'Set'
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, '_' + setter_name, Alias.Reindex, ())
property_holder.declareProtected(write_permission, setter_name)
# Create setters for a list property (no reindexing)
# The base accessor sets the list to a singleton
# and allows simulates a simple property
accessor_args = (prop['type'], prop.get('storage_id'))
# Create setters for a list property
setter_name = '_set' + UpperCase(id)
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, id, List.Setter, accessor_args)
setter_name = '_baseSet' + UpperCase(id)
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, id, List.Setter, accessor_args)
setter_name = '_setDefault' + UpperCase(id)
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, id, List.DefaultSetter, accessor_args)
setter_name = '_baseSetDefault' + UpperCase(id)
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, id, List.DefaultSetter, accessor_args)
setter_name = '_set' + UpperCase(id) + 'List'
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, id, List.ListSetter, accessor_args)
setter_name = '_baseSet' + UpperCase(id) + 'List'
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, id, List.ListSetter, accessor_args)
setter_name = '_set' + UpperCase(id) + 'Set'
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, id, List.SetSetter, accessor_args)
setter_name = '_baseSet' + UpperCase(id) + 'Set'
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, id, List.SetSetter, accessor_args)
elif prop['type'] == 'content':
# Create setters for an object property
# Create setters for a list property (reindexing)
# The base accessor sets the list to a singleton
# and allows simulates a simple property
base_setter_name = 'set' + UpperCase(id)
# The default setter sets the first item of a list without changing other items
default_setter_name = 'setDefault' + UpperCase(id)
# Create setters for an object property
setter_name = 'set' + UpperCase(id)
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, '_' + base_setter_name, Alias.Reindex, ())
property_holder.declareProtected(write_permission, setter_name)
setter_name = 'setDefault' + UpperCase(id)
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, '_' + default_setter_name, Alias.Reindex, ())
property_holder.declareProtected(write_permission, setter_name)
setter_name = 'set' + UpperCase(id) + 'Value'
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, '_' + base_setter_name, Alias.Reindex, ())
property_holder.declareProtected(write_permission, setter_name)
setter_name = 'setDefault' + UpperCase(id) + 'Value'
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, '_' + default_setter_name, Alias.Reindex, ())
property_holder.declareProtected(write_permission, setter_name)
# Create setters for a list property (no reindexing)
# The base accessor sets the list to a singleton
# and allows simulates a simple property
accessor_args = (prop['type'], prop.get('storage_id'))
# Create setters for an object property
setter_name = '_set' + UpperCase(id)
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, id, Content.Setter, accessor_args)
setter_name = '_baseSet' + UpperCase(id)
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, id, Content.Setter, accessor_args)
setter_name = '_setDefault' + UpperCase(id)
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, id, Content.DefaultSetter, accessor_args)
setter_name = '_baseSetDefault' + UpperCase(id)
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, id, Content.DefaultSetter, accessor_args)
setter_name = '_set' + UpperCase(id) + 'Value'
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, id, Content.Setter, accessor_args)
setter_name = '_baseSet' + UpperCase(id) + 'Value'
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, id, Content.Setter, accessor_args)
setter_name = '_setDefault' + UpperCase(id) + 'Value'
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, id, Content.DefaultSetter, accessor_args)
setter_name = '_baseSetDefault' + UpperCase(id) + 'Value'
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, id, Content.DefaultSetter, accessor_args)
else:
accessor_args = (prop['type'], prop.get('storage_id'))
# Create setters for a simple property
setter_name = 'set' + UpperCase(id)
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, '_' + setter_name, Alias.Reindex, ())
property_holder.declareProtected(write_permission, setter_name)
setter_name = '_set' + UpperCase(id)
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, id, Base.Setter, accessor_args)
setter_name = '_baseSet' + UpperCase(id)
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, id, Base.Setter, accessor_args)
######################################################
# Create testers
if prop['type'] == 'group_type':
# No testters
pass
elif prop['type'] == 'content':
# XXX This approach is wrong because testers for all properties
# should be created upfront rather than on demand
accessor_args = (prop['type'], prop.get('storage_id'))
tester_name = 'has' + UpperCase(id)
if not hasattr(property_holder, tester_name) or prop.get('override', 0):
property_holder.registerAccessor(tester_name, id, Content.Tester, accessor_args)
property_holder.declareProtected(read_permission, tester_name)
else:
accessor_args = (prop['type'], prop.get('storage_id'))
tester_name = 'has' + UpperCase(id)
if not hasattr(property_holder, tester_name) or prop.get('override', 0):
property_holder.registerAccessor(tester_name, id, Base.Tester, accessor_args)
property_holder.declareProtected(read_permission, tester_name)
tester_name = '_baseHas' + UpperCase(id)
if not hasattr(property_holder, tester_name) or prop.get('override', 0):
property_holder.registerAccessor(tester_name, id, Base.Tester, accessor_args)
# List Tester
tester_name = 'has' + UpperCase(id) + 'List'
if not hasattr(property_holder, tester_name) or prop.get('override', 0):
property_holder.registerAccessor(tester_name, id, List.Tester, accessor_args)
property_holder.declareProtected(read_permission, tester_name)
tester_name = '_baseHas' + UpperCase(id) + 'List'
if not hasattr(property_holder, tester_name) or prop.get('override', 0):
property_holder.registerAccessor(tester_name, id, List.Tester, accessor_args)
tester_name = 'hasDefault' + UpperCase(id)
if not hasattr(property_holder, tester_name) or prop.get('override', 0):
property_holder.registerAccessor(tester_name, id, List.Tester, accessor_args)
property_holder.declareProtected(read_permission, tester_name)
tester_name = '_baseHasDefault' + UpperCase(id)
if not hasattr(property_holder, tester_name) or prop.get('override', 0):
property_holder.registerAccessor(tester_name, id, List.Tester, accessor_args)
# First Implementation of Boolean Accessor
tester_name = 'is' + UpperCase(id)
if not hasattr(property_holder, tester_name) or prop.get('override', 0):
property_holder.registerAccessor(tester_name, id, Base.Getter,
(prop['type'], prop.get('default'), prop.get('storage_id')))
property_holder.declareProtected(read_permission, tester_name)
tester_name = '_baseIs' + UpperCase(id)
if not hasattr(property_holder, tester_name) or prop.get('override', 0):
property_holder.registerAccessor(tester_name, id, Base.Getter,
(prop['type'], prop.get('default'), prop.get('storage_id')))
from Accessor import Category
def createCategoryAccessors(property_holder, id,
read_permission=Permissions.AccessContentsInformation,
write_permission=Permissions.ModifyPortalContent):
"""
This function creates category accessor and setter for a class
and a property
"""
accessor_name = 'get' + UpperCase(id) + 'List'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Category.ListGetter, ())
property_holder.declareProtected(read_permission, accessor_name)
accessor_name = '_categoryGet' + UpperCase(id) + 'List'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Category.ListGetter, ())
accessor_name = 'get' + UpperCase(id) + 'Set'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Category.SetGetter, ())
property_holder.declareProtected(read_permission, accessor_name)
accessor_name = '_categoryGet' + UpperCase(id) + 'Set'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Category.SetGetter, ())
accessor_name = 'get' + UpperCase(id) + 'ItemList'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Category.ItemListGetter, ())
property_holder.declareProtected(read_permission, accessor_name)
accessor_name = 'getDefault' + UpperCase(id)
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Category.DefaultGetter, ())
property_holder.declareProtected(read_permission, accessor_name)
accessor_name = '_categoryGetDefault' + UpperCase(id)
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Category.DefaultGetter, ())
accessor_name = 'get' + UpperCase(id)
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Category.DefaultGetter, ())
property_holder.declareProtected(read_permission, accessor_name)
accessor_name = '_categoryGet' + UpperCase(id)
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Category.DefaultGetter, ())
accessor_name = 'has' + UpperCase(id)
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Category.Tester, ())
property_holder.declareProtected(read_permission, accessor_name)
setter_name = 'set' + UpperCase(id)
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, '_' + setter_name, Alias.Reindex, ())
property_holder.declareProtected(write_permission, setter_name)
setter_name = 'set' + UpperCase(id) + 'List'
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, '_' + setter_name, Alias.Reindex, ())
property_holder.declareProtected(write_permission, setter_name)
setter_name = 'setDefault' + UpperCase(id)
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, '_' + setter_name, Alias.Reindex, ())
property_holder.declareProtected(write_permission, setter_name)
setter_name = 'set' + UpperCase(id) + 'Set'
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, '_' + setter_name, Alias.Reindex, ())
property_holder.declareProtected(write_permission, setter_name)
accessor_args = ()
setter_name = '_set' + UpperCase(id)
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, id, Category.Setter, accessor_args)
setter_name = '_categorySet' + UpperCase(id)
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, id, Category.Setter, accessor_args)
setter_name = '_set' + UpperCase(id) + 'List'
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, id, Category.ListSetter, accessor_args)
setter_name = '_categorySet' + UpperCase(id) + 'List'
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, id, Category.ListSetter, accessor_args)
setter_name = '_set' + UpperCase(id) + 'Set'
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, id, Category.SetSetter, accessor_args)
setter_name = '_categorySet' + UpperCase(id) + 'Set'
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, id, Category.SetSetter, accessor_args)
setter_name = '_setDefault' + UpperCase(id)
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, id, Category.DefaultSetter, accessor_args)
setter_name = '_categorySetDefault' + UpperCase(id)
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, id, Category.DefaultSetter, accessor_args)
from Accessor import Value, Related, RelatedValue, Translation
def createValueAccessors(property_holder, id,
read_permission=Permissions.AccessContentsInformation,
write_permission=Permissions.ModifyPortalContent):
"""
Creates relation accessors for category id
"""
accessor_name = 'get' + UpperCase(id) + 'ValueList'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.ListGetter, ())
property_holder.declareProtected(read_permission, accessor_name)
accessor_name = '_categoryGet' + UpperCase(id) + 'ValueList'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.ListGetter, ())
accessor_name = UpperCase(id) + 'Values'
accessor_name = string.lower(accessor_name[0]) + accessor_name[1:]
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.ListGetter, ())
property_holder.declareProtected(read_permission, accessor_name)
accessor_name = 'get' + UpperCase(id) + 'ValueSet'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.SetGetter, ())
property_holder.declareProtected(read_permission, accessor_name)
accessor_name = '_categoryGet' + UpperCase(id) + 'ValueSet'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.SetGetter, ())
accessor_name = 'get' + UpperCase(id) + 'TitleList'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.TitleListGetter, ())
property_holder.declareProtected(read_permission, accessor_name)
accessor_name = '_categoryGet' + UpperCase(id) + 'TitleList'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.TitleListGetter, ())
accessor_name = 'get' + UpperCase(id) + 'TitleSet'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.TitleSetGetter, ())
property_holder.declareProtected(read_permission, accessor_name)
accessor_name = '_categoryGet' + UpperCase(id) + 'TitleSet'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.TitleSetGetter, ())
accessor_name = 'get' + UpperCase(id) + 'TranslatedTitleList'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.TranslatedTitleListGetter, ())
property_holder.declareProtected(read_permission, accessor_name)
accessor_name = '_categoryGet' + UpperCase(id) + 'TranslatedTitleList'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.TranslatedTitleListGetter, ())
accessor_name = 'get' + UpperCase(id) + 'TranslatedTitleSet'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.TranslatedTitleSetGetter, ())
property_holder.declareProtected(read_permission, accessor_name)
accessor_name = '_categoryGet' + UpperCase(id) + 'TranslatedTitleSet'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.TranslatedTitleSetGetter, ())
accessor_name = 'get' + UpperCase(id) + 'ReferenceList'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.ReferenceListGetter, ())
property_holder.declareProtected(read_permission, accessor_name)
accessor_name = '_categoryGet' + UpperCase(id) + 'ReferenceList'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.ReferenceListGetter, ())
accessor_name = 'get' + UpperCase(id) + 'ReferenceSet'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.ReferenceSetGetter, ())
property_holder.declareProtected(read_permission, accessor_name)
accessor_name = '_categoryGet' + UpperCase(id) + 'ReferenceSet'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.ReferenceSetGetter, ())
accessor_name = 'get' + UpperCase(id) + 'IdList'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.IdListGetter, ())
property_holder.declareProtected(read_permission, accessor_name)
accessor_name = '_categoryGet' + UpperCase(id) + 'IdList'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.IdListGetter, ())
accessor_name = UpperCase(id) + 'Ids'
accessor_name = string.lower(accessor_name[0]) + accessor_name[1:]
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.IdListGetter, ())
property_holder.declareProtected(read_permission, accessor_name)
accessor_name = 'get' + UpperCase(id) + 'IdSet'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.IdSetGetter, ())
property_holder.declareProtected(read_permission, accessor_name)
accessor_name = '_categoryGet' + UpperCase(id) + 'IdSet'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.IdSetGetter, ())
accessor_name = 'get' + UpperCase(id) + 'LogicalPathList'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.LogicalPathListGetter, ())
property_holder.declareProtected(read_permission, accessor_name)
accessor_name = '_categoryGet' + UpperCase(id) + 'LogicalPathList'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.LogicalPathListGetter, ())
accessor_name = 'get' + UpperCase(id) + 'LogicalPathSet'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.LogicalPathSetGetter, ())
property_holder.declareProtected(read_permission, accessor_name)
accessor_name = '_categoryGet' + UpperCase(id) + 'LogicalPathSet'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.LogicalPathSetGetter, ())
accessor_name = 'get' + UpperCase(id) + 'UidList'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.UidListGetter, ())
property_holder.declareProtected(read_permission, accessor_name)
accessor_name = '_categoryGet' + UpperCase(id) + 'UidList'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.UidListGetter, ())
accessor_name = 'get' + UpperCase(id) + 'UidSet'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.UidSetGetter, ())
property_holder.declareProtected(read_permission, accessor_name)
accessor_name = '_categoryGet' + UpperCase(id) + 'UidSet'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.UidSetGetter, ())
accessor_name = 'get' + UpperCase(id) + 'PropertyList'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.PropertyListGetter, ())
property_holder.declareProtected(read_permission, accessor_name)
accessor_name = '_categoryGet' + UpperCase(id) + 'PropertyList'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.PropertyListGetter, ())
accessor_name = 'get' + UpperCase(id) + 'PropertySet'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.PropertySetGetter, ())
property_holder.declareProtected(read_permission, accessor_name)
accessor_name = '_categoryGet' + UpperCase(id) + 'PropertySet'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.PropertySetGetter, ())
accessor_name = 'getDefault' + UpperCase(id) + 'Value'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.DefaultGetter, ())
property_holder.declareProtected(read_permission, accessor_name)
accessor_name = '_categoryGetDefault' + UpperCase(id) + 'Value'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.DefaultGetter, ())
accessor_name = 'get' + UpperCase(id) + 'Value'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.DefaultGetter, ())
property_holder.declareProtected(read_permission, accessor_name)
accessor_name = '_categoryGet' + UpperCase(id) + 'Value'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.DefaultGetter, ())
accessor_name = 'getDefault' + UpperCase(id) + 'Title'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.DefaultTitleGetter, ())
property_holder.declareProtected(read_permission, accessor_name)
accessor_name = 'get' + UpperCase(id) + 'Title'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.DefaultTitleGetter, ())
property_holder.declareProtected(read_permission, accessor_name)
accessor_name = '_categoryGetDefault' + UpperCase(id) + 'Title'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.DefaultTitleGetter, ())
accessor_name = '_categoryGet' + UpperCase(id) + 'Title'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.DefaultTitleGetter, ())
accessor_name = 'getDefault' + UpperCase(id) + 'TranslatedTitle'
accessor = Value.DefaultTranslatedTitleGetter(accessor_name, id)
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.DefaultTranslatedTitleGetter, ())
property_holder.declareProtected(read_permission, accessor_name)
accessor_name = 'get' + UpperCase(id) + 'TranslatedTitle'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.DefaultTranslatedTitleGetter, ())
property_holder.declareProtected(read_permission, accessor_name)
accessor_name = '_categoryGetDefault' + UpperCase(id) + 'TranslatedTitle'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.DefaultTranslatedTitleGetter, ())
accessor_name = '_categoryGet' + UpperCase(id) + 'TranslatedTitle'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.DefaultTranslatedTitleGetter, ())
accessor_name = 'getDefault' + UpperCase(id) + 'Reference'
accessor = Value.DefaultReferenceGetter(accessor_name, id)
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.DefaultReferenceGetter, ())
property_holder.declareProtected(read_permission, accessor_name)
accessor_name = 'get' + UpperCase(id) + 'Reference'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.DefaultReferenceGetter, ())
property_holder.declareProtected(read_permission, accessor_name)
accessor_name = '_categoryGetDefault' + UpperCase(id) + 'Reference'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.DefaultReferenceGetter, ())
accessor_name = '_categoryGet' + UpperCase(id) + 'Reference'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.DefaultReferenceGetter, ())
accessor_name = 'getDefault' + UpperCase(id) + 'Uid'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.DefaultUidGetter, ())
property_holder.declareProtected(read_permission, accessor_name)
accessor_name = 'get' + UpperCase(id) + 'Uid'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.DefaultUidGetter, ())
property_holder.declareProtected(read_permission, accessor_name)
accessor_name = '_categoryGetDefault' + UpperCase(id) + 'Uid'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.DefaultUidGetter, ())
accessor_name = '_categoryGet' + UpperCase(id) + 'Uid'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.DefaultUidGetter, ())
accessor_name = 'getDefault' + UpperCase(id) + 'Id'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.DefaultIdGetter, ())
property_holder.declareProtected(read_permission, accessor_name)
accessor_name = 'get' + UpperCase(id) + 'Id'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.DefaultIdGetter, ())
property_holder.declareProtected(read_permission, accessor_name)
accessor_name = '_categoryGetDefault' + UpperCase(id) + 'Id'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.DefaultIdGetter, ())
accessor_name = '_categoryGet' + UpperCase(id) + 'Id'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.DefaultIdGetter, ())
accessor_name = 'getDefault' + UpperCase(id) + 'TitleOrId'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.DefaultTitleOrIdGetter, ())
property_holder.declareProtected(read_permission, accessor_name)
accessor_name = 'get' + UpperCase(id) + 'TitleOrId'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.DefaultTitleOrIdGetter, ())
property_holder.declareProtected(read_permission, accessor_name)
accessor_name = '_categoryGetDefault' + UpperCase(id) + 'TitleOrId'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.DefaultTitleOrIdGetter, ())
accessor_name = '_categoryGet' + UpperCase(id) + 'TitleOrId'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.DefaultTitleOrIdGetter, ())
accessor_name = 'getDefault' + UpperCase(id) + 'Property'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.DefaultPropertyGetter, ())
property_holder.declareProtected(read_permission, accessor_name)
accessor_name = 'get' + UpperCase(id) + 'Property'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.DefaultPropertyGetter, ())
property_holder.declareProtected(read_permission, accessor_name)
accessor_name = '_categoryGetDefault' + UpperCase(id) + 'Property'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.DefaultPropertyGetter, ())
accessor_name = '_categoryGet' + UpperCase(id) + 'Property'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.DefaultPropertyGetter, ())
accessor_name = 'getDefault' + UpperCase(id) + 'LogicalPath'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.DefaultLogicalPathGetter, ())
property_holder.declareProtected(read_permission, accessor_name)
accessor_name = 'get' + UpperCase(id) + 'LogicalPath'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.DefaultLogicalPathGetter, ())
property_holder.declareProtected(read_permission, accessor_name)
accessor_name = 'get' + UpperCase(id) + 'TranslatedLogicalPath'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.DefaultTranslatedLogicalPathGetter, ())
property_holder.declareProtected(read_permission, accessor_name)
accessor_name = '_categoryGetDefault' + UpperCase(id) + 'LogicalPath'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.DefaultLogicalPathGetter, ())
accessor_name = '_categoryGet' + UpperCase(id) + 'LogicalPath'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.DefaultLogicalPathGetter, ())
accessor_name = '_categoryGet' + UpperCase(id) + 'TranslatedLogicalPath'
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, Value.DefaultTranslatedLogicalPathGetter, ())
setter_name = 'set' + UpperCase(id) + 'Value'
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, '_' + setter_name, Alias.Reindex, ())
property_holder.declareProtected(write_permission, setter_name)
setter_name = 'set' + UpperCase(id) + 'ValueList'
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, '_' + setter_name, Alias.Reindex, ())
property_holder.declareProtected(write_permission, setter_name)
setter_name = 'set' + UpperCase(id) + 'ValueSet'
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, '_' + setter_name, Alias.Reindex, ())
property_holder.declareProtected(write_permission, setter_name)
setter_name = 'setDefault' + UpperCase(id) + 'Value'
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, '_' + setter_name, Alias.Reindex, ())
property_holder.declareProtected(write_permission, setter_name)
accessor_args = ()
setter_name = '_set' + UpperCase(id) + 'Value'
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, id, Value.Setter, accessor_args)
setter_name = '_categorySet' + UpperCase(id) + 'Value'
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, id, Value.Setter, accessor_args)
setter_name = '_set' + UpperCase(id) + 'ValueList'
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, id, Value.ListSetter, accessor_args)
setter_name = '_categorySet' + UpperCase(id) + 'ValueList'
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, id, Value.ListSetter, accessor_args)
setter_name = '_set' + UpperCase(id) + 'ValueSet'
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, id, Value.SetSetter, accessor_args)
setter_name = '_categorySet' + UpperCase(id) + 'ValueSet'
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, id, Value.SetSetter, accessor_args)
setter_name = '_setDefault' + UpperCase(id) + 'Value'
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, id, Value.DefaultSetter, accessor_args)
setter_name = '_categorySetDefault' + UpperCase(id) + 'Value'
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, id, Value.DefaultSetter, accessor_args)
# Uid setters
setter_name = 'set' + UpperCase(id) + 'Uid'
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, '_' + setter_name, Alias.Reindex, ())
property_holder.declareProtected(write_permission, setter_name)
setter_name = 'setDefault' + UpperCase(id) + 'Uid'
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, '_' + setter_name, Alias.Reindex, ())
property_holder.declareProtected(write_permission, setter_name)
setter_name = 'set' + UpperCase(id) + 'UidList'
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, '_' + setter_name, Alias.Reindex, ())
property_holder.declareProtected(write_permission, setter_name)
setter_name = 'set' + UpperCase(id) + 'UidSet'
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, '_' + setter_name, Alias.Reindex, ())
property_holder.declareProtected(write_permission, setter_name)
setter_name = '_set' + UpperCase(id) + 'Uid'
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, id, Value.UidSetter, accessor_args)
setter_name = '_categorySet' + UpperCase(id) + 'Uid'
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, id, Value.UidSetter, accessor_args)
setter_name = '_setDefault' + UpperCase(id) + 'Uid'
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, id, Value.UidDefaultSetter, accessor_args)
setter_name = '_categorySetDefault' + UpperCase(id) + 'Uid'
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, id, Value.UidDefaultSetter, accessor_args)
setter_name = '_set' + UpperCase(id) + 'UidList'
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, id, Value.UidListSetter, accessor_args)
setter_name = '_categorySet' + UpperCase(id) + 'UidList'
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, id, Value.UidListSetter, accessor_args)
setter_name = '_set' + UpperCase(id) + 'UidSet'
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, id, Value.UidSetSetter, accessor_args)
setter_name = '_categorySet' + UpperCase(id) + 'UidSet'
if not hasattr(property_holder, setter_name):
property_holder.registerAccessor(setter_name, id, Value.UidSetSetter, accessor_args)
def createRelatedValueAccessors(property_holder, id, read_permission=Permissions.AccessContentsInformation):
upper_case_id = UpperCase(id)
# Related Values (ie. reverse relation getters)
# AccessorClass: (accessor_name, )
accessor_dict = {
# List getter
RelatedValue.ListGetter: (
'%s%sRelatedValues' % (upper_case_id[0].lower(),
upper_case_id[1:]),
'get%sRelatedValueList' % upper_case_id,
'_categoryGet%sRelatedValueList' % upper_case_id,
),
# Set getter
RelatedValue.SetGetter: (
'get%sRelatedValueSet' % upper_case_id,
'_categoryGet%sRelatedValueSet' % upper_case_id,
),
# Default value getter
RelatedValue.DefaultGetter: (
'getDefault%sRelatedValue' % upper_case_id,
'get%sRelatedValue' % upper_case_id,
'_categoryGetDefault%sRelatedValue' % upper_case_id,
'_categoryGet%sRelatedValue' % upper_case_id,
),
# Related Relative Url
Related.ListGetter: (
'get%sRelatedList' % upper_case_id,
'_categoryGet%sRelatedList' % upper_case_id,
),
# Related as Set
Related.SetGetter: (
'get%sRelatedSet' % upper_case_id,
'_categoryGet%sRelatedSet' % upper_case_id,
),
# Default getter
Related.DefaultGetter: (
'getDefault%sRelated' % upper_case_id,
'get%sRelated' % upper_case_id,
'_categoryGetDefault%sRelated' % upper_case_id,
'_categoryGet%sRelated' % upper_case_id,
),
# Related Ids (ie. reverse relation getters)
RelatedValue.IdListGetter: (
'%s%sRelatedIds' % (upper_case_id[0].lower(),
upper_case_id[1:]),
'get%sRelatedIdList' % upper_case_id,
'_categoryGet%sRelatedIdList' % upper_case_id,
),
# Related Ids as Set
RelatedValue.IdSetGetter: (
'get%sRelatedIdSet' % upper_case_id,
'_categoryGet%sRelatedIdSet' % upper_case_id,
),
# Default Id getter
RelatedValue.DefaultIdGetter: (
'getDefault%sRelatedId' % upper_case_id,
'get%sRelatedId' % upper_case_id,
'_categoryGetDefault%sRelatedId' % upper_case_id,
'_categoryGet%sRelatedId' % upper_case_id,
),
# Related Title list
RelatedValue.TitleListGetter: (
'get%sRelatedTitleList' % upper_case_id,
'_categoryGet%sRelatedTitleList' % upper_case_id,
),
# Related Title Set
RelatedValue.TitleSetGetter: (
'get%sRelatedTitleSet' % upper_case_id,
'_categoryGet%sRelatedTitleSet' % upper_case_id,
),
# Related default title
RelatedValue.DefaultTitleGetter: (
'getDefault%sRelatedTitle' % upper_case_id,
'get%sRelatedTitle' % upper_case_id,
'_categoryGetDefault%sRelatedTitle' % upper_case_id,
'_categoryGet%sRelatedTitle' % upper_case_id,
),
# Related Property list
RelatedValue.PropertyListGetter: (
'get%sRelatedPropertyList' % upper_case_id,
'_categoryGet%sRelatedPropertyList' % upper_case_id,
),
# Related Property Set
RelatedValue.PropertySetGetter: (
'get%sRelatedPropertySet' % upper_case_id,
'_categoryGet%sRelatedPropertySet' % upper_case_id,
),
# Related default title
RelatedValue.DefaultPropertyGetter: (
'getDefault%sRelatedProperty' % upper_case_id,
'get%sRelatedProperty' % upper_case_id,
'_categoryGetDefault%sRelatedProperty' % upper_case_id,
'_categoryGet%sRelatedProperty' % upper_case_id,
),
}
for accessor_class, accessor_name_list in accessor_dict.items():
for accessor_name in accessor_name_list:
if property_holder is not None:
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, accessor_class, ())
if accessor_name[0] != '_':
property_holder.declareProtected(read_permission, accessor_name)
else:
accessor = accessor_class(accessor_name, id)
if not hasattr(BaseClass, accessor_name):
setattr(BaseClass, accessor_name,
accessor.dummy_copy(accessor_name))
# Declare the security of method which doesn't start with _
if accessor_name[0] != '_':
BaseClass.security.declareProtected(read_permission, accessor_name)
def createGroupTypeAccessors(property_holder, prop,
read_permission=None, portal=None):
"""
Generate accessors that allows to know if we belongs to a particular
group of portal types
"""
raise ValueError("This method is not used. Remove it?")
# Getter
group = prop['group_type']
accessor_name = 'is' + UpperCase(group) + 'Type'
value = prop['default']
accessor_args = (value,)
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name, id, ConstantGetter,
accessor_args)
property_holder.declareProtected(read_permission, accessor_name)
def createTranslationAcquiredPropertyAccessors(
property_holder,
property,
read_permission=Permissions.AccessContentsInformation,
write_permission=Permissions.ModifyPortalContent,
portal=None):
"""Generate translation acquired property accessor to Base class"""
property = property.copy()
translation_acquired_property_id_list = []
accessor_dict_list = []
# Language Dependent Getter/Setter
for language in portal.Localizer.get_languages():
language_key = language.replace('-', '_')
for acquired_property_id in property['acquired_property_id']:
key = '%s_translated_%s' % (language_key, acquired_property_id)
capitalised_composed_id = UpperCase("%s_%s" % (property['id'], key))
accessor_args = (
property['type'],
property['portal_type'],
key,
property['acquisition_base_category'],
property['acquisition_portal_type'],
property['acquisition_accessor_id'],
property.get('acquisition_copy_value',0),
property.get('acquisition_mask_value',0),
property.get('storage_id'),
property.get('alt_accessor_id'),
property.get('acquisition_object_id'),
(property['type'] in list_types or property.get('multivalued', 0)),
(property['type'] == 'tales'),
)
accessor_dict_list.append({'name':'get' + capitalised_composed_id,
'key': key,
'class':Translation.AcquiredPropertyGetter,
'argument':accessor_args,
'permission':read_permission})
accessor_dict_list.append({'name':'_baseGet' + capitalised_composed_id,
'key': key,
'class':Translation.AcquiredPropertyGetter,
'argument':accessor_args,
'permission':read_permission})
accessor_dict_list.append({'name': 'getDefault' + capitalised_composed_id,
'key': key,
'class': Translation.AcquiredPropertyGetter,
'argument': accessor_args,
'permission': read_permission})
accessor_dict_list.append({'name': 'set' + capitalised_composed_id,
'key': '_set' + capitalised_composed_id,
'class': Alias.Reindex,
'argument': (),
'permission': write_permission})
accessor_dict_list.append({'name': '_set' + capitalised_composed_id,
'key': key,
'class': AcquiredProperty.DefaultSetter,
'argument': accessor_args,
'permission': write_permission})
accessor_dict_list.append({'name': 'setDefault' + capitalised_composed_id,
'key': '_set' + capitalised_composed_id,
'class': Alias.Reindex,
'argument': (),
'permission': write_permission})
# Language Independent Getter
for acquired_property_id in property['acquired_property_id']:
if acquired_property_id in property.get('translation_acquired_property_id',()):
key = 'translated_%s' % acquired_property_id
capitalised_composed_id = UpperCase('%s_%s' % (property['id'], key))
accessor_args = (
property['type'],
property['portal_type'],
key,
property['acquisition_base_category'],
property['acquisition_portal_type'],
property['acquisition_accessor_id'],
property.get('acquisition_copy_value',0),
property.get('acquisition_mask_value',0),
property.get('storage_id'),
property.get('alt_accessor_id'),
property.get('acquisition_object_id'),
(property['type'] in list_types or property.get('multivalued', 0)),
(property['type'] == 'tales'),
)
accessor_dict_list.append({'name': 'get' + capitalised_composed_id,
'key': key,
'class': Translation.AcquiredPropertyGetter,
'argument': accessor_args,
'permission': read_permission})
accessor_dict_list.append({'name': '_baseGet' + capitalised_composed_id,
'key': key,
'class': Translation.AcquiredPropertyGetter,
'argument': accessor_args,
'permission': read_permission})
accessor_dict_list.append({'name': 'getDefault' + capitalised_composed_id,
'key': key,
'class': Translation.AcquiredPropertyGetter,
'argument': accessor_args,
'permission': read_permission})
for accessor_dict in accessor_dict_list:
accessor_name = accessor_dict['name']
if getattr(property_holder, accessor_name, None) is None:
property_holder.registerAccessor(accessor_name, # id
accessor_dict['key'],
accessor_dict['class'],
accessor_dict['argument'])
property_holder.declareProtected(accessor_dict['permission'],
accessor_name)
def createTranslationAccessors(property_holder, id, property,
read_permission=Permissions.AccessContentsInformation,
write_permission=Permissions.ModifyPortalContent, default=''):
"""
Generate the translation accessor for a class and a property
"""
capitalised_id = UpperCase(id)
if 'translated' in id:
accessor_name = 'get' + capitalised_id
private_accessor_name = '_baseGet' + capitalised_id
if not hasattr(property_holder, accessor_name):
property_holder.registerAccessor(accessor_name,
id,
Translation.TranslatedPropertyGetter,
(property['id'], property['type'], None, default))
property_holder.declareProtected(read_permission, accessor_name)
if not hasattr(property_holder, private_accessor_name):
property_holder.registerAccessor(private_accessor_name,
id,
Translation.TranslatedPropertyGetter,
(property['id'], property['type'], None, default))
if 'translation_domain' in id:
# Getter
accessor_name = 'get' + capitalised_id
property_holder.registerAccessor(accessor_name,
id,
Translation.PropertyTranslationDomainGetter,
('string', default,))
property_holder.declareProtected(read_permission, accessor_name)
def createTranslationLanguageAccessors(property_holder, property,
read_permission=Permissions.AccessContentsInformation,
write_permission=Permissions.ModifyPortalContent, default='',
portal=None):
"""
Generate translation language accessors
"""
accessor_dict_list = []
localizer = getattr(portal, 'Localizer', None)
if localizer is None:
if not getattr(portal, '_v_bootstrapping', False):
warnings.warn("Localizer is missing. Accessors can not be generated.")
return
for language in localizer.get_languages():
language_key = language.replace('-', '_')
composed_id = '%s_translated_%s' % (language_key, property['id'])
capitalised_compose_id = UpperCase(composed_id)
# get
getter_accessor_args = (property['id'], property['type'], language, default)
accessor_dict_list.append({'name': 'get' + capitalised_compose_id,
'class': Translation.TranslatedPropertyGetter,
'argument': getter_accessor_args,
'permission': read_permission})
accessor_dict_list.append({'name': '_baseGet' + capitalised_compose_id,
'class': Translation.TranslatedPropertyGetter,
'argument': getter_accessor_args,
'permission': read_permission})
# has
has_accessor_args = (property['id'], property['type'], language)
accessor_dict_list.append({'name': 'has' + capitalised_compose_id,
'class': Translation.TranslatedPropertyTester,
'argument': has_accessor_args,
'permission': read_permission})
# set
accessor_dict_list.append({'name':'set' + capitalised_compose_id,
'key': '_set' + capitalised_compose_id,
'class': Alias.Reindex,
'argument': (),
'permission': write_permission})
setter_accessor_args = (property['id'], property['type'], language)
accessor_dict_list.append({'name': '_set' + capitalised_compose_id,
'class': Translation.TranslationPropertySetter,
'argument': setter_accessor_args,
'permission': write_permission})
for accessor_dict in accessor_dict_list:
accessor_name = accessor_dict['name']
if getattr(property_holder, accessor_name, None) is None:
property_holder.registerAccessor(accessor_name,
accessor_dict.get('key', None),
accessor_dict['class'],
accessor_dict['argument'])
property_holder.declareProtected(accessor_dict['permission'],
accessor_name)
from zope.tales.tales import CompilerError
def evaluateExpressionFromString(expression_context, expression_string):
......@@ -2979,6 +1311,7 @@ def evaluateExpressionFromString(expression_context, expression_string):
#####################################################
# More Useful methods which require Base
#####################################################
from Products.ERP5Type.Base import Base as BaseClass
def assertAttributePortalType(o, attribute_name, portal_type):
"""
......
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