Commit d8d32b7e authored by Jean-Paul Smets's avatar Jean-Paul Smets

Added test for List accessors

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@10031 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 54351d51
...@@ -72,38 +72,28 @@ class DefaultSetter(Method): ...@@ -72,38 +72,28 @@ class DefaultSetter(Method):
if not self._reindex: if not self._reindex:
# Modify the property # Modify the property
if self._is_tales_type: if self._is_tales_type:
if value in self._null: setattr(instance, self._storage_id, str(value))
value = None
setattr(instance, self._storage_id, value)
elif value in self._null: elif value in self._null:
# The value has no default property -> it is empty # The value has no default property -> it is empty
setattr(instance, self._storage_id, ()) setattr(instance, self._storage_id, ())
else: else:
value = self._cast(args[0])
if self._item_cast is not identity: if self._item_cast is not identity:
value = map(self._item_cast, value) value = self._item_cast(value)
if len(value) > 0: default_value = value
default_value = value[0]
list_value = getattr(instance, self._storage_id, None) list_value = getattr(instance, self._storage_id, None)
if list_value is None: list_value = [] if list_value is None: list_value = []
new_list_value = [default_value] my_dict = dict([(x, 0) for x in list_value if x != default_value])
keep_value = 0 new_list_value = my_dict.keys()
for k in list_value: new_list_value.insert(0, default_value)
# Only delete the first occurence if exists value = new_list_value
if keep_value or k is not default_value: setattr(instance, self._storage_id, tuple(value))
new_list_value += [k]
keep_value = 1
else:
# The list has no default property -> it is empty
new_list_value = []
setattr(instance, self._storage_id, tuple(new_list_value))
else: else:
# Call the private setter # Call the private setter
method = getattr(instance, '_' + self._id) method = getattr(instance, '_' + self._id)
method(*args, **kw) method(*args, **kw)
if self._reindex: instance.reindexObject() if self._reindex: instance.reindexObject()
class Setter(DefaultSetter): class ListSetter(DefaultSetter):
def __call__(self, instance, *args, **kw): def __call__(self, instance, *args, **kw):
value = args[0] value = args[0]
...@@ -125,8 +115,7 @@ class Setter(DefaultSetter): ...@@ -125,8 +115,7 @@ class Setter(DefaultSetter):
if self._reindex: instance.reindexObject() if self._reindex: instance.reindexObject()
ListSetter = Setter Setter = ListSetter
class SetSetter(Method): class SetSetter(Method):
""" """
...@@ -166,11 +155,8 @@ class SetSetter(Method): ...@@ -166,11 +155,8 @@ class SetSetter(Method):
if not self._reindex: if not self._reindex:
# Modify the property # Modify the property
if self._is_tales_type: if self._is_tales_type:
if value in self._null: setattr(instance, self._storage_id, str(value))
value = None
setattr(instance, self._storage_id, value)
elif value in self._null: elif value in self._null:
# The value has no default property -> it is empty
setattr(instance, self._storage_id, ()) setattr(instance, self._storage_id, ())
else: else:
value = self._cast(args[0]) value = self._cast(args[0])
...@@ -179,27 +165,9 @@ class SetSetter(Method): ...@@ -179,27 +165,9 @@ class SetSetter(Method):
if len(value) > 0: if len(value) > 0:
list_value = getattr(instance, self._storage_id, None) list_value = getattr(instance, self._storage_id, None)
if list_value is None: list_value = [] 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: if len(list_value) > 0:
default_value = list_value[0] default_value = list_value[0]
my_dict = dict([(x, 0) for x in value if x!=default_value]) my_dict = dict([(x, 0) for x in value if x != default_value])
new_list_value = my_dict.keys() new_list_value = my_dict.keys()
# If we change the set, # If we change the set,
# the default value must be in the new set # the default value must be in the new set
...@@ -207,7 +175,6 @@ class SetSetter(Method): ...@@ -207,7 +175,6 @@ class SetSetter(Method):
new_list_value.insert(0, default_value) new_list_value.insert(0, default_value)
else: else:
new_list_value = value new_list_value = value
else: else:
# The list has no default property -> it is empty # The list has no default property -> it is empty
new_list_value = [] new_list_value = []
...@@ -300,7 +267,7 @@ class ListGetter(Method): ...@@ -300,7 +267,7 @@ class ListGetter(Method):
if self._is_tales_type: if self._is_tales_type:
if kw.get('evaluate', 1): if kw.get('evaluate', 1):
if type(list_value) != type(''): if type(list_value) != type(''):
LOG('ListGetter', 0, 'instance = %r, self._storage_id = %r, list_value = %r' % (instance, self._storage_id, list_value,)) LOG('ListGetter', 0, 'instance = %r, self._storage_id = %r, list_value = %r' % (instance, self._storage_id, list_value,)) # If we reach this point, something strange is going on
list_value = evaluateTales(instance=instance, value=list_value) list_value = evaluateTales(instance=instance, value=list_value)
else: else:
return list_value return list_value
......
This diff is collapsed.
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