Commit 96eca6f1 authored by Julien Muchembled's avatar Julien Muchembled

Fix ERP5TypeInformation.getInstancePropertyAndBaseCategoryList

This fixes test_getInstancePropertyAndBaseCategoryList
and also removes obsolete 'updatePropertySheetDefinitionDict' methods.
parent f5aacbf9
No related merge requests found
...@@ -728,23 +728,6 @@ class PDFTypeInformation(ERP5TypeInformation): ...@@ -728,23 +728,6 @@ class PDFTypeInformation(ERP5TypeInformation):
permission_list=['View']), permission_list=['View']),
] ]
def updatePropertySheetDefinitionDict(self, definition_dict, **kw):
"""
This function add properties of scribus file to the propertySheet
"""
if self.getDefaultScribusFormValue() is None:
return
if '_properties' in definition_dict:
parsed_scribus = self._getParsedScribusFile()
for page_content in parsed_scribus.itervalues():
for field_name, fields_values in page_content:
field_id = field_name
field_type = fields_values["data_type"]
definition_dict['_properties'].append({'id':field_name[3:],
'type':field_type,
'mode':'w'})
ERP5TypeInformation.updatePropertySheetDefinitionDict(self, definition_dict)
def getTypePropertySheetValueList(self): def getTypePropertySheetValueList(self):
property_sheet_list = super(PDFTypeInformation, property_sheet_list = super(PDFTypeInformation,
self).getTypePropertySheetValueList() self).getTypePropertySheetValueList()
......
...@@ -145,10 +145,6 @@ class AcquiredProperty(StandardProperty): ...@@ -145,10 +145,6 @@ class AcquiredProperty(StandardProperty):
""" """
@see Products.ERP5Type.Core.StandardProperty._asPropertyMap @see Products.ERP5Type.Core.StandardProperty._asPropertyMap
""" """
# A property whose type is 'content' must never be used by Zope
if property_dict['elementary_type'] == 'content':
return {}
property_map = super(AcquiredProperty, cls)._asPropertyMap(property_dict) property_map = super(AcquiredProperty, cls)._asPropertyMap(property_dict)
property_map['portal_type'] = property_map.pop('content_portal_type') property_map['portal_type'] = property_map.pop('content_portal_type')
......
...@@ -423,19 +423,6 @@ class ERP5TypeInformation(XMLObject, ...@@ -423,19 +423,6 @@ class ERP5TypeInformation(XMLObject,
import erp5.portal_type as module import erp5.portal_type as module
return getattr(module, self.getId()) return getattr(module, self.getId())
security.declarePrivate('updatePropertySheetDefinitionDict')
def updatePropertySheetDefinitionDict(self, definition_dict):
for property_sheet_name in self.getTypePropertySheetList():
base = getattr(PropertySheet, property_sheet_name, None)
if base is not None:
for list_name, property_list in definition_dict.items():
try:
property_list += getattr(base, list_name, ())
except TypeError:
raise ValueError("%s is not a list for %s" % (list_name, base))
if '_categories' in definition_dict:
definition_dict['_categories'] += self.getTypeBaseCategoryList()
# The following 2 methods are needed before there are generated. # The following 2 methods are needed before there are generated.
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
...@@ -517,24 +504,21 @@ class ERP5TypeInformation(XMLObject, ...@@ -517,24 +504,21 @@ class ERP5TypeInformation(XMLObject,
'getInstancePropertyAndBaseCategoryList') 'getInstancePropertyAndBaseCategoryList')
def getInstancePropertyAndBaseCategoryList(self): def getInstancePropertyAndBaseCategoryList(self):
"""Return all the properties and base categories of the portal type. """ """Return all the properties and base categories of the portal type. """
# PropertHolder._properties doesn't contain 'content' properties. # XXX: Hack until introspection methods are defined. At least, this works
ob = self.constructTempInstance(self, self.getId()) # for portal_type whose properties are defined dynamically
property_list = list(getattr(ob.__class__, '_properties', [])) # (e.g. temporary property sheets).
self.updatePropertySheetDefinitionDict({'_properties': property_list}) # See also AcquiredProperty._asPropertyMap
for property_sheet in getClassPropertyList(ob.__class__): cls = self.getPortalObject().portal_types.getPortalTypeClass(self.getId())
property_list += getattr(property_sheet, '_properties', () )
return_set = set() return_set = set()
for property in property_list: for property in cls.getAccessorHolderPropertyList(content=True):
if property['type'] == 'content': if property['type'] == 'content':
for suffix in property['acquired_property_id']: for suffix in property['acquired_property_id']:
return_set.add(property['id'] + '_' + suffix) return_set.add(property['id'] + '_' + suffix)
else: else:
return_set.add(property['id']) return_set.add(property['id'])
for category in ob.getBaseCategoryList(): for category in cls._categories:
return_set.add(category) return_set.add(category)
return_set.add(category + '_free_text') return_set.add(category + '_free_text')
# XXX Can't return set to restricted code in Zope 2.8. # XXX Can't return set to restricted code in Zope 2.8.
return list(return_set) return list(return_set)
......
...@@ -157,11 +157,16 @@ class PortalTypeMetaClass(GhostBaseMetaClass, PropertyHolder): ...@@ -157,11 +157,16 @@ class PortalTypeMetaClass(GhostBaseMetaClass, PropertyHolder):
""" """
return meta_class.subclass_register.get(cls, []) return meta_class.subclass_register.get(cls, [])
def getAccessorHolderPropertyList(cls): def getAccessorHolderPropertyList(cls, content=False):
""" """
Get unique properties, by its id, as defined in the accessor holders, Get unique properties, by its id, as defined in the accessor holders,
meaningful for _propertyMap for example meaningful for _propertyMap for example
Properties whose type is 'content' should not be visible in ZMI
so they are not returned by default. This would also slow down
MovementCollectionDiff._getPropertyList (ERP5 product). However,
ERP5TypeInformation.getInstancePropertyAndBaseCategoryList needs them.
@see Products.ERP5Type.Base.Base._propertyMap @see Products.ERP5Type.Base.Base._propertyMap
""" """
cls.loadClass() cls.loadClass()
...@@ -170,7 +175,8 @@ class PortalTypeMetaClass(GhostBaseMetaClass, PropertyHolder): ...@@ -170,7 +175,8 @@ class PortalTypeMetaClass(GhostBaseMetaClass, PropertyHolder):
for klass in cls.mro(): for klass in cls.mro():
if klass.__module__.startswith('erp5.accessor_holder'): if klass.__module__.startswith('erp5.accessor_holder'):
for property in klass._properties: for property in klass._properties:
property_dict.setdefault(property['id'], property) if content or property['type'] != 'content':
property_dict.setdefault(property['id'], property)
return property_dict.values() return property_dict.values()
......
...@@ -3093,15 +3093,18 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor): ...@@ -3093,15 +3093,18 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor):
self.assertEquals(None, person.getProperty('foo_property')) self.assertEquals(None, person.getProperty('foo_property'))
self.assertEquals(None, person.getProperty('foobar_property')) self.assertEquals(None, person.getProperty('foobar_property'))
def testgetInstancePropertyAndBaseCategoryList(self): def test_getInstancePropertyAndBaseCategoryList(self):
""" """
Check that the method getInstancePropertyAndBaseCategoryList return Check that the method getInstancePropertyAndBaseCategoryList return
properties from property sheets correctly properties from property sheets correctly
""" """
portal_type = self.portal.portal_types.Email portal_type = self.portal.portal_types.Person
result_list = portal_type.getInstancePropertyAndBaseCategoryList() result_list = portal_type.getInstancePropertyAndBaseCategoryList()
self.assertTrue("description" in result_list, # Test a simple property, an acquired one on and a category.
"description not in %s" % result_list) for x in "id", "address_city", "function":
self.assertTrue(x in result_list, "%s not in %s" % (x, result_list))
# Values from which acquired properties are fetched are not returned.
self.assertFalse("address" in result_list)
class TestAccessControl(ERP5TypeTestCase): class TestAccessControl(ERP5TypeTestCase):
......
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