Commit 2c00c5a1 authored by Romain Courteaud's avatar Romain Courteaud

Implement SetGetter and SetSetter.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@7158 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 83429e82
......@@ -175,4 +175,12 @@ class ListGetter(Method):
psyco.bind(__call__)
SetGetter = ListGetter # ERROR
class SetGetter(ListGetter):
"""
Gets a category value set
"""
def __call__(self, instance, *args, **kw):
result_list = ListGetter.__call__(self, instance, *args, **kw)
result_set = dict([(x, 0) for x in result_list]).keys()
return result_set
......@@ -174,7 +174,15 @@ class ListGetter(Method):
return instance._getAcquiredCategoryMembershipList(self._key, **kw)
psyco.bind(__call__)
SetGetter = ListGetter # XXX ERROR
class SetGetter(ListGetter):
"""
Gets a category value set
"""
def __call__(self, instance, *args, **kw):
result_list = ListGetter.__call__(self, instance, *args, **kw)
result_set = dict([(x, 0) for x in result_list]).keys()
return result_set
# ItemList is outdated XXX -> ItemList
......
......@@ -110,7 +110,7 @@ class Setter(DefaultSetter):
if not self._reindex:
# Modify the property
if value in self._null:
setattr(instance, self._storage_id, None)
setattr(instance, self._storage_id, ())
elif self._is_tales_type:
setattr(instance, self._storage_id, str(value))
else:
......@@ -179,20 +179,35 @@ class SetSetter(Method):
if len(value) > 0:
list_value = getattr(instance, self._storage_id, None)
if list_value is None: list_value = []
# if len(list_value) > 0:
# my_dict = {}
# default_value = list_value[0]
# for v in value:
# my_dict[v] = 0
# if my_dict.has_key(default_value):
# del my_dict[default_value]
# # If we change the set, the default value must be in the new set
# if default_value in value:
# new_list_value = [default_value] + my_dict.keys()
# else:
# new_list_value = my_dict.keys()
# else:
# new_list_value = value
if len(list_value) > 0:
my_dict = {}
default_value = list_value[0]
for v in value:
my_dict[v] = 0
if my_dict.has_key(default_value):
del my_dict[default_value]
# If we change the set, the default value must be in the new set
if default_value in value:
new_list_value = [default_value] + my_dict.keys()
else:
my_dict = dict((x, 0) for x in value if x!=default_value)
new_list_value = my_dict.keys()
# If we change the set,
# the default value must be in the new set
if default_value in value:
new_list_value.insert(0, default_value)
else:
new_list_value = value
else:
# The list has no default property -> it is empty
new_list_value = []
......@@ -294,6 +309,15 @@ class ListGetter(Method):
psyco.bind(__call__)
SetGetter = ListGetter
class SetGetter(ListGetter):
"""
Gets an attribute value. A default value can be
provided if needed
"""
def __call__(self, instance, *args, **kw):
result_list = ListGetter.__call__(self, instance, *args, **kw)
result_set = dict([(x, 0) for x in result_list]).keys()
return result_set
Tester = Base.Tester
......@@ -89,4 +89,12 @@ class ListGetter(Method):
psyco.bind(__call__)
SetGetter = ListGetter
class SetGetter(ListGetter):
"""
Gets a category value set
"""
def __call__(self, instance, *args, **kw):
result_list = ListGetter.__call__(self, instance, *args, **kw)
result_set = dict([(x, 0) for x in result_list]).keys()
return result_set
......@@ -97,7 +97,15 @@ class ListGetter(Method):
psyco.bind(__call__)
SetGetter = ListGetter # Error XXX
class SetGetter(ListGetter):
"""
Gets a category value set
"""
def __call__(self, instance, *args, **kw):
result_list = ListGetter.__call__(self, instance, *args, **kw)
result_set = dict([(x, 0) for x in result_list]).keys()
return result_set
class DefaultIdGetter(Method):
"""
......@@ -164,7 +172,14 @@ class IdListGetter(Method):
psyco.bind(__call__)
IdSetGetter = IdListGetter # XXX Error
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(Method):
"""
......@@ -229,7 +244,15 @@ class TitleListGetter(Method):
kw.get('strict', None))) # 'strict' is deprecated
psyco.bind(__call__)
TitleSetGetter = TitleListGetter # XXX Error
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(Method):
"""
......@@ -293,4 +316,12 @@ class PropertyListGetter(Method):
kw.get('strict', None))) # 'strict' is deprecated
psyco.bind(__call__)
PropertySetGetter = PropertyListGetter # Error XXX
class PropertySetGetter(PropertyListGetter):
"""
Gets a category value set
"""
def __call__(self, instance, *args, **kw):
result_list = PropertyListGetter.__call__(self, instance, *args, **kw)
result_set = dict([(x, 0) for x in result_list]).keys()
return result_set
......@@ -117,7 +117,15 @@ class ListGetter(Method):
psyco.bind(__call__)
SetGetter = ListGetter # Error XXX
class SetGetter(ListGetter):
"""
Gets a category value set
"""
def __call__(self, instance, *args, **kw):
result_list = ListGetter.__call__(self, instance, *args, **kw)
result_set = dict([(x, 0) for x in result_list]).keys()
return result_set
class DefaultTitleGetter(Method):
"""
......@@ -175,7 +183,15 @@ class TitleListGetter(Method):
psyco.bind(__call__)
TitleSetGetter = TitleListGetter # Error XXX
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 DefaultTranslatedTitleGetter(Method):
"""
......@@ -233,7 +249,16 @@ class TranslatedTitleListGetter(Method):
psyco.bind(__call__)
TranslatedTitleSetGetter = TranslatedTitleListGetter # Error XXX
class TranslatedTitleSetGetter(TranslatedTitleListGetter):
"""
Gets a category value set
"""
def __call__(self, instance, *args, **kw):
result_list = TranslatedTitleListGetter.__call__(
self, instance, *args, **kw)
result_set = dict([(x, 0) for x in result_list]).keys()
return result_set
class DefaultReferenceGetter(Method):
"""
......@@ -291,7 +316,16 @@ class ReferenceListGetter(Method):
psyco.bind(__call__)
ReferenceSetGetter = ReferenceListGetter # Error XXX
class ReferenceSetGetter(ReferenceListGetter):
"""
Gets a category value set
"""
def __call__(self, instance, *args, **kw):
result_list = ReferenceListGetter.__call__(
self, instance, *args, **kw)
result_set = dict([(x, 0) for x in result_list]).keys()
return result_set
class DefaultUidGetter(Method):
"""
......@@ -352,7 +386,16 @@ class UidListGetter(Method):
psyco.bind(__call__)
UidSetGetter = UidListGetter # Error XXX
class UidSetGetter(UidListGetter):
"""
Gets a category value set
"""
def __call__(self, instance, *args, **kw):
result_list = UidListGetter.__call__(
self, instance, *args, **kw)
result_set = dict([(x, 0) for x in result_list]).keys()
return result_set
class UidSetter(Method):
"""
......@@ -496,7 +539,16 @@ class IdListGetter(Method):
psyco.bind(__call__)
IdSetGetter = IdListGetter # Error XXX
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 LogicalPathListGetter(Method):
"""
......@@ -523,7 +575,16 @@ class LogicalPathListGetter(Method):
portal_type=kw.get('portal_type',()))
]
LogicalPathSetGetter = LogicalPathListGetter # Error XXX
class LogicalPathSetGetter(LogicalPathListGetter):
"""
Gets a category value set
"""
def __call__(self, instance, *args, **kw):
result_list = LogicalPathListGetter.__call__(
self, instance, *args, **kw)
result_set = dict([(x, 0) for x in result_list]).keys()
return result_set
class DefaultPropertyGetter(Method):
"""
......@@ -584,4 +645,13 @@ class PropertyListGetter(Method):
psyco.bind(__call__)
PropertySetGetter = PropertyListGetter # Error XXX
class PropertySetGetter(PropertyListGetter):
"""
Gets a category value set
"""
def __call__(self, instance, *args, **kw):
result_list = PropertyListGetter.__call__(
self, instance, *args, **kw)
result_set = dict([(x, 0) for x in result_list]).keys()
return result_set
......@@ -2126,6 +2126,10 @@ def createCategoryAccessors(property_holder, id,
setter_name = '_categorySet' + UpperCase(id) + 'Set'
if not hasattr(property_holder, setter_name):
setattr(property_holder, setter_name, setter.dummy_copy(setter_name))
setter_name = 'set' + UpperCase(id) + 'Set'
if not hasattr(property_holder, setter_name):
setattr(property_holder, setter_name, setter.dummy_copy(setter_name))
property_holder.security.declareProtected(write_permission, setter_name)
setter_name = '_setDefault' + UpperCase(id)
setter = Category.DefaultSetter(setter_name, id, reindex=0)
......
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