Commit 5de789b5 authored by Sebastien Robin's avatar Sebastien Robin

- stop doing strange things with setReference on properties

- use Reference Propertysheet instead of add reference property
  in another propertysheet

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@43833 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent ac69c319
...@@ -48,7 +48,8 @@ class CategoryProperty(IdAsReferenceMixin('_category'), XMLObject): ...@@ -48,7 +48,8 @@ class CategoryProperty(IdAsReferenceMixin('_category'), XMLObject):
security = ClassSecurityInfo() security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation) security.declareObjectProtected(Permissions.AccessContentsInformation)
property_sheets = (PropertySheet.SimpleItem,) property_sheets = (PropertySheet.SimpleItem,
PropertySheet.Reference)
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'exportToFilesystemDefinition') 'exportToFilesystemDefinition')
...@@ -66,7 +67,7 @@ class CategoryProperty(IdAsReferenceMixin('_category'), XMLObject): ...@@ -66,7 +67,7 @@ class CategoryProperty(IdAsReferenceMixin('_category'), XMLObject):
Set the Reference from a filesystem definition of a property Set the Reference from a filesystem definition of a property
""" """
return context.newContent(portal_type=cls.portal_type, return context.newContent(portal_type=cls.portal_type,
reference=category_name) id=category_name + cls.getIdAsReferenceSuffix())
getter_definition_dict = { getter_definition_dict = {
# normal accessors # normal accessors
......
...@@ -46,12 +46,12 @@ class StandardProperty(IdAsReferenceMixin('_property'), XMLObject): ...@@ -46,12 +46,12 @@ class StandardProperty(IdAsReferenceMixin('_property'), XMLObject):
property_sheets = (PropertySheet.SimpleItem, property_sheets = (PropertySheet.SimpleItem,
PropertySheet.StandardProperty, PropertySheet.StandardProperty,
PropertySheet.Reference,
PropertySheet.TranslatableProperty) PropertySheet.TranslatableProperty)
# Names mapping between filesystem to ZODB property, only meaningful # Names mapping between filesystem to ZODB property, only meaningful
# when importing a property from its filesystem definition # when importing a property from its filesystem definition
_name_mapping_filesystem_to_zodb_dict = {'id': 'reference', _name_mapping_filesystem_to_zodb_dict = {'type': 'elementary_type',
'type': 'elementary_type',
'default': 'property_default'} 'default': 'property_default'}
# ZODB name of attributes whose value is a TALES Expression string # ZODB name of attributes whose value is a TALES Expression string
...@@ -165,6 +165,10 @@ class StandardProperty(IdAsReferenceMixin('_property'), XMLObject): ...@@ -165,6 +165,10 @@ class StandardProperty(IdAsReferenceMixin('_property'), XMLObject):
value = isinstance(value, Expression) and \ value = isinstance(value, Expression) and \
value.text or 'python: ' + repr(value) value.text or 'python: ' + repr(value)
# set correctly the id by following naming conventions
if zodb_property_name == 'id':
value += cls.getIdAsReferenceSuffix()
zodb_property_dict[zodb_property_name] = value zodb_property_dict[zodb_property_name] = value
return zodb_property_dict return zodb_property_dict
......
...@@ -61,7 +61,8 @@ def IdAsReferenceMixin(suffix): ...@@ -61,7 +61,8 @@ def IdAsReferenceMixin(suffix):
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getIdAsReferenceSuffix') 'getIdAsReferenceSuffix')
def getIdAsReferenceSuffix(self): @staticmethod
def getIdAsReferenceSuffix():
return suffix return suffix
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
...@@ -70,18 +71,6 @@ def IdAsReferenceMixin(suffix): ...@@ -70,18 +71,6 @@ def IdAsReferenceMixin(suffix):
id = self.id id = self.id
if id[suffix_index:] == suffix: if id[suffix_index:] == suffix:
return id[:suffix_index] return id[:suffix_index]
# BBB return self._baseGetReference(default=default)
reference = self.__dict__.get('default_reference')
if reference:
transaction.get().addBeforeCommitHook(self.__migrate)
return reference
return default
def _setReference(self, value):
self.__dict__.pop('default_reference', None) # BBB
self.setId(value + suffix)
security.declareProtected(Permissions.ModifyPortalContent, 'setReference')
setReference = _setReference
return IdAsReferenceMixin return IdAsReferenceMixin
...@@ -66,6 +66,7 @@ class ConstraintMixin(IdAsReferenceMixin('_constraint'), Predicate): ...@@ -66,6 +66,7 @@ class ConstraintMixin(IdAsReferenceMixin('_constraint'), Predicate):
implements( IConstraint, ) implements( IConstraint, )
property_sheets = (PropertySheet.SimpleItem, property_sheets = (PropertySheet.SimpleItem,
PropertySheet.Reference,
PropertySheet.Predicate) PropertySheet.Predicate)
def _getMessage(self, message_id): def _getMessage(self, message_id):
...@@ -186,8 +187,9 @@ class ConstraintMixin(IdAsReferenceMixin('_constraint'), Predicate): ...@@ -186,8 +187,9 @@ class ConstraintMixin(IdAsReferenceMixin('_constraint'), Predicate):
base_constraint_definition_dict['portal_type'] = cls.portal_type base_constraint_definition_dict['portal_type'] = cls.portal_type
base_constraint_definition_dict['reference'] = \ base_constraint_definition_dict['id'] = \
filesystem_definition_copy_dict.pop('id') filesystem_definition_copy_dict.pop('id') + \
cls.getIdAsReferenceSuffix()
base_constraint_definition_dict['description'] = \ base_constraint_definition_dict['description'] = \
filesystem_definition_copy_dict.pop('description', '') filesystem_definition_copy_dict.pop('description', '')
......
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