Commit 6e9a7048 authored by Jérome Perrin's avatar Jérome Perrin

make $(Property)Getter reuse ValueGetter

parent 836a3594
...@@ -163,30 +163,12 @@ class SetGetter(ListGetter): ...@@ -163,30 +163,12 @@ class SetGetter(ListGetter):
return result_set return result_set
class DefaultTitleGetter(BaseGetter): class DefaultTitleGetter(DefaultGetter):
"""
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):
self._id = id
self.__name__ = id
self._key = key
def __call__(self, instance, *args, **kw): def __call__(self, instance, *args, **kw):
o = instance._getDefaultAcquiredValue(self._key, **kw) o = DefaultGetter.__call__(self, instance, *args, **kw)
if o is None: if o is None:
return None return None
return o.getTitle() return o.getTitle()
psyco.bind(__call__) psyco.bind(__call__)
class TitleListGetter(ListGetter): class TitleListGetter(ListGetter):
...@@ -228,34 +210,12 @@ class TranslatedTitleSetGetter(TranslatedTitleListGetter): ...@@ -228,34 +210,12 @@ class TranslatedTitleSetGetter(TranslatedTitleListGetter):
return result_set return result_set
class DefaultReferenceGetter(BaseGetter): class DefaultReferenceGetter(DefaultGetter):
"""
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):
self._id = id
self.__name__ = id
self._key = key
def __call__(self, instance, *args, **kw): def __call__(self, instance, *args, **kw):
o = instance._getDefaultAcquiredValue(self._key, o = DefaultGetter.__call__(self, instance, *args, **kw)
spec=kw.get('spec',()),
filter=kw.get('filter', None),
portal_type=kw.get('portal_type',()),
checked_permission=kw.get('checked_permission', None))
if o is None: if o is None:
return None return None
return o.getReference() return o.getReference()
psyco.bind(__call__) psyco.bind(__call__)
class ReferenceListGetter(ListGetter): class ReferenceListGetter(ListGetter):
...@@ -274,37 +234,13 @@ class ReferenceSetGetter(ReferenceListGetter): ...@@ -274,37 +234,13 @@ class ReferenceSetGetter(ReferenceListGetter):
return result_set return result_set
class DefaultUidGetter(BaseGetter): class DefaultUidGetter(DefaultGetter):
"""
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):
self._id = id
self.__name__ = id
self._key = key
def __call__(self, instance, *args, **kw): def __call__(self, instance, *args, **kw):
value = instance._getDefaultAcquiredValue(self._key, o = DefaultGetter.__call__(self, instance, *args, **kw)
spec=kw.get('spec',()), if o is None:
filter=kw.get('filter', None),
portal_type=kw.get('portal_type',()),
checked_permission=kw.get('checked_permission', None))
if value is not None:
return value.getUid()
else:
return None return None
return o.getUid()
psyco.bind(__call__) psyco.bind(__call__)
UidGetter = DefaultUidGetter UidGetter = DefaultUidGetter
class UidListGetter(ListGetter): class UidListGetter(ListGetter):
...@@ -382,98 +318,33 @@ class UidDefaultSetter(UidSetSetter): ...@@ -382,98 +318,33 @@ class UidDefaultSetter(UidSetSetter):
checked_permission=kw.get('checked_permission', None)) checked_permission=kw.get('checked_permission', None))
return (instance, ) return (instance, )
class DefaultIdGetter(BaseGetter): class DefaultIdGetter(DefaultGetter):
"""
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):
self._id = id
self.__name__ = id
self._key = key
def __call__(self, instance, *args, **kw): def __call__(self, instance, *args, **kw):
value = instance._getDefaultAcquiredValue(self._key, spec=kw.get('spec',()), o = DefaultGetter.__call__(self, instance, *args, **kw)
filter=kw.get('filter', None), if o is None:
portal_type=kw.get('portal_type',()),
checked_permission=kw.get('checked_permission', None))
if value is not None:
return value.getId()
else:
return None return None
return o.getId()
psyco.bind(__call__) psyco.bind(__call__)
IdGetter = DefaultIdGetter IdGetter = DefaultIdGetter
class DefaultTitleOrIdGetter(BaseGetter): class DefaultTitleOrIdGetter(DefaultGetter):
"""
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):
self._id = id
self.__name__ = id
self._key = key
def __call__(self, instance, *args, **kw): def __call__(self, instance, *args, **kw):
value = instance._getDefaultAcquiredValue(self._key, spec=kw.get('spec',()), o = DefaultGetter.__call__(self, instance, *args, **kw)
filter=kw.get('filter', None), if o is None:
portal_type=kw.get('portal_type',()),
checked_permission=kw.get('checked_permission', None))
if value is not None:
return value.getTitleOrId()
else:
return None return None
return o.getTitleOrId()
psyco.bind(__call__) psyco.bind(__call__)
TitleOrIdGetter = DefaultTitleOrIdGetter TitleOrIdGetter = DefaultTitleOrIdGetter
class DefaultLogicalPathGetter(BaseGetter): class DefaultLogicalPathGetter(DefaultGetter):
"""
Gets a default logical path 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 = ()
_item_method = 'getTitle' _item_method = 'getTitle'
def __init__(self, id, key):
self._id = id
self.__name__ = id
self._key = key
def __call__(self, instance, *args, **kw): def __call__(self, instance, *args, **kw):
value = instance._getDefaultAcquiredValue(self._key, spec=kw.get('spec',()), o = DefaultGetter.__call__(self, instance, *args, **kw)
filter=kw.get('filter', None), if o is None:
portal_type=kw.get('portal_type',()),
checked_permission=kw.get('checked_permission', None))
if value is not None:
return value.getLogicalPath(item_method=self._item_method)
return None return None
return o.getLogicalPath(item_method=self._item_method)
psyco.bind(__call__) psyco.bind(__call__)
LogicalPathGetter = DefaultLogicalPathGetter LogicalPathGetter = DefaultLogicalPathGetter
...@@ -516,34 +387,12 @@ class LogicalPathSetGetter(LogicalPathListGetter): ...@@ -516,34 +387,12 @@ class LogicalPathSetGetter(LogicalPathListGetter):
return result_set return result_set
class DefaultPropertyGetter(BaseGetter): class DefaultPropertyGetter(DefaultGetter):
"""
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):
self._id = id
self.__name__ = id
self._key = key
def __call__(self, instance, key, *args, **kw): def __call__(self, instance, key, *args, **kw):
value = instance._getDefaultAcquiredValue(self._key, o = DefaultGetter.__call__(self, instance, *args, **kw)
spec=kw.get('spec',()), if o is None:
filter=kw.get('filter', None),
portal_type=kw.get('portal_type',()),
checked_permission=kw.get('checked_permission', None))
if value is not None:
return value.getProperty(key)
else:
return None return None
return o.getProperty(key)
psyco.bind(__call__) psyco.bind(__call__)
......
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