Commit bd419093 authored by Jérome Perrin's avatar Jérome Perrin

Generate testers accessors for acquired content properties

parent 43ebcbd8
...@@ -140,6 +140,14 @@ class Coordinate(Base): ...@@ -140,6 +140,14 @@ class Coordinate(Base):
""" """
return self.asText() return self.asText()
security.declareProtected( Permissions.AccessContentsInformation,
'hasText')
def hasText(self):
"""
calls asText
"""
return bool(self.asText())
security.declareProtected(Permissions.AccessContentsInformation, 'getCoordinateText') security.declareProtected(Permissions.AccessContentsInformation, 'getCoordinateText')
def getCoordinateText(self, default=_marker): def getCoordinateText(self, default=_marker):
"""Fallback on splitted values (old API) """Fallback on splitted values (old API)
......
...@@ -397,6 +397,21 @@ class TestERP5Base(ERP5TypeTestCase): ...@@ -397,6 +397,21 @@ class TestERP5Base(ERP5TypeTestCase):
""" """
organisation = sequence.get('organisation') organisation = sequence.get('organisation')
self.assertFalse(organisation.hasDefaultAddress())
self.assertFalse(organisation.hasDefaultAddressCoordinateText())
self.assertFalse(organisation.hasDefaultAddressRegion())
self.assertFalse(organisation.hasDefaultAddressCity())
self.assertFalse(organisation.hasDefaultTelephone())
self.assertFalse(organisation.hasDefaultTelephoneCoordinateText())
self.assertFalse(organisation.hasDefaultFax())
self.assertFalse(organisation.hasDefaultFaxCoordinateText())
self.assertFalse(organisation.hasDefaultEmail())
self.assertFalse(organisation.hasDefaultEmailText())
self.assertFalse(organisation.hasDefaultEmailCoordinateText())
self.assertFalse(organisation.hasDefaultEmailUrlString())
region = self.getCategoryDictList(base_category='region')[0] region = self.getCategoryDictList(base_category='region')[0]
region_path = region["category_relative_url"] region_path = region["category_relative_url"]
region_title = region["title"] region_title = region["title"]
...@@ -444,20 +459,28 @@ class TestERP5Base(ERP5TypeTestCase): ...@@ -444,20 +459,28 @@ class TestERP5Base(ERP5TypeTestCase):
self.assertEquals( organisation.getDefaultTelephoneText() self.assertEquals( organisation.getDefaultTelephoneText()
, default_telephone.asText() , default_telephone.asText()
) )
self.assertTrue(organisation.hasDefaultTelephone())
self.assertTrue(organisation.hasDefaultTelephoneCoordinateText())
self.failUnless('default_fax' in organisation.contentIds()) self.failUnless('default_fax' in organisation.contentIds())
default_fax = organisation.default_fax default_fax = organisation.default_fax
self.assertEquals(default_fax.getPortalType(), 'Fax') self.assertEquals(default_fax.getPortalType(), 'Fax')
self.assertEquals( organisation.getDefaultFaxText() self.assertEquals( organisation.getDefaultFaxText()
, default_fax.asText() , default_fax.asText()
) )
self.assertTrue(organisation.hasDefaultFax())
self.assertTrue(organisation.hasDefaultFaxCoordinateText())
self.failUnless('default_email' in organisation.contentIds()) self.failUnless('default_email' in organisation.contentIds())
default_email = organisation.default_email default_email = organisation.default_email
self.assertEquals(default_email.getPortalType(), 'Email') self.assertEquals(default_email.getPortalType(), 'Email')
self.assertEquals( organisation.getDefaultEmailText() self.assertEquals( organisation.getDefaultEmailText()
, default_email.asText() , default_email.asText()
) )
self.assertTrue(organisation.hasDefaultEmail())
self.assertTrue(organisation.hasDefaultEmailText())
self.assertTrue(organisation.hasDefaultEmailCoordinateText())
self.assertTrue(organisation.hasDefaultEmailUrlString())
def stepCreatePerson(self, sequence=None, sequence_list=None, **kw): def stepCreatePerson(self, sequence=None, sequence_list=None, **kw):
""" """
...@@ -1326,11 +1349,13 @@ class TestERP5Base(ERP5TypeTestCase): ...@@ -1326,11 +1349,13 @@ class TestERP5Base(ERP5TypeTestCase):
person = self.portal.person_module.newContent(portal_type='Person') person = self.portal.person_module.newContent(portal_type='Person')
self.assertEquals(None, person.getDefaultEmailCoordinateText()) self.assertEquals(None, person.getDefaultEmailCoordinateText())
self.assertFalse(person.hasDefaultEmailCoordinateText())
# On persons, Email is acquired from the default carreer # On persons, Email is acquired from the default carreer
person.setDefaultCareerSubordinationValue(organisation) person.setDefaultCareerSubordinationValue(organisation)
self.assertEquals('organisation@example.com', self.assertEquals('organisation@example.com',
person.getDefaultEmailCoordinateText()) person.getDefaultEmailCoordinateText())
self.assertFalse(person.hasDefaultEmailCoordinateText())
# we can set different values on the person address without modifying # we can set different values on the person address without modifying
# organisation address # organisation address
...@@ -1338,6 +1363,7 @@ class TestERP5Base(ERP5TypeTestCase): ...@@ -1338,6 +1363,7 @@ class TestERP5Base(ERP5TypeTestCase):
self.assertEquals('person@example.com', person.getDefaultEmailCoordinateText()) self.assertEquals('person@example.com', person.getDefaultEmailCoordinateText())
self.assertEquals('organisation@example.com', self.assertEquals('organisation@example.com',
organisation.getDefaultEmailCoordinateText()) organisation.getDefaultEmailCoordinateText())
self.assertTrue(person.hasDefaultEmailCoordinateText())
def test_alternate_email_acquisition(self): def test_alternate_email_acquisition(self):
organisation = \ organisation = \
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
from Acquisition import aq_base from Acquisition import aq_base
from ZPublisher.HTTPRequest import FileUpload from ZPublisher.HTTPRequest import FileUpload
from Base import func_code, type_definition, list_types, ATTRIBUTE_PREFIX, Getter as BaseGetter, Setter as BaseSetter from Base import func_code, type_definition, list_types, ATTRIBUTE_PREFIX, Getter as BaseGetter, Setter as BaseSetter, Tester as BaseTester
from Products.ERP5Type.PsycoWrapper import psyco from Products.ERP5Type.PsycoWrapper import psyco
from zLOG import LOG from zLOG import LOG
...@@ -200,3 +200,86 @@ class Setter(BaseSetter): ...@@ -200,3 +200,86 @@ class Setter(BaseSetter):
DefaultSetter = Setter DefaultSetter = Setter
class Tester(BaseTester):
"""
Tests if an attribute value exists
"""
_need__name__=1
# Generic Definition of Method Object
# This is required to call the method form the Web
func_code = func_code()
func_code.co_varnames = ('self',)
func_code.co_argcount = 1
func_defaults = ()
def __init__(self, id, key, property_type, portal_type, acquired_property,
acquisition_base_category,
acquisition_portal_type,
acquisition_accessor_id,
acquisition_copy_value,
acquisition_mask_value,
storage_id=None,
alt_accessor_id = None,
acquisition_object_id=None,
is_list_type = 0,
is_tales_type = 0
):
if type(portal_type) == type('a'): portal_type = (portal_type, )
self._id = id
self.__name__ = id
self._key = key
self._property_type = property_type
self._portal_type = portal_type
self._null = type_definition[property_type]['null']
# These values are hashed by _get*AcquiredProperty: to be
# hashable, they need to be converted to tuples
if isinstance(acquisition_base_category, list):
acquisition_base_category = tuple(acquisition_base_category)
if isinstance(acquisition_portal_type, list):
acquisition_portal_type = tuple(acquisition_portal_type)
if isinstance(acquisition_object_id, list):
acquisition_object_id = tuple(acquisition_object_id)
if isinstance(alt_accessor_id, list):
alt_accessor_id = tuple(alt_accessor_id)
self._acquisition_base_category = acquisition_base_category
self._acquisition_portal_type = acquisition_portal_type
self._acquisition_accessor_id = acquisition_accessor_id
self._acquisition_copy_value = acquisition_copy_value
self._acquisition_mask_value = acquisition_mask_value
self._acquired_property = acquired_property
if storage_id is None:
storage_id = "%s%s" % (ATTRIBUTE_PREFIX, key)
self._storage_id = storage_id
self._alt_accessor_id = alt_accessor_id
self._acquisition_object_id = acquisition_object_id
self._is_list_type = is_list_type
self._is_tales_type = is_tales_type
def __call__(self, instance, *args, **kw):
if self._storage_id:
# If this property is supposed to be stored as a content subobject,
# then we consider that if the subobject does not exist then the
# property is not set, even if it is acquired from another document.
o = instance._getOb(self._storage_id, None)
if o is None:
return False
value = instance._getDefaultAcquiredProperty(self._key, None, self._null,
base_category=self._acquisition_base_category,
portal_type=self._acquisition_portal_type,
accessor_id=self._acquisition_accessor_id,
copy_value=self._acquisition_copy_value,
mask_value=self._acquisition_mask_value,
storage_id=self._storage_id,
alt_accessor_id=self._alt_accessor_id,
acquisition_object_id=self._acquisition_object_id,
is_list_type=self._is_list_type,
is_tales_type=self._is_tales_type,
checked_permission=kw.get('checked_permission', None)
)
if value is not None:
return value.hasProperty(self._acquired_property)
return False
...@@ -430,6 +430,10 @@ class AcquiredProperty(StandardProperty): ...@@ -430,6 +430,10 @@ class AcquiredProperty(StandardProperty):
'_baseGetDefault%s': AcquiredPropertyAccessor.DefaultGetter, '_baseGetDefault%s': AcquiredPropertyAccessor.DefaultGetter,
} }
_acquisition_base_category_acquired_property_id_tester_definition_dict = {
'has%s': AcquiredPropertyAccessor.Tester,
}
_acquisition_base_category_acquired_property_id_setter_definition_dict = { _acquisition_base_category_acquired_property_id_setter_definition_dict = {
'_set%s': AcquiredPropertyAccessor.Setter, '_set%s': AcquiredPropertyAccessor.Setter,
'_baseSet%s': AcquiredPropertyAccessor.Setter, '_baseSet%s': AcquiredPropertyAccessor.Setter,
...@@ -457,21 +461,29 @@ class AcquiredProperty(StandardProperty): ...@@ -457,21 +461,29 @@ class AcquiredProperty(StandardProperty):
property_dict['multivalued'], property_dict['multivalued'],
property_dict['elementary_type'] == 'tales') property_dict['elementary_type'] == 'tales')
composed_id = "%s_%s" % (property_dict['reference'], aq_id) for composed_id in ("%s_%s" % (property_dict['reference'], aq_id),
"default_%s_%s" % (property_dict['reference'], aq_id)):
cls._applyDefinitionFormatDictOnAccessorHolder( cls._applyDefinitionFormatDictOnAccessorHolder(
composed_id, composed_id,
cls._acquisition_base_category_acquired_property_id_getter_definition_dict, cls._acquisition_base_category_acquired_property_id_getter_definition_dict,
accessor_holder, accessor_holder,
acquired_property_id_argument_list, acquired_property_id_argument_list,
property_dict['read_permission']) property_dict['read_permission'])
cls._applyDefinitionFormatDictOnAccessorHolder( cls._applyDefinitionFormatDictOnAccessorHolder(
composed_id, composed_id,
cls._acquisition_base_category_acquired_property_id_setter_definition_dict, cls._acquisition_base_category_acquired_property_id_tester_definition_dict,
accessor_holder, accessor_holder,
acquired_property_id_argument_list, acquired_property_id_argument_list,
property_dict['write_permission']) property_dict['read_permission'])
cls._applyDefinitionFormatDictOnAccessorHolder(
composed_id,
cls._acquisition_base_category_acquired_property_id_setter_definition_dict,
accessor_holder,
acquired_property_id_argument_list,
property_dict['write_permission'])
_content_type_acquired_property_id_getter_definition_dict = { _content_type_acquired_property_id_getter_definition_dict = {
'get%s': ContentProperty.Getter 'get%s': ContentProperty.Getter
......
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