Commit dbc50fe4 authored by Arnaud Fontaine's avatar Arnaud Fontaine

ZODB Property Sheets:

* Generate accessor holders for Document property_sheets.
* Fix naming of methods in portaltypeclass.
* Add export method for Constraints following other Documents.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@39409 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 4ca04e04
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
from Products.ERP5Type.mixin.constraint import ConstraintMixin from Products.ERP5Type.mixin.constraint import ConstraintMixin
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions from Products.ERP5Type import Permissions, PropertySheet
class CategoryExistenceConstraint(ConstraintMixin): class CategoryExistenceConstraint(ConstraintMixin):
""" """
...@@ -46,6 +46,11 @@ class CategoryExistenceConstraint(ConstraintMixin): ...@@ -46,6 +46,11 @@ class CategoryExistenceConstraint(ConstraintMixin):
security = ClassSecurityInfo() security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation) security.declareObjectProtected(Permissions.AccessContentsInformation)
property_sheets = (PropertySheet.SimpleItem,
PropertySheet.Predicate,
PropertySheet.Reference,
PropertySheet.CategoryExistenceConstraint)
_message_id_list = [ 'message_category_not_set', _message_id_list = [ 'message_category_not_set',
'message_category_not_associated_with_portal_type' ] 'message_category_not_associated_with_portal_type' ]
message_category_not_set = "Category existence error for base"\ message_category_not_set = "Category existence error for base"\
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
from Products.ERP5Type.mixin.constraint import ConstraintMixin from Products.ERP5Type.mixin.constraint import ConstraintMixin
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions from Products.ERP5Type import Permissions, PropertySheet
class PropertyExistenceConstraint(ConstraintMixin): class PropertyExistenceConstraint(ConstraintMixin):
""" """
...@@ -52,6 +52,11 @@ class PropertyExistenceConstraint(ConstraintMixin): ...@@ -52,6 +52,11 @@ class PropertyExistenceConstraint(ConstraintMixin):
security = ClassSecurityInfo() security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation) security.declareObjectProtected(Permissions.AccessContentsInformation)
property_sheets = (PropertySheet.SimpleItem,
PropertySheet.Predicate,
PropertySheet.Reference,
PropertySheet.PropertyExistenceConstraint)
# Define by default error messages # Define by default error messages
_message_id_list = ['message_no_such_property', _message_id_list = ['message_no_such_property',
'message_property_not_set'] 'message_property_not_set']
......
...@@ -57,21 +57,11 @@ def _import_class(classpath): ...@@ -57,21 +57,11 @@ def _import_class(classpath):
except StandardError: except StandardError:
raise ImportError('Could not import document class %s' % classpath) raise ImportError('Could not import document class %s' % classpath)
# FIXME: bad name def _fillAccessorHolderList(accessor_holder_list,
def _create_accessor_holder_class(property_sheet_tool, create_accessor_holder_func,
property_sheet_module, property_sheet_name_set,
property_sheet_name): accessor_holder_module,
""" property_sheet_module):
If the given Property Sheet exists in portal_property_sheets, then
generate its accessor holder
"""
# FIXME: bad name
def _fill_accessor_holder_list(accessor_holder_list,
create_accessor_holder_func,
property_sheet_name_set,
accessor_holder_module,
property_sheet_module):
""" """
Fill the accessor holder list with the given Property Sheets (which Fill the accessor holder list with the given Property Sheets (which
could be coming either from the filesystem or ZODB) could be coming either from the filesystem or ZODB)
...@@ -167,28 +157,6 @@ def portal_type_factory(portal_type_name): ...@@ -167,28 +157,6 @@ def portal_type_factory(portal_type_name):
finally: finally:
del klass del klass
import erp5
#broken# # Initialize filesystem Property Sheets accessor holders
#broken# _fill_accessor_holder_list(
#broken# accessor_holder_list,
#broken# site.portal_property_sheets.createFilesystemPropertySheetAccessorHolder,
#broken# set(portal_type.getTypePropertySheetList() or ()),
#broken# erp5.filesystem_accessor_holder,
#broken# FilesystemPropertySheet)
#broken#
#broken# # Initialize ZODB Property Sheets accessor holders
#broken# _fill_accessor_holder_list(
#broken# accessor_holder_list,
#broken# site.portal_property_sheets.createZodbPropertySheetAccessorHolder,
#broken# set(portal_type.getTypeZodbPropertySheetList() or ()),
#broken# erp5.zodb_accessor_holder,
#broken# site.portal_property_sheets)
#LOG("ERP5Type.Dynamic", INFO,
# "%s: accessor_holder_list: %s" % (portal_type_name,
# accessor_holder_list))
if type_class is not None: if type_class is not None:
type_class = document_class_registry.get(type_class) type_class = document_class_registry.get(type_class)
if type_class is None: if type_class is None:
...@@ -196,6 +164,42 @@ def portal_type_factory(portal_type_name): ...@@ -196,6 +164,42 @@ def portal_type_factory(portal_type_name):
type_class = _import_class(type_class) type_class = _import_class(type_class)
## Disabled because there will be no commit of
## type_zodb_property_sheet, only use for testing ATM
# import erp5
# # Initialize filesystem Property Sheets accessor holders
# _fillAccessorHolderList(
# accessor_holder_list,
# site.portal_property_sheets.createFilesystemPropertySheetAccessorHolder,
# set(portal_type.getTypePropertySheetList() or ()),
# erp5.filesystem_accessor_holder,
# FilesystemPropertySheet)
# # Initialize ZODB Property Sheets accessor holders
# _fillAccessorHolderList(
# accessor_holder_list,
# site.portal_property_sheets.createZodbPropertySheetAccessorHolder,
# set(portal_type.getTypeZodbPropertySheetList() or ()),
# erp5.zodb_accessor_holder,
# site.portal_property_sheets)
# # XXX: for now, we have PropertySheet classes defined in
# # property_sheets attribute of Document, but there will be only
# # string at the end
# from Products.ERP5Type.Base import getClassPropertyList
# _fillAccessorHolderList(
# accessor_holder_list,
# site.portal_property_sheets.createFilesystemPropertySheetAccessorHolder,
# [ klass.__name__ for klass in getClassPropertyList(type_class) ],
# erp5.filesystem_accessor_holder,
# FilesystemPropertySheet)
# LOG("ERP5Type.Dynamic", INFO,
# "%s: accessor_holder_list: %s" % (portal_type_name,
# accessor_holder_list))
mixin_path_list = [] mixin_path_list = []
if mixin_list: if mixin_list:
mixin_path_list = map(mixin_class_registry.__getitem__, mixin_list) mixin_path_list = map(mixin_class_registry.__getitem__, mixin_list)
...@@ -245,6 +249,7 @@ def initializeDynamicModules(): ...@@ -245,6 +249,7 @@ def initializeDynamicModules():
erp5.filesystem_accessor_holder = ModuleType("erp5.filesystem_accessor_holder") erp5.filesystem_accessor_holder = ModuleType("erp5.filesystem_accessor_holder")
sys.modules["erp5.filesystem_accessor_holder"] = erp5.filesystem_accessor_holder sys.modules["erp5.filesystem_accessor_holder"] = erp5.filesystem_accessor_holder
# FIXME: JPS: rename to dynamic_module.newDynamicModule()?
portal_type_container = dynamicmodule.dynamicmodule('erp5.portal_type', portal_type_container = dynamicmodule.dynamicmodule('erp5.portal_type',
portal_type_loader) portal_type_loader)
...@@ -286,8 +291,7 @@ def initializeDynamicModules(): ...@@ -286,8 +291,7 @@ def initializeDynamicModules():
erp5.temp_portal_type = dynamicmodule.dynamicmodule('erp5.temp_portal_type', erp5.temp_portal_type = dynamicmodule.dynamicmodule('erp5.temp_portal_type',
temp_portal_type_loader) temp_portal_type_loader)
# FIXME: bad name def _clearAccessorHolderModule(module):
def _clear_accessor_holder_module(module):
""" """
Clear the given accessor holder module (either for filesystem or Clear the given accessor holder module (either for filesystem or
ZODB) ZODB)
...@@ -340,7 +344,7 @@ def synchronizeDynamicModules(context, force=False): ...@@ -340,7 +344,7 @@ def synchronizeDynamicModules(context, force=False):
type(ExtensionBase).__init__(klass, klass) type(ExtensionBase).__init__(klass, klass)
# Clear accessor holders of ZODB Property Sheets # Clear accessor holders of ZODB Property Sheets
_clear_accessor_holder_module(erp5.zodb_accessor_holder) _clearAccessorHolderModule(erp5.zodb_accessor_holder)
# Clear accessor holders of filesystem Property Sheets # Clear accessor holders of filesystem Property Sheets
_clear_accessor_holder_module(erp5.filesystem_accessor_holder) _clearAccessorHolderModule(erp5.filesystem_accessor_holder)
...@@ -152,20 +152,17 @@ class PropertySheetTool(BaseTool): ...@@ -152,20 +152,17 @@ class PropertySheetTool(BaseTool):
for property in property_sheet.contentValues(): for property in property_sheet.contentValues():
portal_type = property.getPortalType() portal_type = property.getPortalType()
property_definition = property.exportToFilesystemDefinition()
if portal_type == "Standard Property" or \ if portal_type == "Category Property" or \
portal_type == "Acquired Property": portal_type == "Dynamic Category Property":
properties.append(property.exportToFilesystemDefinition()) categories.append(property_definition)
elif portal_type == "Category Property":
categories.append(property.getId())
elif portal_type == "Dynamic Category Property":
categories.append(property.exportToFilesystemDefinition())
elif portal_type.endswith('Constraint'): elif portal_type.endswith('Constraint'):
from Acquisition import aq_base constraints.append(property_definition)
constraints.append(aq_base(property.asContext()))
else:
properties.append(property_definition)
return (properties, categories, constraints) return (properties, categories, constraints)
......
...@@ -85,3 +85,15 @@ class ConstraintMixin(Predicate): ...@@ -85,3 +85,15 @@ class ConstraintMixin(Predicate):
Default method is to call checkConsistency with fixit set to 1 Default method is to call checkConsistency with fixit set to 1
""" """
return self.checkConsistency(obj, fixit=1, **kw) return self.checkConsistency(obj, fixit=1, **kw)
security.declareProtected(Permissions.AccessContentsInformation,
'exportToFilesystemDefinition')
def exportToFilesystemDefinition(self):
"""
Return a temporary copy of the constraint object (with acquisition
wrapping removed) in order to maintain compatibility and be able
to use setDefaultProperties
XXX: remove as soon as the code is stable
"""
return self.asContext().aq_base
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