Commit 041377a4 authored by Arnaud Fontaine's avatar Arnaud Fontaine

Enable generation of accessor holders for ZODB Property Sheets and use

TypePropertySheetList which now contains both ZODB and filesystem
Property Sheets (where the former is used in favor of the latter)


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@41183 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 7b7a8c2d
......@@ -575,6 +575,14 @@ def initializePortalTypeDynamicProperties(self, klass, ptype, aq_key, portal):
ptype_object.updatePropertySheetDefinitionDict(ps_definition_dict)
for base in getClassPropertyList(klass):
# FIXME: With ZODB Property Sheets, there should only be the
# name of the Property Sheet as a string. aq_dynamic should not
# be necessary as soon as all the Documents and Property Sheets
# have been migrated. This is kept for backward compatility with
# the filesystem Property Sheet (see ERP5Type.dynamic.portal_type_class)
if isinstance(base, basestring):
continue
for list_name, current_list in ps_definition_dict.items():
try:
current_list += getattr(base, list_name, ())
......
......@@ -608,8 +608,13 @@ class ERP5TypeInformation(XMLObject,
security.declareProtected(Permissions.AccessContentsInformation,
'getAvailablePropertySheetList')
def getAvailablePropertySheetList(self):
return sorted(k for k in PropertySheet.__dict__
if not k.startswith('__'))
property_sheet_set = set([k for k in PropertySheet.__dict__
if not k.startswith('__')])
property_sheet_tool = self.getPortalObject().portal_property_sheets
property_sheet_set.update(property_sheet_tool.objectIds())
return sorted(property_sheet_set)
security.declareProtected(Permissions.AccessContentsInformation,
'getAvailableConstraintList')
......
......@@ -101,6 +101,7 @@ class BaseType:
, 'mode': 'w'
, 'label': 'Property Sheets'
, 'select_variable':'getAvailablePropertySheetList'
, 'default': ()
},
{ 'id': 'type_base_category'
, 'storage_id': 'base_category_list' # CMF Compatibility
......
......@@ -222,28 +222,28 @@ def generatePortalTypeClass(portal_type_name):
property_sheet_set = set()
#### Waiting for Yoshinori's advice before enabling this code
# if portal_type is not None:
# # Get the Property Sheets defined on the portal_type
# property_sheet_set.update(portal_type.getTypeZodbPropertySheetList() \
# or ())
#### The Property Sheets specified in the property_sheets
#### attribute of a Document are only filesystem-based, thus for
#### now it has to be done in the Portal Types themselves
# # Get the Property Sheets defined on the document and its bases
# # recursively
# from Products.ERP5Type.Base import getClassPropertyList
# for property_sheet in getClassPropertyList(klass):
# if isinstance(property_sheet, basestring):
# property_sheet_name = property_sheet
# # FIXME: The Property Sheets of a document should be given as a
# # string from now on, but to avoid changing all the code now, we
# # just get the class name of the filesystem Property Sheet
# else:
# property_sheet_name = property_sheet.__name__
# property_sheet_set.add(property_sheet_name)
if portal_type is not None:
# Get the Property Sheets defined on the portal_type and use the
# ZODB Property Sheet rather than the filesystem only if it
# exists in ZODB
zodb_property_sheet_set = set(site.portal_property_sheets.objectIds())
for property_sheet in portal_type.getTypePropertySheetList():
if property_sheet in zodb_property_sheet_set:
property_sheet_set.add(property_sheet)
# Get the Property Sheets defined on the document and its bases
# recursively. Fallback on the filesystem Property Sheet only and
# only if the ZODB Property Sheet does not exist
from Products.ERP5Type.Base import getClassPropertyList
for property_sheet in getClassPropertyList(klass):
# If the Property Sheet is a string, then this is a ZODB
# Property Sheet
#
# NOTE: The Property Sheets of a document should be given as a
# string from now on
if isinstance(property_sheet, basestring):
property_sheet_name = property_sheet
property_sheet_set.add(property_sheet_name)
import erp5
......
......@@ -33,7 +33,7 @@ import transaction
from Products.ERP5Type.dynamic.portal_type_class import synchronizeDynamicModules
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Type.tests.backportUnittest import expectedFailure, skip
from Products.ERP5Type.tests.backportUnittest import expectedFailure
from zope.interface import Interface, implementedBy
......@@ -545,9 +545,7 @@ class TestZodbPropertySheet(ERP5TypeTestCase):
id='Test Migration',
portal_type='Base Type',
type_class='Folder',
# XXX: to be renamed to type_property_sheet_list as soon as
# the migration has been finished
type_zodb_property_sheet_list=('TestMigration',),
type_property_sheet_list=('TestMigration',),
type_base_category_list=('test_category_existence_constraint',),
type_allowed_content_type_list=('Content Existence Constraint',))
......@@ -596,20 +594,18 @@ class TestZodbPropertySheet(ERP5TypeTestCase):
portal = self.getPortal()
person_type = portal.portal_types.Person
self.failIf('TestMigration' in \
(person_type.getTypeZodbPropertySheetList() or []))
self.failIf('TestMigration' in person_type.getTypePropertySheetList())
new_person = None
try:
# Assign ZODB test Property Sheet to the existing Person type
# and create a new Person, this should generate the test
# accessor holder which should be in the Person type inheritance
person_type.setTypeZodbPropertySheetList('TestMigration')
person_type.setTypePropertySheetList('TestMigration')
transaction.commit()
self.assertTrue('TestMigration' in \
person_type.getTypeZodbPropertySheetList())
self.assertTrue('TestMigration' in person_type.getTypePropertySheetList())
# The accessor holder will be generated once the new Person will
# be created as Person type has test Property Sheet
......@@ -678,7 +674,7 @@ class TestZodbPropertySheet(ERP5TypeTestCase):
# '_setType*'
transaction.commit()
person_type.setTypeZodbPropertySheetList(None)
person_type.setTypePropertySheetList(())
if new_person is not None:
portal.person_module.deleteContent(new_person.getId())
......@@ -689,15 +685,14 @@ class TestZodbPropertySheet(ERP5TypeTestCase):
# unassigned by creating a new person in Person module
transaction.commit()
self.failIf('TestMigration' in \
(person_type.getTypeZodbPropertySheetList() or []))
self.failIf('TestMigration' in person_type.getTypePropertySheetList())
try:
new_person = portal.person_module.newContent(
id='testAssignZodbPropertySheet', portal_type='Person')
self.failIfHasAttribute(new_person, 'getTestStandardPropertyAssign')
self.failIfHasAttribute(erp5.accessor_holder, 'TestMigration')
self.failIfHasAttribute(new_person, 'getTestStandardPropertyAssign')
finally:
if new_person is not None:
......@@ -1019,9 +1014,6 @@ class TestZodbPropertySheet(ERP5TypeTestCase):
self.test_module.setTitle,
'my_property_type_validity_constraint_title')
TestZodbPropertySheet = skip("ZODB Property Sheets code is not enabled yet")(
TestZodbPropertySheet)
from Products.ERP5Type import PropertySheet
from Products.CMFCore.Expression import Expression
......
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