diff --git a/product/ERP5Type/Accessor/Acquired.py b/product/ERP5Type/Accessor/Acquired.py index 1c98d63ba6656ffb884c6eaf4035258853aeaca1..5be81028cdc4c5d8eeb2b25ef2f3f4d8855ce3d9 100644 --- a/product/ERP5Type/Accessor/Acquired.py +++ b/product/ERP5Type/Accessor/Acquired.py @@ -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 + diff --git a/product/ERP5Type/Accessor/Category.py b/product/ERP5Type/Accessor/Category.py index bdbefba1301a84ab8ea81b6eb2c9ad81c0629638..f9550d13062d08a7623628c4edc0c285524f7931 100644 --- a/product/ERP5Type/Accessor/Category.py +++ b/product/ERP5Type/Accessor/Category.py @@ -51,9 +51,9 @@ class Setter(Method): def __call__(self, instance, *args, **kw): instance._setCategoryMembership(self._key, args[0], - spec=kw.get('spec',()), - filter=kw.get('filter', None), - portal_type=kw.get('portal_type',())) + spec=kw.get('spec',()), + filter=kw.get('filter', None), + portal_type=kw.get('portal_type',())) if self._reindex: instance.reindexObject() class DefaultSetter(Method): @@ -114,9 +114,9 @@ class SetSetter(Method): else: new_list = args[0] instance._setCategoryMembership(self._key, new_list, - spec=kw.get('spec',()), - filter=kw.get('filter', None), - portal_type=kw.get('portal_type',())) + spec=kw.get('spec',()), + filter=kw.get('filter', None), + portal_type=kw.get('portal_type',())) if self._reindex: instance.reindexObject() @@ -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 diff --git a/product/ERP5Type/Accessor/List.py b/product/ERP5Type/Accessor/List.py index 0ed472f54505d3790dcc9d944e57e10a1c3fa083..bcb132b64c6389475ea3fe16ddc2b44e38f29635 100644 --- a/product/ERP5Type/Accessor/List.py +++ b/product/ERP5Type/Accessor/List.py @@ -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 + 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 = [default_value] + my_dict.keys() - else: - new_list_value = my_dict.keys() + 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 diff --git a/product/ERP5Type/Accessor/Related.py b/product/ERP5Type/Accessor/Related.py index bb3ec6c06ed7cbfa5ce38d09b1fc1ef7588d46e8..57415cb8d0e6a1f07ebe95b8f4756b9d0c7d50b8 100644 --- a/product/ERP5Type/Accessor/Related.py +++ b/product/ERP5Type/Accessor/Related.py @@ -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 + diff --git a/product/ERP5Type/Accessor/RelatedValue.py b/product/ERP5Type/Accessor/RelatedValue.py index f01d635f16adcdc0a6ff01705942dc01048e5da9..9509e9f653cdf18a162c3ccaa5083e758be80f1b 100644 --- a/product/ERP5Type/Accessor/RelatedValue.py +++ b/product/ERP5Type/Accessor/RelatedValue.py @@ -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 + diff --git a/product/ERP5Type/Accessor/Value.py b/product/ERP5Type/Accessor/Value.py index 47c49a87f72dd36dcc61aead484a43f748ddbfd5..577b00669af087dc27e228c49bcf2d9477eb6365 100644 --- a/product/ERP5Type/Accessor/Value.py +++ b/product/ERP5Type/Accessor/Value.py @@ -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 + diff --git a/product/ERP5Type/Utils.py b/product/ERP5Type/Utils.py index 34113e17b9095106d7f98104f4e9ae28d9eba8e0..3dfa55d93ced1416af0b7a34f57ac0a6a5500317 100644 --- a/product/ERP5Type/Utils.py +++ b/product/ERP5Type/Utils.py @@ -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)