From 653fc5b7dce78972a8e3a31cca165ff385b5c0f2 Mon Sep 17 00:00:00 2001
From: Julien Muchembled <jm@nexedi.com>
Date: Mon, 28 Sep 2009 17:41:12 +0000
Subject: [PATCH] Code style changes (based on Yoshinori's comments)

git-svn-id: https://svn.erp5.org/repos/public/erp5/sandbox/portal_types@29284 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5/Document/BusinessTemplate.py  |  4 +++-
 product/ERP5/ERP5Site.py                   |  4 ++--
 product/ERP5Type/Core/ActionInformation.py | 12 +++++++++---
 product/ERP5Type/ERP5Type.py               |  4 ++--
 product/ERP5Type/Utils.py                  |  2 +-
 5 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/product/ERP5/Document/BusinessTemplate.py b/product/ERP5/Document/BusinessTemplate.py
index 07313e0510..418c8b1f35 100644
--- a/product/ERP5/Document/BusinessTemplate.py
+++ b/product/ERP5/Document/BusinessTemplate.py
@@ -1554,8 +1554,10 @@ class PortalTypeTemplateItem(ObjectTemplateItem):
     for relative_url in self._archive.keys():
       obj = p.unrestrictedTraverse(relative_url)
       obj = obj._getCopy(context)
+      # obj is in ghost state and an attribute must be accessed
+      # so that obj.__dict__ does not return an empty dict
       obj.meta_type
-      for attr in tuple(obj.__dict__):
+      for attr in obj.__dict__.keys():
         if attr == '_property_domain_dict':
           continue
         if attr[0] == '_' or attr in ('allowed_content_types',
diff --git a/product/ERP5/ERP5Site.py b/product/ERP5/ERP5Site.py
index 2d08771ba8..dcba586530 100644
--- a/product/ERP5/ERP5Site.py
+++ b/product/ERP5/ERP5Site.py
@@ -1714,7 +1714,7 @@ class ERP5Generator(PortalGenerator):
     tool = getToolByName(p, 'portal_types', None)
     if tool is None:
       return
-    for t in BusinessTemplate,:
+    for t in (BusinessTemplate, ):
       t = t.factory_type_information
       if not tool.hasObject(t['id']):
         tool._setObject(t['id'], ERP5TypeInformation(uid=None, **t))
@@ -1728,7 +1728,7 @@ class ERP5Generator(PortalGenerator):
       return
     if template_tool.getInstalledBusinessTemplate('erp5_core') is None:
       bootstrap_dir = self.getBootstrapDirectory()
-      for bt in 'erp5_core', p.erp5_catalog_storage, 'erp5_xhtml_style':
+      for bt in ('erp5_core', p.erp5_catalog_storage, 'erp5_xhtml_style'):
         if not bt:
           continue
         template = os.path.join(bootstrap_dir, bt)
diff --git a/product/ERP5Type/Core/ActionInformation.py b/product/ERP5Type/Core/ActionInformation.py
index 4ab65e7dc8..e0bfcdada1 100644
--- a/product/ERP5Type/Core/ActionInformation.py
+++ b/product/ERP5Type/Core/ActionInformation.py
@@ -69,11 +69,11 @@ class ActionInformation(XMLObject):
         category = self.getActionType() or ''
         info = ec.vars
         if (info['here'] is not None and
-            (category.startswith('object') or
-             category.startswith('workflow'))):
+            (category[:6] == 'object' or
+             category[:8] == 'workflow')):
           context = info['here']
         elif (info['folder'] is not None and
-              category.startswith('folder')):
+              category[:6] == 'folder'):
           context = info['folder']
         else:
           context = info['portal']
@@ -105,12 +105,14 @@ class ActionInformation(XMLObject):
     if isinstance(value, basestring):
       value = value and Expression(value) or None
     self._baseSetAction(value)
+
   def _setCondition(self, value):
     """Overridden setter for 'condition' to accept string and clean null values
     """
     if isinstance(value, basestring):
       value = value and Expression(value) or None
     self._baseSetCondition(value)
+
   def _setIcon(self, value):
     """Overridden setter for 'icon' to accept string and clean null values
     """
@@ -123,11 +125,13 @@ class ActionInformation(XMLObject):
     if getattr(aq_base(self), 'action', None) == '':
       del self.action
     return self._baseGetAction()
+
   def getCondition(self):
     """Overridden getter for 'condition' to clean null values"""
     if getattr(aq_base(self), 'condition', None) == '':
       del self.condition
     return self._baseGetCondition()
+
   def getIcon(self):
     """Overridden getter for 'icon' to clean null values"""
     if getattr(aq_base(self), 'icon', None) == '':
@@ -138,10 +142,12 @@ class ActionInformation(XMLObject):
   def getActionText(self):
     """Return the text of the action expression"""
     return getattr(self.getAction(), 'text', None)
+
   security.declareProtected(AccessContentsInformation, 'getConditionText')
   def getConditionText(self):
     """Return the text of the condition expression"""
     return getattr(self.getCondition(), 'text', None)
+
   security.declareProtected(AccessContentsInformation, 'getIconText')
   def getIconText(self):
     """Return the text of the icon expression"""
diff --git a/product/ERP5Type/ERP5Type.py b/product/ERP5Type/ERP5Type.py
index 8131f2938f..10230f5cae 100644
--- a/product/ERP5Type/ERP5Type.py
+++ b/product/ERP5Type/ERP5Type.py
@@ -457,7 +457,7 @@ class ERP5TypeInformation(XMLObject,
         id = id + "d"
       return factory_method(portal, id).propertyMap()
 
-    def edit(self, *args, **kw):
+    def _edit(self, *args, **kw):
       """
         Method overload
 
@@ -470,7 +470,7 @@ class ERP5TypeInformation(XMLObject,
       """
       property_list = 'factory', 'property_sheet_list', 'base_category_list'
       previous_state = [getattr(aq_base(self), x) for x in property_list]
-      result = XMLObject.edit(self, *args, **kw)
+      result = XMLObject._edit(self, *args, **kw)
       if previous_state != [getattr(aq_base(self), x) for x in property_list]:
         from Products.ERP5Type.Base import _aq_reset
         _aq_reset()
diff --git a/product/ERP5Type/Utils.py b/product/ERP5Type/Utils.py
index 3dc1889c93..868e3e8cc0 100644
--- a/product/ERP5Type/Utils.py
+++ b/product/ERP5Type/Utils.py
@@ -1113,7 +1113,7 @@ def createExpressionContext(object, portal=None):
   if portal is None and object is not None:
     portal = object.getPortalObject()
 
-  if object is None or aq_base(object) is None:
+  if object is None or getattr(object, 'aq_base', None) is None:
     folder = portal
   else:
     folder = object
-- 
2.30.9