Commit 044311fd authored by Nicolas Dumazet's avatar Nicolas Dumazet

coding style/cleanup only


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@41739 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent e7be2a3d
...@@ -1273,6 +1273,13 @@ def getExistingBaseCategoryList(portal, base_cat_list): ...@@ -1273,6 +1273,13 @@ def getExistingBaseCategoryList(portal, base_cat_list):
new_base_cat_list.append(base_cat) new_base_cat_list.append(base_cat)
return tuple(new_base_cat_list) return tuple(new_base_cat_list)
default_translation_property_dict = {
'id' : 'translation_domain',
'description' : '',
'default' : '',
'type' : 'string',
'mode' : 'w',
}
def setDefaultProperties(property_holder, object=None, portal=None): def setDefaultProperties(property_holder, object=None, portal=None):
""" """
This methods sets default accessors for this object as well This methods sets default accessors for this object as well
...@@ -1305,10 +1312,11 @@ def setDefaultProperties(property_holder, object=None, portal=None): ...@@ -1305,10 +1312,11 @@ def setDefaultProperties(property_holder, object=None, portal=None):
for prop in property_holder.__dict__.get('_properties', []): for prop in property_holder.__dict__.get('_properties', []):
# Copy the dict so that Expression objects are not overwritten. # Copy the dict so that Expression objects are not overwritten.
prop_list.append(prop.copy()) prop_list.append(prop.copy())
cat_list = [] # Do not consider superclass _categories definition
cat_list += property_holder.__dict__.get('_categories',[]) # Do not consider superclass _categories definition cat_list = property_holder.__dict__.get('_categories', [])
constraint_list = [] # a list of declarative consistency definitions (ie. constraints) # a list of declarative consistency definitions (ie. constraints)
constraint_list += property_holder.__dict__.get('_constraints',[]) # Do not consider superclass _constraints definition # Do not consider superclass _constraints definition
constraint_list = property_holder.__dict__.get('_constraints', [])
for base in property_holder.property_sheets: for base in property_holder.property_sheets:
for prop in base._properties: for prop in base._properties:
# Copy the dict so that Expression objects are not overwritten. # Copy the dict so that Expression objects are not overwritten.
...@@ -1317,7 +1325,7 @@ def setDefaultProperties(property_holder, object=None, portal=None): ...@@ -1317,7 +1325,7 @@ def setDefaultProperties(property_holder, object=None, portal=None):
if isinstance(base._categories, (tuple, list)): if isinstance(base._categories, (tuple, list)):
cat_list += base._categories cat_list += base._categories
else: else:
cat_list += [base._categories] cat_list.append(base._categories)
if hasattr(base, '_constraints'): if hasattr(base, '_constraints'):
constraint_list += base._constraints constraint_list += base._constraints
...@@ -1339,7 +1347,7 @@ def setDefaultProperties(property_holder, object=None, portal=None): ...@@ -1339,7 +1347,7 @@ def setDefaultProperties(property_holder, object=None, portal=None):
cat_list = getExistingBaseCategoryList(portal, new_cat_list) cat_list = getExistingBaseCategoryList(portal, new_cat_list)
for const in constraint_list: for const in constraint_list:
for key,value in const.items(): for key, value in const.iteritems():
if isinstance(value, Expression): if isinstance(value, Expression):
const[key] = value(econtext) const[key] = value(econtext)
...@@ -1348,7 +1356,7 @@ def setDefaultProperties(property_holder, object=None, portal=None): ...@@ -1348,7 +1356,7 @@ def setDefaultProperties(property_holder, object=None, portal=None):
# Create default accessors for property sheets # Create default accessors for property sheets
converted_prop_list = [] converted_prop_list = []
converted_prop_keys = {} converted_prop_set = set()
for prop in prop_list: for prop in prop_list:
read_permission = prop.get('read_permission', read_permission = prop.get('read_permission',
Permissions.AccessContentsInformation) Permissions.AccessContentsInformation)
...@@ -1363,18 +1371,17 @@ def setDefaultProperties(property_holder, object=None, portal=None): ...@@ -1363,18 +1371,17 @@ def setDefaultProperties(property_holder, object=None, portal=None):
prop['type'] prop['type']
if 'base_id' in prop: if 'base_id' in prop:
continue continue
if not converted_prop_keys.has_key(prop['id']): if prop['id'] not in converted_prop_set:
if prop['type'] != 'content': if prop['type'] != 'content':
converted_prop_list += [prop] converted_prop_list.append(prop)
converted_prop_keys[prop['id']] = 1 converted_prop_set.add(prop['id'])
# Create range accessors, if this has a range. # Create range accessors, if this has a range.
if prop.get('range', 0): if prop.get('range', 0):
for value in ('min', 'max'): for value in ('min', 'max'):
range_prop = prop.copy() range_prop = prop.copy()
del range_prop['range'] del range_prop['range']
if 'storage_id' in range_prop: range_prop.pop('storage_id', None)
del range_prop['storage_id']
if range_prop.get('acquisition_accessor_id', 0): if range_prop.get('acquisition_accessor_id', 0):
range_prop['acquisition_accessor_id'] = '%sRange%s' % ( range_prop['acquisition_accessor_id'] = '%sRange%s' % (
range_prop['acquisition_accessor_id'], value.capitalize()) range_prop['acquisition_accessor_id'], value.capitalize())
...@@ -1405,27 +1412,19 @@ def setDefaultProperties(property_holder, object=None, portal=None): ...@@ -1405,27 +1412,19 @@ def setDefaultProperties(property_holder, object=None, portal=None):
portal=portal) portal=portal)
# make accessor to translation_domain # make accessor to translation_domain
# first create default one as a normal property # first create default one as a normal property
txn_prop = {} accessor_id = '%_translation_domain' % prop['id']
txn_prop['description'] = ''
txn_prop['default'] = ''
txn_prop['id'] = 'translation_domain'
txn_prop['type'] = 'string'
txn_prop['mode'] = 'w'
createDefaultAccessors( createDefaultAccessors(
property_holder, property_holder,
'%s_%s' %(prop['id'], txn_prop['id']), accessor_id,
prop=txn_prop, prop=default_translation_property_dict,
read_permission=read_permission, read_permission=read_permission,
write_permission=write_permission, write_permission=write_permission,
portal=portal) portal=portal)
# then overload accesors getPropertyTranslationDomain # then overload accesors getPropertyTranslationDomain
if prop.has_key('translation_domain'): default = prop.get('translation_domain', '')
default = prop['translation_domain']
else:
default = ''
createTranslationAccessors( createTranslationAccessors(
property_holder, property_holder,
'%s_translation_domain' % (prop['id']), accessor_id,
prop, prop,
read_permission=read_permission, read_permission=read_permission,
write_permission=write_permission, write_permission=write_permission,
...@@ -1448,7 +1447,8 @@ def setDefaultProperties(property_holder, object=None, portal=None): ...@@ -1448,7 +1447,8 @@ def setDefaultProperties(property_holder, object=None, portal=None):
'mode' : 'w' 'mode' : 'w'
} }
# XXX These are only for backward compatibility. # XXX These are only for backward compatibility.
if cat == 'group': prop['storage_id'] = 'group' if cat == 'group':
prop['storage_id'] = 'group'
elif cat == 'site': elif cat == 'site':
prop['storage_id'] = 'location' prop['storage_id'] = 'location'
createDefaultAccessors( createDefaultAccessors(
...@@ -1486,7 +1486,8 @@ def setDefaultProperties(property_holder, object=None, portal=None): ...@@ -1486,7 +1486,8 @@ def setDefaultProperties(property_holder, object=None, portal=None):
if object is not None and property_holder.__name__ == "Base": if object is not None and property_holder.__name__ == "Base":
# XXX use if possible is and real class # XXX use if possible is and real class
base_category_list = [] base_category_list = []
for cat in base_category_dict.keys(): # first extend the Tales category definitions into base_category_list
for cat in base_category_dict:
if isinstance(cat, Expression): if isinstance(cat, Expression):
result = cat(econtext) result = cat(econtext)
if isinstance(result, (list, tuple)): if isinstance(result, (list, tuple)):
...@@ -1495,6 +1496,7 @@ def setDefaultProperties(property_holder, object=None, portal=None): ...@@ -1495,6 +1496,7 @@ def setDefaultProperties(property_holder, object=None, portal=None):
base_category_list.append(result) base_category_list.append(result)
else: else:
base_category_list.append(cat) base_category_list.append(cat)
for cat in base_category_list: for cat in base_category_list:
# Get read and write permission # Get read and write permission
if portal is not None: if portal is not None:
...@@ -1515,21 +1517,21 @@ def setDefaultProperties(property_holder, object=None, portal=None): ...@@ -1515,21 +1517,21 @@ def setDefaultProperties(property_holder, object=None, portal=None):
else: else:
read_permission = Permissions.AccessContentsInformation read_permission = Permissions.AccessContentsInformation
write_permission = Permissions.ModifyPortalContent write_permission = Permissions.ModifyPortalContent
# Actualy create accessors # Actually create accessors
createRelatedValueAccessors(property_holder, cat, read_permission=read_permission) createRelatedValueAccessors(property_holder, cat, read_permission=read_permission)
# Unnecessary to create these accessors more than once. # Unnecessary to create these accessors more than once.
base_category_dict.clear() base_category_dict.clear()
from Products.ERP5Type.mixin.constraint import ConstraintMixin from Products.ERP5Type.mixin.constraint import ConstraintMixin
property_holder.constraints = [] property_holder.constraints = []
for const in constraint_list: for constraint in constraint_list:
# ZODB Property Sheets constraints are no longer defined by a # ZODB Property Sheets constraints are no longer defined by a
# dictionnary but by a ConstraintMixin, thus just append it to # dictionary but by a ConstraintMixin, thus just append it to
# the list of constraints # the list of constraints
if isinstance(const, ConstraintMixin): if isinstance(constraint, ConstraintMixin):
property_holder.constraints.append(const) property_holder.constraints.append(constraint)
else: else:
createConstraintList(property_holder, constraint_definition=const) createConstraintList(property_holder, constraint_definition=constraint)
# ERP5 _properties and Zope _properties are somehow different # ERP5 _properties and Zope _properties are somehow different
# The id is converted to the Zope standard - we keep the original id # The id is converted to the Zope standard - we keep the original id
...@@ -1546,7 +1548,7 @@ def setDefaultProperties(property_holder, object=None, portal=None): ...@@ -1546,7 +1548,7 @@ def setDefaultProperties(property_holder, object=None, portal=None):
and not prop.get('acquisition_copy_value'): and not prop.get('acquisition_copy_value'):
# Set acquisition values as read only if no value is copied # Set acquisition values as read only if no value is copied
new_prop['mode'] = 'r' new_prop['mode'] = 'r'
new_converted_prop_list += [new_prop] new_converted_prop_list.append(new_prop)
# Set the properties of the class # Set the properties of the class
property_holder._properties = tuple(new_converted_prop_list) property_holder._properties = tuple(new_converted_prop_list)
property_holder._categories = tuple(cat_list) property_holder._categories = tuple(cat_list)
...@@ -1565,7 +1567,7 @@ def setDefaultProperties(property_holder, object=None, portal=None): ...@@ -1565,7 +1567,7 @@ def setDefaultProperties(property_holder, object=None, portal=None):
#if not hasattr(property_holder, prop['id']): #if not hasattr(property_holder, prop['id']):
# setattr(property_holder, prop['id'], None) # This makes sure no acquisition will happen # setattr(property_holder, prop['id'], None) # This makes sure no acquisition will happen
# but is wrong when we use storage_id ..... # but is wrong when we use storage_id .....
storage_id = prop.get('storage_id', prop['id']) #storage_id = prop.get('storage_id', prop['id'])
#if not hasattr(BaseClass, storage_id): #if not hasattr(BaseClass, storage_id):
# setattr(property_holder, storage_id, None) # This breaks things with aq_dynamic # setattr(property_holder, storage_id, None) # This breaks things with aq_dynamic
#setattr(BaseClass, storage_id, None) # This blocks acquisition #setattr(BaseClass, storage_id, None) # This blocks acquisition
...@@ -1579,7 +1581,7 @@ def setDefaultProperties(property_holder, object=None, portal=None): ...@@ -1579,7 +1581,7 @@ def setDefaultProperties(property_holder, object=None, portal=None):
# pass # pass
# Create for every portal type group an accessor (like isPortalDeliveryType) # Create for every portal type group an accessor (like isPortalDeliveryType)
# In the future, this should probalby use categories # In the future, this should probably use categories
if portal is not None and object is not None: # we can not do anything without portal if portal is not None and object is not None: # we can not do anything without portal
# import lately in order to avoid circular dependency # import lately in order to avoid circular dependency
from Products.ERP5Type.ERP5Type import ERP5TypeInformation from Products.ERP5Type.ERP5Type import ERP5TypeInformation
......
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