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): ...@@ -175,4 +175,12 @@ class ListGetter(Method):
psyco.bind(__call__) 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
...@@ -51,9 +51,9 @@ class Setter(Method): ...@@ -51,9 +51,9 @@ class Setter(Method):
def __call__(self, instance, *args, **kw): def __call__(self, instance, *args, **kw):
instance._setCategoryMembership(self._key, args[0], instance._setCategoryMembership(self._key, args[0],
spec=kw.get('spec',()), spec=kw.get('spec',()),
filter=kw.get('filter', None), filter=kw.get('filter', None),
portal_type=kw.get('portal_type',())) portal_type=kw.get('portal_type',()))
if self._reindex: instance.reindexObject() if self._reindex: instance.reindexObject()
class DefaultSetter(Method): class DefaultSetter(Method):
...@@ -114,9 +114,9 @@ class SetSetter(Method): ...@@ -114,9 +114,9 @@ class SetSetter(Method):
else: else:
new_list = args[0] new_list = args[0]
instance._setCategoryMembership(self._key, new_list, instance._setCategoryMembership(self._key, new_list,
spec=kw.get('spec',()), spec=kw.get('spec',()),
filter=kw.get('filter', None), filter=kw.get('filter', None),
portal_type=kw.get('portal_type',())) portal_type=kw.get('portal_type',()))
if self._reindex: instance.reindexObject() if self._reindex: instance.reindexObject()
...@@ -174,7 +174,15 @@ class ListGetter(Method): ...@@ -174,7 +174,15 @@ class ListGetter(Method):
return instance._getAcquiredCategoryMembershipList(self._key, **kw) return instance._getAcquiredCategoryMembershipList(self._key, **kw)
psyco.bind(__call__) 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 # ItemList is outdated XXX -> ItemList
......
...@@ -110,7 +110,7 @@ class Setter(DefaultSetter): ...@@ -110,7 +110,7 @@ class Setter(DefaultSetter):
if not self._reindex: if not self._reindex:
# Modify the property # Modify the property
if value in self._null: if value in self._null:
setattr(instance, self._storage_id, None) setattr(instance, self._storage_id, ())
elif self._is_tales_type: elif self._is_tales_type:
setattr(instance, self._storage_id, str(value)) setattr(instance, self._storage_id, str(value))
else: else:
...@@ -179,20 +179,35 @@ class SetSetter(Method): ...@@ -179,20 +179,35 @@ 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:
my_dict = {}
default_value = list_value[0] default_value = list_value[0]
for v in value: my_dict = dict((x, 0) for x in value if x!=default_value)
my_dict[v] = 0 new_list_value = my_dict.keys()
if my_dict.has_key(default_value): # If we change the set,
del my_dict[default_value] # the default value must be in the new set
# If we change the set, the default value must be in the new set
if default_value in value: if default_value in value:
new_list_value = [default_value] + my_dict.keys() new_list_value.insert(0, default_value)
else:
new_list_value = my_dict.keys()
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 = []
...@@ -294,6 +309,15 @@ class ListGetter(Method): ...@@ -294,6 +309,15 @@ class ListGetter(Method):
psyco.bind(__call__) 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 Tester = Base.Tester
...@@ -89,4 +89,12 @@ class ListGetter(Method): ...@@ -89,4 +89,12 @@ class ListGetter(Method):
psyco.bind(__call__) 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): ...@@ -97,7 +97,15 @@ class ListGetter(Method):
psyco.bind(__call__) 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): class DefaultIdGetter(Method):
""" """
...@@ -164,7 +172,14 @@ class IdListGetter(Method): ...@@ -164,7 +172,14 @@ class IdListGetter(Method):
psyco.bind(__call__) 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): class DefaultTitleGetter(Method):
""" """
...@@ -229,7 +244,15 @@ class TitleListGetter(Method): ...@@ -229,7 +244,15 @@ class TitleListGetter(Method):
kw.get('strict', None))) # 'strict' is deprecated kw.get('strict', None))) # 'strict' is deprecated
psyco.bind(__call__) 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): class DefaultPropertyGetter(Method):
""" """
...@@ -293,4 +316,12 @@ class PropertyListGetter(Method): ...@@ -293,4 +316,12 @@ class PropertyListGetter(Method):
kw.get('strict', None))) # 'strict' is deprecated kw.get('strict', None))) # 'strict' is deprecated
psyco.bind(__call__) 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): ...@@ -117,7 +117,15 @@ class ListGetter(Method):
psyco.bind(__call__) 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): class DefaultTitleGetter(Method):
""" """
...@@ -175,7 +183,15 @@ class TitleListGetter(Method): ...@@ -175,7 +183,15 @@ class TitleListGetter(Method):
psyco.bind(__call__) 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): class DefaultTranslatedTitleGetter(Method):
""" """
...@@ -233,7 +249,16 @@ class TranslatedTitleListGetter(Method): ...@@ -233,7 +249,16 @@ class TranslatedTitleListGetter(Method):
psyco.bind(__call__) 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): class DefaultReferenceGetter(Method):
""" """
...@@ -291,7 +316,16 @@ class ReferenceListGetter(Method): ...@@ -291,7 +316,16 @@ class ReferenceListGetter(Method):
psyco.bind(__call__) 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): class DefaultUidGetter(Method):
""" """
...@@ -352,7 +386,16 @@ class UidListGetter(Method): ...@@ -352,7 +386,16 @@ class UidListGetter(Method):
psyco.bind(__call__) 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): class UidSetter(Method):
""" """
...@@ -496,7 +539,16 @@ class IdListGetter(Method): ...@@ -496,7 +539,16 @@ class IdListGetter(Method):
psyco.bind(__call__) 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): class LogicalPathListGetter(Method):
""" """
...@@ -523,7 +575,16 @@ class LogicalPathListGetter(Method): ...@@ -523,7 +575,16 @@ class LogicalPathListGetter(Method):
portal_type=kw.get('portal_type',())) 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): class DefaultPropertyGetter(Method):
""" """
...@@ -584,4 +645,13 @@ class PropertyListGetter(Method): ...@@ -584,4 +645,13 @@ class PropertyListGetter(Method):
psyco.bind(__call__) 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, ...@@ -2126,6 +2126,10 @@ def createCategoryAccessors(property_holder, id,
setter_name = '_categorySet' + UpperCase(id) + 'Set' setter_name = '_categorySet' + UpperCase(id) + 'Set'
if not hasattr(property_holder, setter_name): if not hasattr(property_holder, setter_name):
setattr(property_holder, setter_name, setter.dummy_copy(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_name = '_setDefault' + UpperCase(id)
setter = Category.DefaultSetter(setter_name, id, reindex=0) 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