Commit eff87725 authored by Yoshinori Okuji's avatar Yoshinori Okuji

Generate range accessors if a property has a range.

Rewrite convertToUpperCase and convertToMixedCase for
efficiency and simplicity.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@3057 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent bc87de82
...@@ -77,13 +77,7 @@ def convertToUpperCase(key): ...@@ -77,13 +77,7 @@ def convertToUpperCase(key):
This function turns an attribute name into This function turns an attribute name into
a method name according to the ERP5 naming conventions a method name according to the ERP5 naming conventions
""" """
result = '' return ''.join([part.capitalize() for part in str(key).split('_')])
parts = string.split(str(key),'_')
for part in parts:
letter_list = list(part)
letter_list[0] = string.upper(letter_list[0])
result = result + string.join(letter_list,'')
return result
UpperCase = convertToUpperCase UpperCase = convertToUpperCase
...@@ -92,15 +86,10 @@ def convertToMixedCase(key): ...@@ -92,15 +86,10 @@ def convertToMixedCase(key):
This function turns an attribute name into This function turns an attribute name into
a method name according to the ERP5 naming conventions a method name according to the ERP5 naming conventions
""" """
result = '' parts = str(key).split('_', 1)
parts = string.split(str(key),'_') if len(parts) == 2:
i = 0 parts[1] = convertToUpperCase(parts[1])
for part in parts: return ''.join(parts)
letter_list = list(part)
if i: letter_list[0] = string.upper(letter_list[0])
result = result + string.join(letter_list,'')
i += 1
return result
# Some set operations # Some set operations
def cartesianProduct(list_of_list): def cartesianProduct(list_of_list):
...@@ -985,6 +974,16 @@ def setDefaultProperties(klass, object=None): ...@@ -985,6 +974,16 @@ def setDefaultProperties(klass, object=None):
if not converted_prop_keys.has_key(prop['id']): if not converted_prop_keys.has_key(prop['id']):
if prop['type'] != 'content': converted_prop_list += [prop] if prop['type'] != 'content': converted_prop_list += [prop]
converted_prop_keys[prop['id']] = 1 converted_prop_keys[prop['id']] = 1
# Create range accessors, if this has a range.
if prop.get('range', 0):
for value in ('min', 'max'):
range_prop = prop.copy()
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(klass, '%s_range_%s' % (prop['id'], value), prop=range_prop)
createDefaultAccessors(klass, prop['id'], prop=prop) createDefaultAccessors(klass, prop['id'], prop=prop)
else: else:
raise TypeError, '"%s" is illegal type for propertysheet' % \ raise TypeError, '"%s" is illegal type for propertysheet' % \
......
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