Commit 8633169a authored by Julien Muchembled's avatar Julien Muchembled

small optimizations

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@39185 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent d8e79e9d
...@@ -67,15 +67,14 @@ class Setter(Method): ...@@ -67,15 +67,14 @@ class Setter(Method):
storage_id = "%s%s" % (ATTRIBUTE_PREFIX, key) storage_id = "%s%s" % (ATTRIBUTE_PREFIX, key)
self._storage_id = storage_id self._storage_id = storage_id
def __call__(self, instance, *args, **kw): def __call__(self, instance, value, *args, **kw):
value = args[0]
modified_object_list = [] modified_object_list = []
# Modify the property # Modify the property
if value in self._null: if value in self._null:
setattr(instance, self._storage_id, None) setattr(instance, self._storage_id, None)
elif self._property_type == 'content': elif self._property_type == 'content':
# A file object should be provided # A file object should be provided
file_upload = args[0] file_upload = value
if isinstance(file_upload, FileUpload) or \ if isinstance(file_upload, FileUpload) or \
getattr(aq_base(value), 'tell', None) is not None: getattr(aq_base(value), 'tell', None) is not None:
# When editing through the web interface, we are always provided a # When editing through the web interface, we are always provided a
...@@ -100,7 +99,7 @@ class Setter(Method): ...@@ -100,7 +99,7 @@ class Setter(Method):
LOG('ERP5Type WARNING', 0, '%s is not a file like object' LOG('ERP5Type WARNING', 0, '%s is not a file like object'
% str(file_upload)) % str(file_upload))
else: else:
setattr(instance, self._storage_id, self._cast(args[0])) setattr(instance, self._storage_id, self._cast(value))
modified_object_list.append(instance) modified_object_list.append(instance)
return modified_object_list return modified_object_list
...@@ -123,17 +122,14 @@ class Setter(Method): ...@@ -123,17 +122,14 @@ class Setter(Method):
# if roles has an __of__ method, call it explicitly, as the Method # if roles has an __of__ method, call it explicitly, as the Method
# already has an __of__ method that has been already called at this # already has an __of__ method that has been already called at this
# point. # point.
roles = getattr(roles, '__of__', lambda aq_parent: roles)(im_self) return getattr(roles, '__of__', lambda aq_parent: roles)(im_self)
return roles
from Products.CMFCore.Expression import Expression from Products.CMFCore.Expression import Expression
def _evaluateTales(instance=None, value=None): def _evaluateTales(instance=None, value=None):
from Products.ERP5Type.Utils import createExpressionContext from Products.ERP5Type.Utils import createExpressionContext
__traceback_info__ = (instance, value) __traceback_info__ = (instance, value)
expression = Expression(value) return Expression(value)(createExpressionContext(instance))
econtext = createExpressionContext(instance)
return expression(econtext)
evaluateTales = CachingMethod(_evaluateTales, id = 'evaluateTales', cache_factory='erp5_content_short') evaluateTales = CachingMethod(_evaluateTales, id = 'evaluateTales', cache_factory='erp5_content_short')
...@@ -170,10 +166,6 @@ class Getter(Method): ...@@ -170,10 +166,6 @@ class Getter(Method):
self._is_tales_type = (property_type == 'tales') self._is_tales_type = (property_type == 'tales')
def __call__(self, instance, *args, **kw): def __call__(self, instance, *args, **kw):
if len(args) > 0:
default = args[0]
else:
default = self._default
# No acquisition on properties but inheritance. # No acquisition on properties but inheritance.
# Instead of using getattr, which use inheritance from SuperClass # Instead of using getattr, which use inheritance from SuperClass
# why not use __dict__.get directly ? # why not use __dict__.get directly ?
...@@ -184,6 +176,10 @@ class Getter(Method): ...@@ -184,6 +176,10 @@ class Getter(Method):
return evaluateTales(instance, value) return evaluateTales(instance, value)
else: else:
return value return value
if args:
default = args[0]
else:
default = self._default
if self._is_tales_type and default is not None and kw.get('evaluate', 1): if self._is_tales_type and default is not None and kw.get('evaluate', 1):
return evaluateTales(instance, default) return evaluateTales(instance, default)
return default return default
...@@ -203,8 +199,7 @@ class Getter(Method): ...@@ -203,8 +199,7 @@ class Getter(Method):
if roles is None: if roles is None:
return rolesForPermissionOn(None, im_self, ('Manager',), return rolesForPermissionOn(None, im_self, ('Manager',),
'_Access_contents_information_Permission') '_Access_contents_information_Permission')
roles = getattr(roles, '__of__', lambda aq_parent: roles)(im_self) return getattr(roles, '__of__', lambda aq_parent: roles)(im_self)
return roles
class Tester(Method): class Tester(Method):
......
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