Commit 2f683b4e authored by Jérome Perrin's avatar Jérome Perrin

simplify related accessors

parent de579ea9
...@@ -111,163 +111,6 @@ class SetGetter(ListGetter): ...@@ -111,163 +111,6 @@ class SetGetter(ListGetter):
result_set = dict([(x, 0) for x in result_list]).keys() result_set = dict([(x, 0) for x in result_list]).keys()
return result_set return result_set
class DefaultIdGetter(BaseGetter):
"""
Gets a default reference object
"""
_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, warning=0):
self._id = id
self.__name__ = id
self._key = key
self._warning = warning
def __call__(self, instance, *args, **kw):
if self._warning:
LOG("ERP5Type", WARNING, "Deprecated Getter Id: %s" % self._id)
return instance._getDefaultRelatedProperty(
self._key, 'id',
spec=kw.get('spec',()),
filter=kw.get('filter', None),
portal_type=kw.get('portal_type',()),
strict_membership=kw.get('strict_membership',
# 'strict' is deprecated
kw.get('strict', None)),
checked_permission=kw.get('checked_permission', None))
psyco.bind(__call__)
IdGetter = DefaultIdGetter
class IdListGetter(BaseGetter):
"""
Gets a list of reference objects
"""
_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, warning=0):
self._id = id
self.__name__ = id
self._key = key
self._warning = warning
def __call__(self, instance, *args, **kw):
if self._warning:
LOG("ERP5Type", WARNING, "Deprecated Getter Id: %s" % self._id)
return instance._getRelatedPropertyList(
self._key, 'id',
spec=kw.get('spec',()),
filter=kw.get('filter', None),
portal_type=kw.get('portal_type',()),
strict_membership=kw.get('strict_membership',
# 'strict' is deprecated
kw.get('strict', None)),
checked_permission=kw.get('checked_permission', None))
psyco.bind(__call__)
class IdSetGetter(IdListGetter):
"""
Gets a category value set
"""
def __call__(self, instance, *args, **kw):
result_list = IdListGetter.__call__(self, instance, *args, **kw)
result_set = dict([(x, 0) for x in result_list]).keys()
return result_set
class DefaultTitleGetter(BaseGetter):
"""
Gets a default reference object
"""
_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, warning=0):
self._id = id
self.__name__ = id
self._key = key
self._warning = warning
def __call__(self, instance, *args, **kw):
if self._warning:
LOG("ERP5Type", WARNING, "Deprecated Getter Id: %s" % self._id)
return instance._getDefaultRelatedProperty(
self._key, 'title',
spec=kw.get('spec',()),
filter=kw.get('filter', None),
portal_type=kw.get('portal_type',()),
strict_membership=kw.get('strict_membership',
# 'strict' is deprecated
kw.get('strict', None)),
checked_permission=kw.get('checked_permission', None))
psyco.bind(__call__)
TitleGetter = DefaultTitleGetter
class TitleListGetter(BaseGetter):
"""
Gets a list of reference objects
"""
_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, warning=0):
self._id = id
self.__name__ = id
self._key = key
self._warning = warning
def __call__(self, instance, *args, **kw):
if self._warning:
LOG("ERP5Type", WARNING, "Deprecated Getter Id: %s" % self._id)
return instance._getRelatedPropertyList(
self._key, 'title',
spec=kw.get('spec',()),
filter=kw.get('filter', None),
portal_type=kw.get('portal_type',()),
strict_membership=kw.get('strict_membership',
# 'strict' is deprecated
kw.get('strict', None)),
checked_permission=kw.get('checked_permission', None))
psyco.bind(__call__)
class TitleSetGetter(TitleListGetter):
"""
Gets a category value set
"""
def __call__(self, instance, *args, **kw):
result_list = TitleListGetter.__call__(self, instance, *args, **kw)
result_set = dict([(x, 0) for x in result_list]).keys()
return result_set
class DefaultPropertyGetter(BaseGetter): class DefaultPropertyGetter(BaseGetter):
""" """
...@@ -345,3 +188,31 @@ class PropertySetGetter(PropertyListGetter): ...@@ -345,3 +188,31 @@ class PropertySetGetter(PropertyListGetter):
result_list = PropertyListGetter.__call__(self, instance, *args, **kw) result_list = PropertyListGetter.__call__(self, instance, *args, **kw)
result_set = dict([(x, 0) for x in result_list]).keys() result_set = dict([(x, 0) for x in result_list]).keys()
return result_set return result_set
class DefaultIdGetter(PropertyGetter):
def __call__(self, instance, *args, **kw):
return PropertyGetter.__call__(self, instance, 'id', *args, **kw)
IdGetter = DefaultIdGetter
class IdListGetter(PropertyListGetter):
def __call__(self, instance, *args, **kw):
return PropertyListGetter.__call__(self, instance, 'id', *args, **kw)
class IdSetGetter(PropertySetGetter):
def __call__(self, instance, *args, **kw):
return PropertySetGetter.__call__(self, instance, 'id', *args, **kw)
class DefaultTitleGetter(PropertyGetter):
def __call__(self, instance, *args, **kw):
return PropertyGetter.__call__(self, instance, 'title', *args, **kw)
TitleGetter = DefaultTitleGetter
class TitleListGetter(PropertyListGetter):
def __call__(self, instance, *args, **kw):
return PropertyListGetter.__call__(self, instance, 'title', *args, **kw)
class TitleSetGetter(PropertySetGetter):
def __call__(self, instance, *args, **kw):
return PropertySetGetter.__call__(self, instance, 'title', *args, **kw)
...@@ -398,10 +398,15 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor): ...@@ -398,10 +398,15 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor):
portal_type = "Person"), [person_object] ) portal_type = "Person"), [person_object] )
self.assertEquals( category_object.getRegionRelatedTitleList( self.assertEquals( category_object.getRegionRelatedTitleList(
portal_type = "Person"), [person_title] ) portal_type = "Person"), [person_title] )
self.assertEquals( category_object.getRegionRelatedTitleSet(
portal_type = "Person"), [person_title] )
self.assertEquals( category_object.getRegionRelatedList( self.assertEquals( category_object.getRegionRelatedList(
portal_type = "Person"), [person_relative_url] ) portal_type = "Person"), [person_relative_url] )
self.assertEquals( category_object.getRegionRelatedIdList( self.assertEquals( category_object.getRegionRelatedIdList(
portal_type = "Person"), [person_id] ) portal_type = "Person"), [person_id] )
self.assertEquals( category_object.getRegionRelatedIdSet(
portal_type = "Person"), [person_id] )
def checkRelationUnset(self): def checkRelationUnset(self):
self.commit() self.commit()
person_object.reindexObject() person_object.reindexObject()
......
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