Commit 25a269ba authored by Arnaud Fontaine's avatar Arnaud Fontaine

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
parent 0a8a0995
......@@ -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)
......@@ -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)
......@@ -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))
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment