Commit e57fd1cd authored by Arnaud Fontaine's avatar Arnaud Fontaine

Add property documents for web-based Property Sheets



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@38976 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 13f2e816
##############################################################################
#
# Copyright (c) 2010 Nexedi SARL and Contributors. All Rights Reserved.
# Arnaud Fontaine <arnaud.fontaine@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability 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
# garantees 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from AccessControl import ClassSecurityInfo
from Products.CMFCore.Expression import Expression
from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5.Document.StandardProperty import StandardProperty
class AcquiredProperty(StandardProperty):
"""
Define an Acquired Property Document for a web-based Property Sheet
(an Acquired Property only brings new attributes to a Standard
Property)
"""
meta_type = 'ERP5 Acquired Property'
portal_type = 'Acquired Property'
# Declarative security
security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation)
property_sheets = StandardProperty.property_sheets + \
(PropertySheet.AcquiredProperty,)
# Filesystem-based name of attributes specific to 'content' type
_content_type_attribute_tuple = ('portal_type',
'acquired_property_id',
'translation_acquired_property')
# Add names specific to 'content' type (see StandardProperty)
_name_mapping_filesystem_to_web_dict = \
dict([ (name, 'content_' + name,) for name in _content_type_attribute_tuple ],
**StandardProperty._name_mapping_filesystem_to_web_dict)
# Web-based name of attributes whose value is a TALES Expression
_expression_attribute_tuple = ('acquisition_portal_type',
'content_portal_type')
@staticmethod
def _convertValueToTalesExpression(value):
"""
Convert a string value to a TALES expression for attributes listed
in '_expression_attribute_tuple'
"""
return value is None and value or Expression(value)
security.declareProtected(Permissions.AccessContentsInformation,
'exportToFilesystemDefinition')
def exportToFilesystemDefinition(self):
"""
Return the filesystem definition of this web-based property
"""
filesystem_property_dict = \
StandardProperty.exportToFilesystemDefinition(self)
filesystem_property_dict.update(
{'acquisition_base_category': self.getAcquisitionBaseCategoryList() or None,
'acquisition_object_id': self.getAcquisitionObjectIdList() or None,
'acquisition_portal_type': self._convertValueToTalesExpression(self.getAcquisitionPortalType()),
'acquisition_accessor_id': self.getAcquisitionAccessorId(),
'alt_accessor_id': self.getAltAccessorIdList() or None,
'acquisition_copy_value': self.getAcquisitionCopyValue(),
'acquisition_mask_value': self.getAcquisitionMaskValue(),
'portal_type': self._convertValueToTalesExpression(self.getContentPortalType()),
'acquired_property_id': self.getContentAcquiredPropertyIdList() or None,
'translation_acquired_property_id': self.getContentTranslationAcquiredPropertyIdList() or None})
return filesystem_property_dict
def _convertFromFilesytemPropertyDict(self, filesystem_property_dict):
"""
Convert a property dict coming from a Property Sheet on the
filesystem to a web-based property dict
"""
web_property_dict = StandardProperty._convertFromFilesytemPropertyDict(
self, filesystem_property_dict)
# Update the properties whose values are TALES Expression
for attribute in self._expression_attribute_tuple:
if attribute in web_property_dict:
value = isinstance(web_property_dict[attribute], Expression) and \
web_property_dict[attribute].text or \
'python: ' + repr(web_property_dict[attribute])
web_property_dict[attribute] = value
return web_property_dict
##############################################################################
#
# Copyright (c) 2010 Nexedi SARL and Contributors. All Rights Reserved.
# Arnaud Fontaine <arnaud.fontaine@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability 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
# garantees 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from AccessControl import ClassSecurityInfo
from Products.CMFCore.Expression import Expression
from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5Type.XMLObject import XMLObject
class DynamicCategoryProperty(XMLObject):
"""
Define a Dynamic Category Property Document for a web-based Property
Sheets (a dynamic category is defined by a TALES expression rather
than a string and is being used by Item and Movement for example)
"""
meta_type = 'ERP5 Dynamic Category Property'
portal_type = 'Dynamic Category Property'
# Declarative security
security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation)
property_sheets = (PropertySheet.DynamicCategoryProperty,)
security.declareProtected(Permissions.AccessContentsInformation,
'exportToFilesystemDefinition')
def exportToFilesystemDefinition(self):
"""
Return the filesystem definition of the property
"""
return Expression(self.getCategoryExpression())
security.declareProtected(Permissions.AccessContentsInformation,
'importFromFilesystemDefinition')
def importFromFilesystemDefinition(self, category_expression):
"""
Set the Expression text from a filesystem definition of a property
"""
self.setCategoryExpression(category_expression.text)
##############################################################################
#
# Copyright (c) 2010 Nexedi SARL and Contributors. All Rights Reserved.
# Arnaud Fontaine <arnaud.fontaine@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability 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
# garantees 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5Type.XMLObject import XMLObject
class StandardProperty(XMLObject):
"""
Define an Acquired Property Document for a web-based Property Sheet
"""
meta_type = 'ERP5 Standard Property'
portal_type = 'Standard Property'
# Declarative security
security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation)
property_sheets = (PropertySheet.SimpleItem,
PropertySheet.StandardProperty,
PropertySheet.TranslatableProperty)
# Names mapping between filesystem to web-based property, only
# meaningful when importing a property from its filesystem
# definition
_name_mapping_filesystem_to_web_dict = {'id': 'reference',
'type': 'elementary_type',
'default': 'property_default'}
security.declareProtected(Permissions.AccessContentsInformation,
'exportToFilesystemDefinition')
def exportToFilesystemDefinition(self):
"""
Return the filesystem definition of this web-based property
"""
return {'id': self.getReference(),
'description': self.getDescription(),
'type': self.getElementaryType(),
'storage_id': self.getStorageId(),
'multivalued': self.getMultivalued(),
'default': self.getPropertyDefault(),
'range': self.getRange(),
'preference': self.getPreference(),
'read_permission': self.getReadPermission(),
'write_permission': self.getWritePermission(),
'translatable': self.getTranslatable(),
'translation_domain': self.getTranslationDomain()}
def _convertFromFilesytemPropertyDict(self, filesystem_property_dict):
"""
Convert a property dict coming from a Property Sheet on the
filesystem to a web-based property dict
"""
# Prepare a dictionnary of the web-based property
web_property_dict = {}
for fs_property_name, value in filesystem_property_dict.iteritems():
# Convert filesystem property name to web-based if necessary
web_property_name = \
fs_property_name in self._name_mapping_filesystem_to_web_dict and \
self._name_mapping_filesystem_to_web_dict[fs_property_name] or \
fs_property_name
web_property_dict[web_property_name] = value
return web_property_dict
security.declareProtected(Permissions.AccessContentsInformation,
'importFromFilesystemDefinition')
def importFromFilesystemDefinition(self, filesystem_property_dict):
"""
Set attributes from the filesystem definition of a property
"""
self.edit(**self._convertFromFilesytemPropertyDict(filesystem_property_dict))
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