Commit cbacf592 authored by Yoshinori Okuji's avatar Yoshinori Okuji

Generate reference getters for categories.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@5851 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 8fb922b5
...@@ -177,6 +177,64 @@ class TitleListGetter(Method): ...@@ -177,6 +177,64 @@ class TitleListGetter(Method):
TitleSetGetter = TitleListGetter # Error XXX TitleSetGetter = TitleListGetter # Error XXX
class DefaultReferenceGetter(Method):
"""
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):
o = instance._getDefaultAcquiredValue(self._key,
spec=kw.get('spec',()),
filter=kw.get('filter', None),
portal_type=kw.get('portal_type',()))
if o is None:
return None
return o.getReference()
psyco.bind(__call__)
class ReferenceListGetter(Method):
"""
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):
self._id = id
self.__name__ = id
self._key = key
def __call__(self, instance, *args, **kw):
return [x.getReference() for x in instance._getAcquiredValueList(self._key,
spec=kw.get('spec',()),
filter=kw.get('filter', None),
portal_type=kw.get('portal_type',()))
]
psyco.bind(__call__)
ReferenceSetGetter = ReferenceListGetter # Error XXX
class DefaultUidGetter(Method): class DefaultUidGetter(Method):
""" """
Gets a default reference object Gets a default reference object
......
...@@ -2128,6 +2128,24 @@ def createValueAccessors(property_holder, id, ...@@ -2128,6 +2128,24 @@ def createValueAccessors(property_holder, id,
if not hasattr(property_holder, accessor_name): if not hasattr(property_holder, accessor_name):
setattr(property_holder, accessor_name, accessor.dummy_copy(accessor_name)) setattr(property_holder, accessor_name, accessor.dummy_copy(accessor_name))
accessor_name = 'get' + UpperCase(id) + 'ReferenceList'
accessor = Value.ReferenceListGetter(accessor_name, id)
if not hasattr(property_holder, accessor_name):
setattr(property_holder, accessor_name, accessor)
property_holder.security.declareProtected(read_permission, accessor_name)
accessor_name = '_categoryGet' + UpperCase(id) + 'ReferenceList'
if not hasattr(property_holder, accessor_name):
setattr(property_holder, accessor_name, accessor.dummy_copy(accessor_name))
accessor_name = 'get' + UpperCase(id) + 'ReferenceSet'
accessor = Value.ReferenceSetGetter(accessor_name, id)
if not hasattr(property_holder, accessor_name):
setattr(property_holder, accessor_name, accessor)
property_holder.security.declareProtected(read_permission, accessor_name)
accessor_name = '_categoryGet' + UpperCase(id) + 'ReferenceSet'
if not hasattr(property_holder, accessor_name):
setattr(property_holder, accessor_name, accessor.dummy_copy(accessor_name))
accessor_name = 'get' + UpperCase(id) + 'IdList' accessor_name = 'get' + UpperCase(id) + 'IdList'
accessor = Value.IdListGetter(accessor_name, id) accessor = Value.IdListGetter(accessor_name, id)
if not hasattr(property_holder, accessor_name): if not hasattr(property_holder, accessor_name):
...@@ -2237,6 +2255,22 @@ def createValueAccessors(property_holder, id, ...@@ -2237,6 +2255,22 @@ def createValueAccessors(property_holder, id,
if not hasattr(property_holder, accessor_name): if not hasattr(property_holder, accessor_name):
setattr(property_holder, accessor_name, accessor.dummy_copy(accessor_name)) setattr(property_holder, accessor_name, accessor.dummy_copy(accessor_name))
accessor_name = 'getDefault' + UpperCase(id) + 'Reference'
accessor = Value.DefaultReferenceGetter(accessor_name, id)
if not hasattr(property_holder, accessor_name):
setattr(property_holder, accessor_name, accessor)
property_holder.security.declareProtected(read_permission, accessor_name)
accessor_name = 'get' + UpperCase(id) + 'Reference'
if not hasattr(property_holder, accessor_name):
setattr(property_holder, accessor_name, accessor.dummy_copy(accessor_name))
property_holder.security.declareProtected(read_permission, accessor_name)
accessor_name = '_categoryGetDefault' + UpperCase(id) + 'Reference'
if not hasattr(property_holder, accessor_name):
setattr(property_holder, accessor_name, accessor.dummy_copy(accessor_name))
accessor_name = '_categoryGet' + UpperCase(id) + 'Reference'
if not hasattr(property_holder, accessor_name):
setattr(property_holder, accessor_name, accessor.dummy_copy(accessor_name))
accessor_name = 'getDefault' + UpperCase(id) + 'Uid' accessor_name = 'getDefault' + UpperCase(id) + 'Uid'
accessor = Value.DefaultUidGetter(accessor_name, id) accessor = Value.DefaultUidGetter(accessor_name, id)
if not hasattr(property_holder, accessor_name): if not hasattr(property_holder, accessor_name):
......
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