[Erp5-report] r40578 arnaud.fontaine - /erp5/trunk/products/ERP5Type/dynamic/lazy_class.py

nobody at svn.erp5.org nobody at svn.erp5.org
Wed Nov 24 09:48:02 CET 2010


Author: arnaud.fontaine
Date: Wed Nov 24 09:48:02 2010
New Revision: 40578

URL: http://svn.erp5.org?rev=40578&view=rev
Log:
Load portal type class when trying to access a class attribute and
avoid loading the class if it has already been loaded before

Modified:
    erp5/trunk/products/ERP5Type/dynamic/lazy_class.py

Modified: erp5/trunk/products/ERP5Type/dynamic/lazy_class.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/dynamic/lazy_class.py?rev=40578&r1=40577&r2=40578&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/dynamic/lazy_class.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/dynamic/lazy_class.py [utf8] Wed Nov 24 09:48:02 2010
@@ -129,7 +129,27 @@ class PortalTypeMetaClass(ExtensionClass
       cls.__ghostbase__ = None
       cls.resetAcquisitionAndSecurity()
 
+  def __getattr__(cls, name):
+    """
+    Load the class before trying to access a class attribute (for
+    example, Standard Property document defines a class method to
+    import a filesystem property)
+    """
+    # Perform the loadClass only on erp5.portal_type classes
+    if cls.__module__ != 'erp5.portal_type':
+      return getattr(cls.__bases__[0], name)
+
+    if not name.startswith('__') and cls.__ghostbase__ is None:
+      cls.loadClass()
+      return getattr(cls, name)
+
+    raise AttributeError
+
   def loadClass(cls):
+    # Do not load the class again if it has already been loaded
+    if cls.__ghostbase__ is not None:
+      return
+
     # cls might be a subclass of a portal type class
     # we need to find the right class to change
     for klass in cls.__mro__:




More information about the Erp5-report mailing list