[Erp5-report] r43006 nicolas.dumazet - in /erp5/trunk/products/ERP5Type: ./ dynamic/ mixin/

nobody at svn.erp5.org nobody at svn.erp5.org
Fri Feb 4 01:43:58 CET 2011


Author: nicolas.dumazet
Date: Fri Feb  4 01:43:58 2011
New Revision: 43006

URL: http://svn.erp5.org?rev=43006&view=rev
Log:
Move up all temporary-related code to a new ERP5Type mixin.

In particular, remove the hackish _set_xxx on Base

Added:
    erp5/trunk/products/ERP5Type/mixin/temporary.py
Modified:
    erp5/trunk/products/ERP5Type/Base.py
    erp5/trunk/products/ERP5Type/dynamic/portal_type_class.py

Modified: erp5/trunk/products/ERP5Type/Base.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Base.py?rev=43006&r1=43005&r2=43006&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Base.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/Base.py [utf8] Fri Feb  4 01:43:58 2011
@@ -3280,44 +3280,6 @@ class Base( CopyContainer,
     from Products.ERP5Type.Error import Error
     return Error(**kw)
 
-
-  _temp_isIndexable = 0
-
-  def _temp_reindexObject(self, *args, **kw):
-    pass
-
-  def _temp_recursiveReindexObject(self, *args, **kw):
-    pass
-
-  def _temp_activate(self, *args, **kw):
-    return self
-
-  def _temp_setUid(self, value):
-    self.uid = value # Required for Listbox so that no casting happens when we use TempBase to create new objects
-
-  def _temp_getUid(self):
-    try:
-      return getattr(aq_base(self), 'uid')
-    except AttributeError:
-      value = self.getId()
-      self.setUid(value)
-      return value
-
-  def _temp_setTitle(self, value):
-    """
-    Required so that getProperty('title') will work on tempBase objects
-    The dynamic acquisition work very well for a lot of properties, but
-    not for title. For example, if we do setProperty('organisation_url'), then
-    even if organisation_url is not in a propertySheet, the method getOrganisationUrl
-    will be generated. But this does not work for title, because I(seb)'m almost sure
-    there is somewhere a method '_setTitle' or 'setTitle' with no method getTitle on Base.
-    That why setProperty('title') and getProperty('title') does not work.
-    """
-    self.title = value
-
-  def _temp_getTitle(self):
-    return getattr(self,'title',None)
-
   security.declarePublic('log')
   def log(self, description, content='', level=INFO):
     """Put a log message """

Modified: erp5/trunk/products/ERP5Type/dynamic/portal_type_class.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/dynamic/portal_type_class.py?rev=43006&r1=43005&r2=43006&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/dynamic/portal_type_class.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/dynamic/portal_type_class.py [utf8] Fri Feb  4 01:43:58 2011
@@ -35,6 +35,8 @@ from types import ModuleType
 from dynamic_module import registerDynamicModule
 from accessor_holder import _generateBaseAccessorHolder, _generatePreferenceToolAccessorHolder
 
+
+from Products.ERP5Type.mixin.temporary import TemporaryDocumentMixin
 from Products.ERP5Type.Base import _aq_reset, Base
 from Products.ERP5Type.Globals import InitializeClass
 from Products.ERP5Type.Utils import setDefaultClassProperties
@@ -389,26 +391,8 @@ def initializeDynamicModules():
     """
     klass = getattr(portal_type_container, portal_type_name)
 
-    from Products.ERP5Type.Accessor.Constant import PropertyGetter as \
-      PropertyConstantGetter
-
-    class TempDocument(klass):
-      isTempDocument = PropertyConstantGetter('isTempDocument', value=True)
-      __roles__ = None
-    TempDocument.__name__ = "Temp " + portal_type_name
-
-    # Replace some attributes.
-    for name in ('isIndexable', 'reindexObject', 'recursiveReindexObject',
-                 'activate', 'setUid', 'setTitle', 'getTitle', 'getUid'):
-      setattr(TempDocument, name, getattr(klass, '_temp_%s' % name))
-
-    # Make some methods public.
-    for method_id in ('reindexObject', 'recursiveReindexObject',
-                      'activate', 'setUid', 'setTitle', 'getTitle',
-                      'edit', 'setProperty', 'getUid', 'setCriterion',
-                      'setCriterionPropertyList'):
-      setattr(TempDocument, '%s__roles__' % method_id, None)
-    return TempDocument
+    return type("Temporary %s" % portal_type_name,
+                (TemporaryDocumentMixin, klass), {})
 
   erp5.temp_portal_type = registerDynamicModule('erp5.temp_portal_type',
                                                 loadTempPortalTypeClass)

Added: erp5/trunk/products/ERP5Type/mixin/temporary.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/mixin/temporary.py?rev=43006&view=auto
==============================================================================
--- erp5/trunk/products/ERP5Type/mixin/temporary.py (added)
+++ erp5/trunk/products/ERP5Type/mixin/temporary.py [utf8] Fri Feb  4 01:43:58 2011
@@ -0,0 +1,81 @@
+##############################################################################
+#
+# Copyright (c) 2010 Nexedi SARL and Contributors. All Rights Reserved.
+#                    Nicolas Dumazet <nicolas.dumazet at nexedi.com>
+#
+# WARNING: This program as such is intended to be used by professional
+# programmers who take the whole responsibility of assessing all potential
+# consequences resulting from its eventual inadequacies and bugs
+# End users who are looking for a ready-to-use solution with commercial
+# guarantees and support are strongly adviced to contract a Free Software
+# Service Company
+#
+# This program is Free Software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+##############################################################################
+
+from Acquisition import aq_base
+from Products.ERP5Type.Accessor.Constant import PropertyGetter as \
+  PropertyConstantGetter
+
+class TemporaryDocumentMixin(object):
+  """
+  Setters and attributes that are attached to temporary documents.
+  """
+  isIndexable = 0
+  isTempDocument = PropertyConstantGetter('isTempDocument', value=True)
+  __roles__ = None
+
+  def reindexObject(self, *args, **kw):
+    pass
+
+  def recursiveReindexObject(self, *args, **kw):
+    pass
+
+  def activate(self, *args, **kw):
+    return self
+
+  def setUid(self, value):
+    self.uid = value # Required for Listbox so that no casting happens when we use TempBase to create new objects
+
+  def getUid(self):
+    try:
+      return getattr(aq_base(self), 'uid')
+    except AttributeError:
+      value = self.getId()
+      self.setUid(value)
+      return value
+
+  def setTitle(self, value):
+    """
+    Required so that getProperty('title') will work on tempBase objects
+    The dynamic acquisition work very well for a lot of properties, but
+    not for title. For example, if we do setProperty('organisation_url'), then
+    even if organisation_url is not in a propertySheet, the method getOrganisationUrl
+    will be generated. But this does not work for title, because I(seb)'m almost sure
+    there is somewhere a method '_setTitle' or 'setTitle' with no method getTitle on Base.
+    That why setProperty('title') and getProperty('title') does not work.
+    """
+    self.title = value
+
+  def getTitle(self):
+    return getattr(self,'title',None)
+
+# Make some methods public.
+for method_id in ('reindexObject', 'recursiveReindexObject',
+                  'activate', 'setUid', 'setTitle', 'getTitle',
+                  'edit', 'setProperty', 'getUid', 'setCriterion',
+                  'setCriterionPropertyList'):
+  setattr(TemporaryDocumentMixin, '%s__roles__' % method_id, None)



More information about the Erp5-report mailing list