############################################################################## # # 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