[Erp5-report] r17639 - /erp5/trunk/products/ERP5Type/Accessor/List.py

nobody at svn.erp5.org nobody at svn.erp5.org
Thu Nov 15 18:26:58 CET 2007


Author: jp
Date: Thu Nov 15 18:26:57 2007
New Revision: 17639

URL: http://svn.erp5.org?rev=17639&view=rev
Log:
Proposed patch to solve the problem of tales expressions passed as default value.

Modified:
    erp5/trunk/products/ERP5Type/Accessor/List.py

Modified: erp5/trunk/products/ERP5Type/Accessor/List.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Accessor/List.py?rev=17639&r1=17638&r2=17639&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Accessor/List.py (original)
+++ erp5/trunk/products/ERP5Type/Accessor/List.py Thu Nov 15 18:26:57 2007
@@ -210,56 +210,6 @@
     func_code.co_argcount = 1
     func_defaults = ()
 
-    def __init__(self, id, key, property_type, default = None, storage_id=None):
-      self._id = id
-      self.__name__ = id
-      self._key = key
-      self._property_type = property_type
-      self._null = type_definition[property_type]['null']
-      self._default = default
-      if storage_id is None:
-        storage_id = "%s%s" % (ATTRIBUTE_PREFIX, key)
-      self._storage_id = storage_id
-      self._is_tales_type = (property_type == 'tales')
-
-    def __call__(self, instance, *args, **kw):
-      if len(args) > 0:
-        default = args[0]
-      else:
-        default = self._default
-        if default and len(default):
-          default = default[0]
-        else:
-          default = None
-      list_value = getattr(instance, self._storage_id, None)
-      if list_value is not None:
-        if self._is_tales_type:
-          if kw.get('evaluate', 1):
-            list_value = evaluateTales(instance=instance, value=list_value)
-          else:
-            return list_value
-        if len(list_value) > 0:
-          return list_value[0]
-      return default
-
-    psyco.bind(__call__)
-
-Getter = DefaultGetter
-
-class ListGetter(Method):
-    """
-      Gets an attribute value. A default value can be
-      provided if needed
-    """
-    _need__name__=1
-
-    # Generic Definition of Method Object
-    # This is required to call the method form the Web
-    func_code = func_code()
-    func_code.co_varnames = ('self',)
-    func_code.co_argcount = 1
-    func_defaults = ()
-
     def __init__(self, id, key, property_type, default=None, storage_id=None):
       self._id = id
       self.__name__ = id
@@ -277,7 +227,55 @@
         default = args[0]
       else:
         default = self._default
-      list_value = getattr(aq_base(instance), self._storage_id, None)
+      list_value = getattr(instance, self._storage_id, default)
+      if list_value is not None:
+        if self._is_tales_type:
+          if kw.get('evaluate', 1):
+            list_value = evaluateTales(instance=instance, value=list_value)
+          else:
+            return list_value
+        if len(list_value) > 0:
+          return list_value[0]
+      if default and len(default):
+        return default[0]
+      return None
+
+    psyco.bind(__call__)
+
+Getter = DefaultGetter
+
+class ListGetter(Method):
+    """
+      Gets an attribute value. A default value can be
+      provided if needed
+    """
+    _need__name__=1
+
+    # Generic Definition of Method Object
+    # This is required to call the method form the Web
+    func_code = func_code()
+    func_code.co_varnames = ('self',)
+    func_code.co_argcount = 1
+    func_defaults = ()
+
+    def __init__(self, id, key, property_type, default=None, storage_id=None):
+      self._id = id
+      self.__name__ = id
+      self._key = key
+      self._property_type = property_type
+      self._null = type_definition[property_type]['null']
+      self._default = default
+      if storage_id is None:
+        storage_id = "%s%s" % (ATTRIBUTE_PREFIX, key)
+      self._storage_id = storage_id
+      self._is_tales_type = (property_type == 'tales')
+
+    def __call__(self, instance, *args, **kw):
+      if len(args) > 0:
+        default = args[0]
+      else:
+        default = self._default
+      list_value = getattr(aq_base(instance), self._storage_id, default)
       # We should not use here self._null but None instead XXX
       if list_value not in self._null:
         if self._is_tales_type:




More information about the Erp5-report mailing list