Commit 06709d64 authored by Arnaud Fontaine's avatar Arnaud Fontaine

Create a separate Document for Property Sheet and move methods from

Property Sheet Tool to this new document and update Property Sheet
Portal Type accordingly


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@43214 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent f3a29e7a
......@@ -2,7 +2,7 @@
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ERP5TypeInformation" module="Products.ERP5Type.ERP5Type"/>
<global name="Base Type" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
......@@ -61,7 +61,7 @@
</item>
<item>
<key> <string>type_class</string> </key>
<value> <string>Folder</string> </value>
<value> <string>PropertySheet</string> </value>
</item>
<item>
<key> <string>type_interface_list</string> </key>
......
40874
\ No newline at end of file
40875
\ No newline at end of file
This diff is collapsed.
##############################################################################
#
# Copyright (c) 2011 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 Products.ERP5Type.Core.Folder import Folder
from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions
from Products.ERP5Type.Base import PropertyHolder
from Products.ERP5Type.dynamic.accessor_holder import AccessorHolderType
from zLOG import LOG, INFO
class PropertySheet(Folder):
"""
Define a Property Sheet for ZODB Property Sheets, which contains
properties (such as Standard Property), categories (such as Category
Property) and/or constraints (such as Property Existence Constraint)
"""
meta_type = 'ERP5 Property Sheet'
portal_type = 'Property Sheet'
# Declarative security
security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation)
security.declareProtected(Permissions.AccessContentsInformation,
'exportToFilesystemDefinition')
def exportToFilesystemDefinition(self):
"""
Export the ZODB Property Sheet to its filesystem definition as a
tuple (properties, categories, constraints)
"""
properties = []
constraints = []
categories = []
for item in self.contentValues():
definition = item.exportToFilesystemDefinition()
# If a category doesn't have a name yet or the constraint class
# returned is None, then just skip it
if definition is None:
LOG("ERP5Type.Core.PropertySheet", INFO,
"Skipping property with ID '%s' in Property Sheet '%s'" % \
(item.getId(), self.getId()))
continue
portal_type = item.getPortalType()
if portal_type == "Category Property" or \
portal_type == "Dynamic Category Property":
categories.append(definition)
elif portal_type.endswith('Constraint'):
constraints.append(definition)
else:
properties.append(definition)
return (properties, categories, constraints)
security.declarePrivate('createAccessorHolder')
def createAccessorHolder(self):
"""
Create a new accessor holder from the Property Sheet (the
accessors are created through a Property Holder)
"""
property_holder = PropertyHolder(self.getId())
# Prepare the Property Holder
property_holder._properties, \
property_holder._categories, \
property_holder._constraints = self.exportToFilesystemDefinition()
return AccessorHolderType.fromPropertyHolder(
property_holder,
self.getPortalObject(),
'erp5.accessor_holder')
......@@ -33,12 +33,9 @@ from AccessControl import ClassSecurityInfo
from Products.ERP5Type.Tool.BaseTool import BaseTool
from Products.ERP5Type import Permissions
from Products.ERP5Type.Accessor import Translation
from Products.ERP5Type.Base import PropertyHolder
from Products.CMFCore.utils import getToolByName
from Products.CMFCore.Expression import Expression
from Products.ERP5Type.dynamic.accessor_holder import AccessorHolderType
from zLOG import LOG, INFO, WARNING
class PropertySheetTool(BaseTool):
......@@ -206,68 +203,6 @@ class PropertySheetTool(BaseTool):
return self.Base_redirect('view',
keep_items={'portal_status_message': message})
security.declareProtected(Permissions.AccessContentsInformation,
'exportPropertySheetToFilesystemDefinitionTuple')
def exportPropertySheetToFilesystemDefinitionTuple(self, property_sheet):
"""
Export a given ZODB Property Sheet to its filesystem definition as
tuple (properties, categories, constraints)
XXX: Move this code and the accessor generation code (from Utils)
within their respective documents
"""
properties = []
constraints = []
categories = []
for property in property_sheet.contentValues():
property_definition = property.exportToFilesystemDefinition()
# If a category doesn't have a name yet or the constraint class
# returned is None, then just skip it
if property_definition is None:
LOG("Tool.PropertySheetTool", INFO,
"Skipping property with ID '%s' in Property Sheet '%s'" % \
(property.getId(), property_sheet.getId()))
continue
portal_type = property.getPortalType()
if portal_type == "Category Property" or \
portal_type == "Dynamic Category Property":
categories.append(property_definition)
elif portal_type.endswith('Constraint'):
constraints.append(property_definition)
else:
properties.append(property_definition)
return (properties, categories, constraints)
security.declarePrivate('createZodbPropertySheetAccessorHolder')
def createZodbPropertySheetAccessorHolder(self, property_sheet):
"""
Create a new accessor holder from the given ZODB Property Sheet
(the accessors are created through a Property Holder)
"""
property_sheet_name = property_sheet.getId()
definition_tuple = \
self.exportPropertySheetToFilesystemDefinitionTuple(property_sheet)
property_holder = PropertyHolder(property_sheet_name)
# Prepare the Property Holder
property_holder._properties, \
property_holder._categories, \
property_holder._constraints = definition_tuple
return AccessorHolderType.fromPropertyHolder(
property_holder,
self.getPortalObject(),
'erp5.accessor_holder')
security.declareProtected(Permissions.ManagePortal,
'getPropertyAvailablePermissionList')
def getPropertyAvailablePermissionList(self):
......
......@@ -90,10 +90,8 @@ def _createAccessorHolderList(site,
except AttributeError:
# Generate the accessor holder as it has not been done yet
try:
accessor_holder_class = \
property_sheet_tool.createZodbPropertySheetAccessorHolder(
getattr(property_sheet_tool,
property_sheet_name))
property_sheet = getattr(property_sheet_tool, property_sheet_name)
accessor_holder_class = property_sheet.createAccessorHolder()
except:
LOG("ERP5Type.dynamic", ERROR,
......
......@@ -1257,8 +1257,7 @@ class TestZodbImportFilesystemPropertySheet(ERP5TypeTestCase):
self.portal.portal_property_sheets.objectIds())
zodb_property_tuple, zodb_category_tuple, zodb_constraint_class_tuple = \
portal.exportPropertySheetToFilesystemDefinitionTuple(
zodb_property_sheet)
zodb_property_sheet.exportToFilesystemDefinition()
self._checkPropertyOrConstraintDefinitionTuple(
property_sheet_name,
......
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