From 25a269ba23de13be3be6fe983f7e21c411982f54 Mon Sep 17 00:00:00 2001 From: Arnaud Fontaine <arnaud.fontaine@nexedi.com> Date: Wed, 24 Nov 2010 09:11:01 +0000 Subject: [PATCH] Define importFromFilesystemDefinition as a class method This method is now responsible for creating the property within the Property Sheet, meaningful when importing constraints as some of them may create multiple ZODB constraints from their filesystem definition and also making the code better by avoiding a newContent() then an edit() git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@40580 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ERP5Type/Core/CategoryProperty.py | 6 ++++-- .../ERP5Type/Core/DynamicCategoryProperty.py | 6 ++++-- product/ERP5Type/Core/StandardProperty.py | 17 ++++++++++------- product/ERP5Type/Tool/PropertySheetTool.py | 16 +++++++++++----- 4 files changed, 29 insertions(+), 16 deletions(-) diff --git a/product/ERP5Type/Core/CategoryProperty.py b/product/ERP5Type/Core/CategoryProperty.py index 438970c354..7ca707d10f 100644 --- a/product/ERP5Type/Core/CategoryProperty.py +++ b/product/ERP5Type/Core/CategoryProperty.py @@ -58,8 +58,10 @@ class CategoryProperty(XMLObject): security.declareProtected(Permissions.AccessContentsInformation, 'importFromFilesystemDefinition') - def importFromFilesystemDefinition(self, category_name): + @classmethod + def importFromFilesystemDefinition(cls, context, category_name): """ Set the Reference from a filesystem definition of a property """ - self.setReference(category_name) + return context.newContent(portal_type=cls.portal_type, + reference=category_name) diff --git a/product/ERP5Type/Core/DynamicCategoryProperty.py b/product/ERP5Type/Core/DynamicCategoryProperty.py index 78ffafe6b8..c90b7e07a6 100644 --- a/product/ERP5Type/Core/DynamicCategoryProperty.py +++ b/product/ERP5Type/Core/DynamicCategoryProperty.py @@ -59,8 +59,10 @@ class DynamicCategoryProperty(XMLObject): security.declareProtected(Permissions.AccessContentsInformation, 'importFromFilesystemDefinition') - def importFromFilesystemDefinition(self, category_expression): + @classmethod + def importFromFilesystemDefinition(cls, context, category_expression): """ Set the Expression text from a filesystem definition of a property """ - self.setCategoryExpression(category_expression.text) + return context.newContent(portal_type=cls.portal_type, + category_expression=category_expression.text) diff --git a/product/ERP5Type/Core/StandardProperty.py b/product/ERP5Type/Core/StandardProperty.py index c4bc8c6961..5e9a7c6736 100644 --- a/product/ERP5Type/Core/StandardProperty.py +++ b/product/ERP5Type/Core/StandardProperty.py @@ -146,7 +146,8 @@ class StandardProperty(XMLObject): 'translatable': self.getTranslatable(), 'translation_domain': self.getTranslationDomain()} - def _convertFromFilesystemPropertyDict(self, filesystem_property_dict): + @classmethod + def _convertFromFilesystemPropertyDict(cls, filesystem_property_dict): """ Convert a property dict coming from a Property Sheet on the filesystem to a ZODB property dict @@ -157,13 +158,13 @@ class StandardProperty(XMLObject): for fs_property_name, value in filesystem_property_dict.iteritems(): # Convert filesystem property name to ZODB if necessary zodb_property_name = \ - fs_property_name in self._name_mapping_filesystem_to_zodb_dict and \ - self._name_mapping_filesystem_to_zodb_dict[fs_property_name] or \ + fs_property_name in cls._name_mapping_filesystem_to_zodb_dict and \ + cls._name_mapping_filesystem_to_zodb_dict[fs_property_name] or \ fs_property_name # Convert existing TALES expression class or primitive type to a # TALES expression string - if zodb_property_name in self._expression_attribute_tuple: + if zodb_property_name in cls._expression_attribute_tuple: value = isinstance(value, Expression) and \ value.text or 'python: ' + repr(value) @@ -173,9 +174,11 @@ class StandardProperty(XMLObject): security.declareProtected(Permissions.AccessContentsInformation, 'importFromFilesystemDefinition') - def importFromFilesystemDefinition(self, filesystem_property_dict): + @classmethod + def importFromFilesystemDefinition(cls, context, filesystem_property_dict): """ Set attributes from the filesystem definition of a property """ - self.edit(**self._convertFromFilesystemPropertyDict( - filesystem_property_dict)) + return context.newContent( + portal_type=cls.portal_type, + **cls._convertFromFilesystemPropertyDict(filesystem_property_dict)) diff --git a/product/ERP5Type/Tool/PropertySheetTool.py b/product/ERP5Type/Tool/PropertySheetTool.py index 326a1442a6..2b8dda7ca8 100644 --- a/product/ERP5Type/Tool/PropertySheetTool.py +++ b/product/ERP5Type/Tool/PropertySheetTool.py @@ -88,14 +88,17 @@ class PropertySheetTool(BaseTool): new_property_sheet = self.newContent(id=klass.__name__, portal_type='Property Sheet') + types_tool = self.getPortalObject().portal_types + for attribute_dict in getattr(klass, '_properties', []): # The property could be either a Standard or an Acquired # Property - portal_type = self._guessFilesystemPropertyPortalType(attribute_dict) + portal_type_class = types_tool.getPortalTypeClass( + self._guessFilesystemPropertyPortalType(attribute_dict)) # Create the new property and set its attributes - new_property = new_property_sheet.newContent(portal_type=portal_type) - new_property.importFromFilesystemDefinition(attribute_dict) + portal_type_class.importFromFilesystemDefinition(new_property_sheet, + attribute_dict) for category in getattr(klass, '_categories', []): # A category may be a TALES Expression rather than a plain @@ -103,8 +106,11 @@ class PropertySheetTool(BaseTool): portal_type = isinstance(category, Expression) and \ 'Dynamic Category Property' or 'Category Property' - new_category = new_property_sheet.newContent(portal_type=portal_type) - new_category.importFromFilesystemDefinition(category) + portal_type_class = types_tool.getPortalTypeClass(portal_type) + + # Create the new category + portal_type_class.importFromFilesystemDefinition(new_property_sheet, + category) return new_property_sheet -- 2.30.9